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

Publish debug informations through the debug package #105

Open
clouedoc opened this issue Mar 24, 2022 · 0 comments
Open

Publish debug informations through the debug package #105

clouedoc opened this issue Mar 24, 2022 · 0 comments

Comments

@clouedoc
Copy link
Contributor

clouedoc commented Mar 24, 2022

Hi! 👋

Firstly, thanks for creating this life-saving package! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

My problem was that I added a double-slash at the end of my Loki URL.
e.g. I supplied http://host/ instead of http://host

The patch I'm submitting will help others debug this kind of problem in the future.
I suggest using the almost-standard debug package to supply the user with debugging information.

To enable printing of the debugging information, the user only has to define the following environment variable:

DEBUG=winston-loki

By using this environment variable, the user will get debug information printed to the console like so:

image

Here is a rough implementation example:

diff --git a/node_modules/winston-loki/src/requests.js b/node_modules/winston-loki/src/requests.js
index 5f57fdc..18a7af3 100644
--- a/node_modules/winston-loki/src/requests.js
+++ b/node_modules/winston-loki/src/requests.js
@@ -1,5 +1,6 @@
 const http = require('http')
 const https = require('https')
+const debug = require('debug')('winston-loki')
 
 const post = async (lokiUrl, contentType, headers = {}, data = '', timeout) => {
   // Construct a buffer from the data string to have deterministic data size
@@ -25,6 +26,8 @@ const post = async (lokiUrl, contentType, headers = {}, data = '', timeout) => {
       timeout: timeout
     }
 
+    debug("sending options: " + JSON.stringify(options, undefined, 2))
+
     // Construct the request
     const req = lib.request(options, res => {
       let resData = ''
@@ -34,6 +37,7 @@ const post = async (lokiUrl, contentType, headers = {}, data = '', timeout) => {
 
     // Error listener
     req.on('error', error => {
+      debug("loki HTTP error: " + error)
       reject(error)
     })
 

I'm interested in creating a PR for this feature.

Thank you for your attention.

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

No branches or pull requests

1 participant