Support different loggers
aqrln opened this issue · 6 comments
Instead of writing errors and warnings to stderr, make loggers pluggable.
Ref: #101 (comment)
@lundibundi @aqrln paused, I'll give comments ASAP about code in #224
Impress logger is an object having a set of logging methods with single string argument:
logger.method(message: string)
By default we have following methods:
- to log errors and debugging:
error, debug, warning
- to log API requests:
access, api, slow
- to log server events:
server, node, cloud
But application can have additional loggers it is configurable: config/log.js
JSTP may use access, api, slow
to log RPC access. Logger will create separate file per process (to have exclusive write). But server
and cloud
logs have single file per server (no separate file per process). Impress logger implements log rotation (new file each day and delete old files).
We do not need:
- support winston or bunyan
- logging level (number)
.isDebug()
or.isWarn()
- you can do something like this
const debug = logger.debug || () => {};
instead
- you can do something like this
@metarhia/jstp-core
@tshemsedinov, .isDebug()
and other similar methods are needed to avoid unnecessary preparation in cases when there is no such method in the provided logger (see #224 (comment)).
if (logger.debug) ...
@belochub
Even more, you do not need to know whether app is in debug mode, just call logger.debug(message)
and it will be logged to file or to console or both or ignored at all. @belochub
It doesn't check whether an application is in debug mode or not, it's just checking if the logger is attached to avoid preparation (like serialization or removing sensitive information, see #224 (comment)).
Even if there is a function which ignores the message, it is better to avoid calling it, because otherwise, additional message processing is unavoidable and this will harm the overall performance.