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

Map Winston levels to LogDNA levels #31

Closed
kendallroth opened this issue Sep 2, 2021 · 7 comments · Fixed by #32
Closed

Map Winston levels to LogDNA levels #31

kendallroth opened this issue Sep 2, 2021 · 7 comments · Fixed by #32
Labels

Comments

@kendallroth
Copy link

kendallroth commented Sep 2, 2021

In our project there is a discrepancy between the log levels supported by @logdna/logger and the levels we are using in WinstonJS (we also use CRITICAL). We have not found a way to "map" between the Winston log levels (custom or otherwise) to the list of supported LogDNA levels.

For example, a potential workaround would be mapping our WinstonJS critical log level to the LogDNA error log level (since they do not support critical). However, currently this is not possible, so any of our critical logs get reported as info in LogDNA.

Is there any way to get support for additional log levels, or at least mapping them?

P.S. The LogDNA docs apparently support more common log levels, but their package does not... See slightly different ask in @logdna/logger

@kendallroth
Copy link
Author

While debugging this I came across a few potential issues. Most notably, this library only supports the NPM log levels; however, WinstonJS provides several log level configurations (docs)! Furthermore, this library does not support custom log levels, as the mapping between WinstonJS and LogDNA levels is hardcoded (file)! This is quite frustrating for developers working with custom log levels, as it means there is no way to pass some log levels through to LogDNA (or map them).

Is there a way that this level mapping could be customizable?

@kendallroth
Copy link
Author

kendallroth commented Sep 3, 2021

As a workaround, I created a patch file with patch-package to resolve our specific issue. Ideally however, it would be best to provide a custom log level mapping instead of generating patch files. Other portion to get this working was in the @logdna/logger repository (another custom patch).

Please note these are intended as temporary workarounds only :)

diff --git a/node_modules/logdna-winston/index.js b/node_modules/logdna-winston/index.js
index e17031a..81abcf9 100644
--- a/node_modules/logdna-winston/index.js
+++ b/node_modules/logdna-winston/index.js
@@ -6,7 +6,8 @@ const pkg = require('./package.json')
 
 // Convert between Winston levels and @logdna/logger levels
 const levelTranslate = new Map([
-  ['error', 'error']
+  ['critical', 'critical']
+, ['error', 'error']
 , ['warn', 'warn']
 , ['info', 'info']
 , ['http', 'debug']

@kendallroth
Copy link
Author

@darinspivey Regarding your brief mention of this repository in Issue #53, will there also be a change to support a custom Map (or something) between potentially custom WinstonJS log levels and the supported (and maybe custom) LogDNA levels?

@darinspivey
Copy link
Contributor

@kendallroth Yes, once custom levels are supported, this package will get a major change to allow the usage of custom log levels. TBD.

darinspivey added a commit that referenced this issue Sep 16, 2021
As Winston allows for the use of custom log levels, now
so does LogDNA. Custom levels can be defined for both
Winston and LogDNA such that those custom levels will
show up on LogDNA's log viewer.

BREAKING CHANGE: This removes the log level "translation"
that used to be in place to convert Winston levels to ones
that would be acceptable by LogDNA. Since LogDNA can now
define custom levels as well, this translation is no longer
needed, however it may break implementations that are
relying on the translated levels.

Fixes: #31
darinspivey added a commit that referenced this issue Sep 16, 2021
As Winston allows for the use of custom log levels, now
so does LogDNA. Custom levels can be defined for both
Winston and LogDNA such that those custom levels will
show up on LogDNA's log viewer.

BREAKING CHANGE: This removes the log level "translation"
that used to be in place to convert Winston levels to ones
that would be acceptable by LogDNA. Since LogDNA can now
define custom levels as well, this translation is no longer
needed, however it may break implementations that are
relying on the translated levels.

Fixes: #31
darinspivey added a commit that referenced this issue Sep 17, 2021
As Winston allows for the use of custom log levels, now
so does LogDNA. Custom levels can be defined for both
Winston and LogDNA such that those custom levels will
show up on LogDNA's log viewer.

BREAKING CHANGE: This removes the log level "translation"
that used to be in place to convert Winston levels to ones
that would be acceptable by LogDNA. Since LogDNA can now
define custom levels as well, this translation is no longer
needed, however it may break implementations that are
relying on the translated levels.

Fixes: #31
@darinspivey
Copy link
Contributor

@kendallroth Please let us know how this change works for you.

@logdnabot
Copy link
Member

🎉 This issue has been resolved in version 4.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@kendallroth
Copy link
Author

@darinspivey Thank you so much for your work on this; I have tested (albeit not in production yet) and verified that this resolves our use case. Simply being able to use the custom Winston levels along with a quick call to Object.keys() is extremely nice!

P.S. While testing this I did run into an unrelated bug with the transport level option (used differently by LogDNA and WinstonJS), but have opened a separate issue for that)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants