How to display milliseconds in logs?

Stephen W_
Giga Guru

The sys logs, (warning, error, all) only display the created date in seconds.

The problem is, there are a lot of activities that then are grouped in the same second, and I lose my order of operations making troubleshooting a whole lot more difficult.

 

Can I alter the detail level?

 

Thanks,

-Stephen

12 REPLIES 12

Rob King
Kilo Contributor

Hello, from 2021 ...

My colleague and I were just trying to diagnose a script and noted how difficult it was to work out the order of things that are happening almost instantaneously.  Given that the date/time is stored in milliseconds we just need a way to expose that as an option, even if it is only when reviewing logs where scripts are being analysed.

GLewis5
Tera Guru

Please be sure to vote for Provide more precise created date in logging tables in the Idea Portal.

 

Jon G1
Kilo Sage

Yet further in the future: While it isn't exactly what this question is looking for, ServiceNow seems to have a built-in script include called GSLog.  This script include seems like a ServiceNow developer's answer to this problem, but it has some big flaws.

 

1. It's in the global application scope. That means that logs generated from this tool go to the system log even if you call it from an application scope.  Log entries don't go into the application log.  If you want to use it for application logging, you can do so by calling it as global.GSLog() but it is recommended not to do that with any applications you intend to share.

2. Since it is part of the global application scope and uses the global version of gs.log(), it replaces certain log levels. You're basically limited to info, warn, and error.  Debug comes through as an information level message with a '[DEBUG]' tag prepended to the message.

 

If you're okay with those issues, then you can use it like this:

 

var log = new global.GSLog('[system property to get level from]', '[log source]');
log.includeTimestamp();

log.debug('debug');
log.info('info');
log.warn('warn');
log.error('error');

 

 

Your log messages will include a timestamp that looks like this:

 

2023-01-18 13:59:35.620 Test info message
2023-01-18 13:59:35.619 [DEBUG] Test debug message

 

 

Other than that, I have not found another way to include a timestamp short of writing my own logging helper script include (which I have done). I came hoping that someone else had found a better solution, but alas, 8 years of nothing from ServiceNow on this front.