signale icon indicating copy to clipboard operation
signale copied to clipboard

Multiple interactive loggers

Open br0p0p opened this issue 6 years ago • 7 comments

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!

br0p0p avatar Jun 15 '18 19:06 br0p0p

Any update in this feature request?

thereis avatar Nov 24 '18 13:11 thereis

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

wvffle avatar Feb 08 '19 18:02 wvffle

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.

tomkln avatar Jun 06 '19 12:06 tomkln

any update?

adamramadhan avatar Jun 09 '20 10:06 adamramadhan

Any update on this?

alii avatar Dec 20 '20 12:12 alii

Any update on this?

paulo-digital avatar Dec 21 '20 16:12 paulo-digital

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.

toniopelo avatar Jun 13 '21 10:06 toniopelo