Any specific scenarios do logging for scripting? Whats the best practice?

Suggy
Giga Sage

I have an understanding that we should avoid using gs.log which pushing the code to PROD, but if I see a vanilla instance, I see several logs being logged based on OOB scripts.

 

Also in this post I see one of the SN employee stating "best practice suggests that scripts should log what they're doing." 

https://www.servicenow.com/community/developer-forum/where-to-find-job-log-for-a-scheduled-job-that-...

 

Question - Whats really the best practice for logging? should we log? not log? log minimal only when necessary?

 

2 REPLIES 2

Mark Manders
Mega Patron

There is a difference in adding comments to a script to explain what it is doing, or logging what it is doing. Because if you write every script to the system logs, you would also never find anything. 

Depending on the script, you should decide if something needs to be logged or not. You could log errors when something goes wrong, but do you really need to know when it runs correctly.

 

Also: ServiceNow has a lot of people working on their product, so the fact that some logs are in the system that shouldn't be, does not make it a best practice. The biggest issue within the logging discussion is always that people add logs to scripts while developing, just to see if everything runs as it should and they forget to get those logs out of the code when moving to PROD. 

If you are looking for an example of how ServiceNow is handling their own best practices, just get a new instance, without any config and run the OOB instance scan. 


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Joni V B
Tera Guru

@Suggy ,

I wouldn't push any general logging into a production instance for everything that works as designed.
Exceptions / warnings / errors are useful of course to log on a production instance. As long as the standard process / execution flow of your logic is being followed I would consider it as pollution of the logs (and ServiceNow is already polluting the logs enough I think :-)).

Best regards,

Joni