Anyone ever use a 'logging framework' in their sol...
# suitescript
d
Anyone ever use a 'logging framework' in their solutions? Like js-logger, etc?
s
NFT uses the Aurelia logger and it works great. It's simple but has all the features I wanted from a 'real' logger which NS lacks.
c
What do you gain from a "real" logger? I've never used one other that console so I am curious now.
d
@creece I was more looking for a logging framework, that I can wrap around N/log
I don't need/want anything fancy (I could probably write my own), but wanted to know if there was a library people were using/liking
This js-logger (https://www.npmjs.com/package/js-logger) looks good. I can extend it to use log.audit('','') rather than the default console.log
s
I guess you don't like Aurelia logger for some reason 🙂
By 'real' logger I mean logging with features common in the industry - e.g. log4net/log4j, EntLib logger, winston etc.
Specifically, I wanted 3 abilities
1. ability to have multiple named loggers. This is used to allow shared libraries to log independently of the main script and allow library logging to be turned off by default.
2. ability to control log level programmatically, rather than relying only on the script deployment record in NS.
3. ability to define different log destinations and multiple log destinations. For example, in client scripts we log to console by default (to prevent network round-trips to log to the NS execution log) but it's easy to add an additional appender to log server-side if desired, without changing any of the log calls. Log content should be separate (logically) from how the content is sent/stored.
Darren, I'd recommend you try NFT, even if only for the logger. That's an easy way to get started, and the autologging is a significant win.
I find it hard to understand why everyone doesn't use a logging library for reasons like above and more?
if you ever find yourself commenting out log lines, it's probably a sign you could benefit from a logging library 🙂
c
I guess i rarely have log statements in my code past production so its an edge case for me. Just your typical try/catches
I try to take the no news is good news approach for logging
d
Thanks @stalbert @creece. I've played with js-logger and love it. Hits all 3 of your wants @stalbert.
👍 1
c
btw i not saying don't use one, I was just curious what they did vs. how I could use it myself
d
My concern with NFT is the level of abstraction it brings as well as hefty library of files. It would likely overcomplicate the bulk of our customizations. Lastly, it means yet another 'tool'/'system' a new/existing developer would need to educate themselves on
s
I take the opposite approach @creece - I take the approach that log code was important, so don't delete it. Instead, control it.
My point with NFT is you can upload the ZIP file but only use part of it. The logging stuff has no dependencies or requirement that you use anything else in NFT. The one handy addition it provides is an ExecutionLogAppender which logs to the NS exeuction log. It's also nice that log entries have the logger name in the title if it's other than the default logger
say you have a library abstracting some complex tax calculations "tax". When that library logs, the execution log title is prefixed with
[tax]
so that log messages from that library are clearly distinct from messages in another library
with a logging library, you may disable the detailed debug loggging in that library only, and that's fine and supported.
Or maybe you just bump the logging level for the lib to be 'error' and higher
point being, you control that outside the script, and get to leave all the log calls in the code. At runtime the calls are short circuited so there's no significant perf hit by leaving them in.
that said, I don't usually have many log calls in my top-level code - I rely on the autologger and functional decomposition of my problem (aka small functions that autolog).