Skip to content
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

Improved logging #149

Merged
merged 2 commits into from
Jan 26, 2021
Merged

Improved logging #149

merged 2 commits into from
Jan 26, 2021

Conversation

SweVictor
Copy link
Collaborator

Completely rewritten logging for js to improve code structure and user experience

  • configuration setting for log level
  • centralized logging based on winston
  • color coded logs
  • updates readme with log settings and notes on how to export logs

Also breaks out configuration fetching in js, removes the redundant plejd.json file and cleans up code from plejd.sh.

- Based on "winston" logging library
- Removed no longer needed lodash
- Locked npm dependencies to most recent major versions to avoid installs breaking due to node module updates
- Break out reading of settings in js and remove it from shell scripts
- Pick up config from Logger via Configuration class
@kodarn
Copy link

kodarn commented Jan 22, 2021

Nice work! I have been missing prepended timestamps! 😀 👍

@SweVictor
Copy link
Collaborator Author

image

Absolutely!

@icanos
Copy link
Owner

icanos commented Jan 22, 2021

Great work! One small thing though, I'd like the file names to conform to the rest of the project in using lower case names. Nothing major :-)

@SweVictor
Copy link
Collaborator Author

I can change it for sure, however the semantics is different. The two new files export the class directly and is used const Logger = require('./Logger'), while most other files use const mqtt = require('./mqtt'); const MqttClient = mqtt.MqttClient; (or const MqttClient = require('./mqtt).MqttClient;`.

I personally prefer the "follow default export naming convention" mentioned for example here AirBnB style guide and also strive for "one export per file", but I realize it's a bit different than today.

Either way I think it's good to set a pattern. What do you think, how should we proceed? Always export a "wrapper" (mqtt above)? Move towards AirBnB style?

On a side note I am personally like named exports than default exports, so I would normally do similar to how you have done so far (with other syntax) export class Logger { ...} / import { Logger } from './Logger;, which I suppose would work with the above example as well (const { MqttClient } = require('./mqtt')). This does not seem to be the NodeJS standard though...

@icanos
Copy link
Owner

icanos commented Jan 22, 2021

I agree with you 100% regarding exports and classes, I like the AirBnB style. Think this addon has grown a bit from my initial tests :-) therefore the structure today is quite poor.

When working with React and such, you normally (at least if you scan the internet a few seconds :-D) use default exports if you don't have more than one export. I can't say that I'm pro this or that, as long as we follow the same standard through out the whole project.

@SweVictor
Copy link
Collaborator Author

So - what's the decision :)

I'm quite fine with either way forward, but I think it's good to decide "something".

@icanos
Copy link
Owner

icanos commented Jan 22, 2021

Lets follow the AirBnB style guide and rework any files not conforming to that. That would also mean that we use default exports and strive for a single export per file.

@SweVictor SweVictor mentioned this pull request Jan 22, 2021
@SweVictor
Copy link
Collaborator Author

Adjusted code style on top of this PR, but broke out in separate branch/pr for comparison purposes. Is a bit opinionated and touches a lot of files, feel free to reject or suggest major changes!

@icanos icanos merged commit 1b55cab into icanos:master Jan 26, 2021
@SweVictor SweVictor deleted the feature/improved-logging branch January 26, 2021 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants