Add timestamps to log messages
See original GitHub issueIn Chrome you can use “Show timestamps” to see timestamps next to your log messages. Unfortunately, this does not work in Node.js. Therefore we should add an option to automatically print timestamps together with the log message.
Proposal
const logdown = require('logdown')
const logger = logdown('MyLogger', { markdown: false, timestamp: true })
logger.log('Hello, World!')
Proposed Output
[2017-03-13 12:15:03.137] MyLogger Hello, World!
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to add timestamps to log messages - xMatters Support
After this, instead of using "console.log('Your message here');" each time you want to include a timestamp, simply use: tsLog( 'Great news!' );.
Read more >include timestamp in log messages #38410 - JuliaLang/julia
To include the timestamp, one currently has to add the now function to each log call, e.g.. julia> @info "$(now(UTC)) hello world" [...
Read more >Print timestamp for logging in Python - Stack Overflow
Before the first time you log anything do this: logging.basicConfig( format='%(asctime)s %(levelname)-8s %(message)s', level=logging.
Read more >How to add a timestamp to bash script log? - linux - Server Fault
When you need to send to log file use #!/usr/bin/env bash source /path/to/config.sh echo "$TIMESTAMP Say what you are doing" >> $LOGFILE do_what_you_want ......
Read more >How can I add timestamp to console.log? - Forums - IBM
Is there a way to add timestamps into console.log? ... If you look at messages.log or trace.log in the usr/servers/myServer/logs directory, they both...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
It’s great that logdown is extensible! I really like such architecture!
However, I think logging the time is a core functionality of a log library. There is a reason that Google implemented timestamps for
console.log
statements in Chrome.As a compromise it would be great if we can supply a hook for the formatter, which makes it easier to modify texts before they get logged. Here is a great example from js-logger:
Currently I am extending logdown with timestamps like this:
Not actually. The initial idea of the lib was to wrap
console
with a markdown parser and debug compatibility. But again, I’m open to adding a timestamp capability.You don’t have to import
tubo
. That’s is just a wrapper for better pipeline pattern.To create a “ecosystem” is not the goal I first mentioned, but rather keeping the library as simple as possible. And extensible.
But again, timestamp is something that makes sense to have in the library. Go ahead if you fancy implementing it.