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.

Intercepting the 'time' section of the log message?

See original GitHub issue

Hi,

Great tool. I especially love the fact that we can intercept and modify the concat and render stages.

One thing I was not able to do:

I would like to format the timestamp in the following fashion:

[2019-01-19T15:40:28.535Z] (INFO) This is just a message reporting a variable:
                        	  [1, 2, 3, 4, 5, 6] (info @ logging.js:60)

I know we can add a custom printer for the time, but that changes the output to:

[Sat Jan 19 2019 15:17:03 GMT+0000 (Greenwich Mean Time)]

which is not something that I would like to do? So here is what I am trying to achieve:

  • Add [ to the start and ] to the end of the timestamp.
  • Change the color of the timestamp (I know I can do that through the custom printer, but the custom printer is changing the look of the date)
  • Adding a (INFO) signature between the timestamp and the message block, so the second line of the message does not spill below the (INFO) signature.

So it looks a bit like this: format

Obviously, I tried this:

const logging = log.configure ({
    /*  Injects a function after the "concat" step            */
    'concat+' (blocks) {
        console.log(blocks)
        return blocks;
    },
    time: {
        yes: true,
        format: 'iso'
    }
});

as an attempt to intercept the text stream and try re-format it, but I got this:

[ '\u001b[33m\u001b[22m\u001b[1mThis is just a message reporting a variable:\u001b[22m\u001b[39m',
  '\u001b[33m\u001b[22m\u001b[1m\u001b[22m\u001b[39m [1, 2, 3, 4, 5, 6]' ]

… so the timestamp was not there 😃

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
xplcommented, Jan 22, 2019

@cryptoeraser I’ve added a new overrideable stage called tag. Please see the updated docs:

  1. Displaying The INFO/WARN/ERROR Tags
  2. Customized Tag Printer
screen shot 2019-01-22 at 22 46 59

The example code:

const bullet = require ('string.bullet') // NB: these packages are part of Ololog, no need to install them separately
const { cyan, yellow, red, dim } = require ('ansicolor')

const log = require ('ololog').configure ({

    locate: false,
    time: true,
    tag: (lines, {
            level = '',
            levelColor = { 'info': cyan, 'warn': yellow, 'error': red.bright.inverse },
            clusterId
          }) => {
        
        const clusterStr = clusterId ? ('CLUSTER[' + (clusterId + '').padStart (2, '0') + ']') : ''
        const levelStr = level && (levelColor[level] || (s => s)) (level.toUpperCase ())

        return bullet (dim (clusterStr.padStart (10)) + '\t' + levelStr.padStart (6) + '\t', lines)
    }
})
log.configure ({ tag: { clusterId: 1  } })       ('foo')
log.configure ({ tag: { clusterId: 3  } }).info  ('bar')
log.configure ({ tag: { clusterId: 27 } }).error ('a multiline\nerror\nmessage')
0reactions
cryptoerasercommented, Jan 22, 2019

Yeah, I have seen your commit and I was already digging in the diffs 😃 Thank you very much! This is amazing!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Intercepting all logging messages - python - Stack Overflow
I'm working with an application where just about every module and every class emits logging messages.
Read more >
Logging and intercepting database operations - EF6
Starting with Entity Framework 6, anytime Entity Framework sends a command to the database this command can be intercepted by application ...
Read more >
Intercepting messages - PortSwigger
From the Proxy > Intercept tab, you can intercept HTTP requests and responses sent between the browser and the target server.
Read more >
intercept, evaluate, change syslog messages - Server Fault
is it possible to intercept syslog messages and evaluate (in special cases change) them before they are written into /var/log/?.
Read more >
Chapter 18. Intercepting Messages Red Hat AMQ 7.0
Chapter 18. Intercepting Messages. With AMQ Broker you can intercept packets entering or exiting the broker, allowing you to audit packets or filter...
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