Is it possible to set the log level when logging with gs.log() ?

bbarnard
Kilo Contributor

Is it possible to set the level of a log entry to Warning, Error, or Information? I see logs being created by the system with the levels being set, but I do not see an option to use the gs.log() function to set the level. Is this possible?

I'm currently using the source functionality "gs.log(msg,src)" but would like to enhance my logging in scripts, bus rules, etc...

Thanks,
Bryan

9 REPLIES 9

tony_fugere
Mega Guru

I think the idea here is that Level is sort of internal to ServiceNow as a platform to allow Support to find "true errors/warnings" etc. Use the Source and build a custom module that applies the appropriate filter to show you log messages from Source = "Warning" or Source = "Error". That way you stay segregated from the Platform and easily troubleshoot your customizations.


Thanks John and Tony for you input,

I dug around and found a way to do it using one of the Packages, however if the level is indeed used for internal ServiceNow support I can see why it would be a bad idea to intermingle our debugging and info logs with the actual system logs. I was thinking of how I could add some enhanced logging functionality ideally something similar to the functionality the firebug console provides with their console.log, console.warn, console.info, and console.error functionality. I think I can achieve similar functionality in ServiceNow if I create a custom log table and a logging script include, with client scripts to color code the list view of the records based on a field value. I am concerned about the growth rate of this table due to verbose logging, but I think I can handle this with either business rules or a scheduled job to clear the table at regular intervals.

Any feedback/suggestions would be appreciated.

Thanks,
Bryan


We recommend avoiding the use of direct package calls whenever possible. I know we use them in some of the OOB scripts but at least we can keep track of those. If we ever have to modify the java classes or structure it may break your custom scripts.

As for the size of the log....
1. Only log what you need. If it's for debugging you could define a new property and only write to the log when your debug property is enabled. Also, if they are session based scripts you can also use gs.print to output to the console for debugging. Just run the debug log module to view them. Messages are displayed to the console only and not written to the database.
2.System log should already be configured for table rotation (see module) so it won't keep growing forever. You could configure the same for your log table if needed.


Thanks for the info, I'm trying to avoid package calls where possible for just that reason.

-Bryan