Console.log timestamps in Chrome
Quickly annotate your console.log
outputs with timestamps in Chrome by overriding the function:
This small yet robust one-liner infuses console.log
with the power to prepend logs with an ISO timestamp, transforming your logs into historically aware messages.
For those fortuned enough to have Chrome 68+, you can watch timestamps dance in your logs without touching a line of code!
Enabling in-built timestamps
Chrome has evolved, and it's not shy to flaunt its features. Here's how to tell your chrome to stamp your log entries:
- Press
F12
orCmd+Opt+I
on a Mac /Ctrl+Shift+I
on Windows to summon the mighty Chrome DevTools. - Make a swift click on vertical ellipsis (⋮) adorning the top-right of the console or simply press
F1
to greet Settings. - In the land of Console section, checkmark the option saying "Show timestamps".
Fear not, for with this road not only you abstain from coding exertions but also preserve the purity and dignity of your console.log
function.
Creating your timestamp formatter
For those inclined towards customization or living in prehistoric chrome can manifest their own console.log
magic:
- Bound Logger: Summon your deeply bound logger to create a superficial timestamp using
console.log.bind
.
- Profiling Tools: Harness the power of
console.time
andconsole.timeEnd
for timing perfection.
- ES6 Arrow Functions: Why not make chrome arrows of time fly straight into your logs?
Timestamp Visualization
Here are your ancient logs, which once roamed the console land without a trace of time, now come labeled with timestamps:
Lowering the curtain on Chrome console methods
Light and fast
When speed is the essence, let Chrome's inherent timestamping guide you on console logs. It's as easy as flipping a switch but remember, customization is preserved for the brave.
Tailored perfection
When uniqueness demands precedence, enhancing console.log
is the path to walk on. Coding environments oblivious of DevTools will be more welcoming to you.
Weighing performance
Fear not, for the performance impact while toy logging is meager turning colossus only in high-frequency logging. In performance-focused tasks, trust the built-in option or delegating logging frameworks for efficient timestamping!
Was this article helpful?