-
-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Unified winston-based logging module (PR to branch) #47
[WIP] Unified winston-based logging module (PR to branch) #47
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ahochsteger The base is good. What is missing is a way to customize logger options like transports to use, enable/disable logs (silence transports). I would also provide a file transport, not by default but if it's requested in the options.
this.reconnectTimeout = setTimeout(this.connect.bind(this), 3000) | ||
} | ||
} else { | ||
debug('Driver already connected to', this.cfg.port) | ||
logger.info('Driver already connected to', this.cfg.port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.info('Driver already connected to', this.cfg.port) | |
logger.info(`Driver already connected to ${this.cfg.port}`) |
I would convert all this loggers that are using commas ,
to use the template ``
@@ -1897,7 +1904,7 @@ ZwaveClient.prototype.callApi = async function (apiName, ...args) { | |||
} | |||
} | |||
|
|||
debug(result.message, apiName, result.result || '') | |||
logger.info(result.message, apiName, result.result || '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
const logContainer = new winston.Container() | ||
|
||
// Example: Pre-configured module logger with special properties | ||
logContainer.add('ZWC', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's ZWC
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the short representation of "ZwaveClient" for shorter logging statements. It just shows that it may be different to the (possibly longer) filename.
It's also one of the assumptions we did not yet talk about and I'd like to get some feedback about what is expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think zjs2m
it's more generic (also the old z2m
would be fine IMO) as we also have a zwave client module.
Modules are:
store
: the json store moduleapp
: everything that is inapp.js
apis
: to log api requests (will replace morgan)zwave
: zwave clientmqtt
: mqtt client
Or is there something else you'd expect? |
@ahochsteger What I mean is: When z2m starts we read
Something like what I have done in this PR in zwave-js: zwave-js/node-zwave-js@5942fc8#diff-6f99af7443b72862fc7d1dce631cac3b76263260bdead8dfa2bbbfa062a38340R13 |
@robertsLando I see what you mean. I see the following options:
Assuming option 2, it could look like this: const logger = require('./logger.js').module('<modname>')
...
logger.setup(<some logging settings>)
logger.info("Some log message")
... The downside is, that you HAVE to call What do you think? |
There is no need to do this. The |
What about the logging configuration of other modules (MqttClient, ZwaveClient, ...)? They need the config too.
So it comes down to the following architectural decisions:
Since the current approach uses labels to tag logging events with the source module and the labels may have to be passed to the logger during instantiation time (at least I did not find a way to change it afterwards), I guess 1a+2b may be a good compromise. Maybe the suggestion to move the label to the info object may be a solution to make 1a+2a possible (see winstonjs/winston#736) if we really need this. @robertsLando what's your thoughts on this? |
@robertsLando may you provide some feedback about the assumptions in the description so we can adjust them and move them to the section Agreed Conditions & Requirements? I'd like to do the code changes after this is done. |
IMO this would become difficult to implement without so much benefits. If you are looking for zwave client logs you could easily get them by using Esentially there will be only 1 level of childs (modules) and this level will be:
In gateway we could think about having a custom logger for hass related stuff too. It could be a child of gateway or another module that extends the main About assumptions:
Yes
Not sure about what you mean here. In my idea there will be only one logger instance and more modules each module will share the same transports of the main instance. The output format w
Yes
I would use
What do you mean here?
Sure, in UI we the level input should be the same I'm using in zwave settings for zwave-js
Actually the logging solution is almost the same as Just a thought: I think that the |
@robertsLando thanks for your feedback, I moved all agreed items to the other section - only two left.
This is an implementation detail about how we map modules to winston elements:
I guess, you wanted to write some more about formatting, but your sentence seems to be not finished ...
It was my assumption that there may be modules that require very special logging configuration and we want to support that.
What do you mean with "level input" here?
I had the impression to be more sophisticated since there are a lot of logging classes and much improved colored formatting.
Yes, that's a chicken/egg problem. |
Sorry didn't noticed that 😆 The output format could be like:
Example:
In my idea all loggers should use the same transports but they could use different formats, the base format is the one I showed you previously then we can customize the formats based on different modules needs. In a first step we could keep the format the same for all modules and then see how we could improve formats.
Actually if you check the UI, settings page, zwave section, there is a select input for levels, we could use the same for the log levels of our logger settings
Most of the complicated stuff there is the log formatting, what I would like to replicate here is the structure it uses (shared transports and module/labels)
This could be a solution but IMO logging settings should be stored in settings.
Logging settings (like other settings) must be persistent. |
@ahochsteger I have introduced the |
@robertsLando thanks for the feedback - it's integrated into the list of requirements.
I'd miss the date here which is required if zwavejs2mqtt is running silently for a longer time and from time to time I'd like to review the logs for problems. Then it would be important to know on which day that was. Optionally the timezone could be added too, but this is not that important IMO. |
Yep no problem we can add the date too :)
Nope, I don't think so. Useless IMO |
@robertsLando, as you suggested on slack I'm about to move the commits & PR to a direct branch of this repo ( |
@robertsLando, may you merge this into the new branch? |
@robertsLando, nevermind, was able to do it myself :-). |
This PR is now continued in #67. |
This PR is a draft to unify the logging across zwavejs2mqtt using winston and is continued in #67.
It provides the following changes:
lib/logging.js
)lib/ZwaveClient.js
)Usage:
Conditions & Requirements:
<timestamp> <level> <moduleName/label>: <logMessage>
(e.g.2020-12-04 09:06:32.568 INFO APP: Zwave2MQTT Version 0.0.0
)ZWAVE
MQTT
GATEWAY
STORE
HASS
HTTP
APP
settings.js
using the optionslogEnabled
,logToFile
andlogLevel
settings.js
Logging changes in the existing codebase:
The following files are affected and show the existing logging implementation that should be migrated to winston logging:
app.js
(uses debug & morgan) ---> winstonHTTP
andAPP
modulesbin/www
(uses debug) --> consolelib/debug.js
(uses debug) ---> Will becomelogger.js
lib/Gateway.js
(uses debug) ---> winstonGATEWAY
and (maybe)HASS
moduleslib/jsonStore.js
(uses debug) ---> winstonSTORE
module (need to think about this, we could use console otherwise)lib/MqttClient.js
(uses debug) --> winstonMQTT
modulelib/ZwaveClient.js
(uses debug) --> winstonZWAVE
moduleNext Steps:
Foot notes: