question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple interactive loggers

See original GitHub issue

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!

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:19
  • Comments:7

github_iconTop GitHub Comments

7reactions
tomklncommented, 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.

0reactions
toniopelocommented, Jun 13, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple interactive loggers #44 - klaudiosinani/signale - GitHub
Is it possible to have multiple interactive loggers that update independently of each other (either separated by scope or Signale instance)?
Read more >
To Configure Multiple Periodic Stats Loggers | Ping Identity ...
Multiple Periodic Stats Loggers can be created to log different statistics, view historical information about gauges, or to create a log at different...
Read more >
Python logging in interactive sessions - Stack Overflow
Yes, you are creating and reusing a single instance of your logger. Each handler added to that logger is also logging a message....
Read more >
Logging providers - .NET - Microsoft Learn
For example, the Azure Application Insights provider stores logs in Azure Application Insights. Multiple providers can be enabled.
Read more >
8 Advanced Python Logging Features that You Shouldn't Miss
Handler specifies the destination of log messages. A log message can be sent to more than one destination. The logging module actually provides ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found