Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple interactive loggers #44

Open
br0p0p opened this issue Jun 15, 2018 · 7 comments
Open

Multiple interactive loggers #44

br0p0p opened this issue Jun 15, 2018 · 7 comments
Labels
feature request Request for a new feature

Comments

@br0p0p
Copy link

br0p0p commented Jun 15, 2018

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
Copy link

thereis commented Nov 24, 2018

Any update in this feature request?

@wvffle
Copy link

wvffle commented Feb 8, 2019

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

@tomkln
Copy link

tomkln commented Jun 6, 2019

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
Copy link

any update?

@alii
Copy link

alii commented Dec 20, 2020

Any update on this?

1 similar comment
@paulo-digital
Copy link

Any update on this?

@toniopelo
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

9 participants