klaudiosinani / signale

Highly configurable logging utility
MIT License
8.92k stars 232 forks source link

Multiple interactive loggers #44

Open br0p0p opened 6 years ago

br0p0p commented 6 years ago

Is it possible to have multiple interactive loggers that update independently of each other (either separated by scope or Signale instance)? It seems that the current behavior is that the most recent call to an interactive logger will overwrite any previous interactive output.

Here's an example of what I'm trying and the desired output:

const { Signale } = require('signale');

const interactive = new Signale({ interactive: true, scope: 'scope 1' });

setTimeout(() => {
    interactive.success('[%d/4] - Process A', 2);
    setTimeout(() => {
        interactive.await('[%d/4] - Process B', 3);
        setTimeout(() => {
            interactive.error('[%d/4] - Process B', 4);
            setTimeout(() => {}, 2000);
        }, 4000);
    }, 3000);
}, 2000);

const interactive2 = new Signale({ interactive: true, scope: 'scope 2' });

setTimeout(() => {
    interactive2.info('[%d/3] - starting it...', 1);
    setTimeout(() => {
        interactive2.await('[%d/3] - doing it...', 2);
        setTimeout(() => {
            interactive2.success('[%d/3] - finished it!', 3);
            setTimeout(() => {}, 2000);
        }, 4000);
    }, 3000);
}, 2000);

Output: Only displays the "scope 2"/interactive2 logs

[scope 2] › ✔  success   [3/3] - finished it!

Desired output:

[scope 1] › ✖  error     [4/4] - Process B
[scope 2] › ✔  success   [3/3] - finished it!
thereis commented 5 years ago

Any update in this feature request?

wvffle commented 5 years ago

I'd really like to see this feature in next version

tomkln commented 5 years ago

As a workaround, you could add an empty console.log(); after your last interactive log message. It starts a new line and prevents updates to the previous line.

adamramadhan commented 4 years ago

any update?

alii commented 3 years ago

Any update on this?

paulo-digital commented 3 years ago

Any update on this?

toniopelo commented 3 years ago

As a workaround inspired from @tomkln comment, here is how I export my logger :

import signale, { DefaultMethods, Signale, SignaleOptions } from 'signale'

export const getLogger = (
  scope: string,
  options: SignaleOptions = {},
): Signale<DefaultMethods> & { breakInteractiveChain: () => void } =>
  Object.assign(new Signale({ scope, ...options }), {
    // eslint-disable-next-line no-console
    breakInteractiveChain: () => console.log(),
  })

export default signale

And here is how I consume it :

const iLogger = getLogger('send-mail', { interactive: true })

iLogger.await('Fetching users')
iLogger.success('Users fetched')

// Prevent subsequent calls to interactive logger to override previous ones
iLogger.breakInteractiveChain()

iLogger.await('Sending mails')
iLogger.success('Mails sent')

If this console.log() hack finally is the preferred solution, I could make a tiny PR about this.