hb-smart-logger 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +19 -29
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hb-smart-logger",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "Production-ready Winston logger with daily rotation, safe JSON handling, and logger.log() alias",
5
5
  "main": "src/index.js",
6
6
  "publishConfig": {
package/src/index.js CHANGED
@@ -1,11 +1,16 @@
1
1
  const fs = require("fs");
2
2
  const path = require("path");
3
- const winston = require("winston");
3
+
4
+ /* ---------------------------------------------------
5
+ LOAD ENV (dotenv)
6
+ --------------------------------------------------- */
4
7
  const dotenv = require("dotenv");
5
- const DailyRotateFile = require("winston-daily-rotate-file");
6
8
  dotenv.config();
7
9
 
8
- // Debug flag (explicit opt-in)
10
+ const winston = require("winston");
11
+ const DailyRotateFile = require("winston-daily-rotate-file");
12
+
13
+ // Explicit debug opt-in
9
14
  const DEBUG_ENABLED = String(process.env.DEBUG).toLowerCase() === "true";
10
15
 
11
16
  // Ensure logs directory exists
@@ -60,10 +65,10 @@ const logFormat = winston.format.printf(
60
65
  );
61
66
 
62
67
  /* ---------------------------------------------------
63
- BASE LOGGER (INFO ALWAYS ENABLED)
68
+ BASE LOGGER
64
69
  --------------------------------------------------- */
65
70
  const baseLogger = winston.createLogger({
66
- level: "info", // 🔒 never suppress info
71
+ level: "debug", // allow all levels internally
67
72
  format: winston.format.combine(
68
73
  winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
69
74
  winston.format.errors({ stack: true }),
@@ -73,15 +78,15 @@ const baseLogger = winston.createLogger({
73
78
  });
74
79
 
75
80
  /* ---------------------------------------------------
76
- ROTATING FILES
81
+ FILE TRANSPORTS
77
82
  --------------------------------------------------- */
78
83
 
79
- // Combined logs → info, warn, error ALWAYS
84
+ // Combined logs
80
85
  baseLogger.add(
81
86
  new DailyRotateFile({
82
87
  dirname: path.join(logDir, "combined"),
83
88
  filename: "combined-%DATE%.log",
84
- level: "info",
89
+ level: DEBUG_ENABLED ? "debug" : "info",
85
90
  datePattern: "YYYY-MM-DD",
86
91
  zippedArchive: true,
87
92
  maxSize: "10m",
@@ -89,7 +94,7 @@ baseLogger.add(
89
94
  })
90
95
  );
91
96
 
92
- // Per-level logs (always enabled)
97
+ // Always-on per-level logs
93
98
  ["error", "warn", "info"].forEach((level) => {
94
99
  baseLogger.add(
95
100
  new DailyRotateFile({
@@ -104,7 +109,7 @@ baseLogger.add(
104
109
  );
105
110
  });
106
111
 
107
- // Debug logs ONLY if enabled
112
+ // Debug file ONLY when enabled
108
113
  if (DEBUG_ENABLED) {
109
114
  baseLogger.add(
110
115
  new DailyRotateFile({
@@ -120,13 +125,11 @@ if (DEBUG_ENABLED) {
120
125
  }
121
126
 
122
127
  /* ---------------------------------------------------
123
- CONSOLE OUTPUT
128
+ CONSOLE TRANSPORT (NO DUPLICATES)
124
129
  --------------------------------------------------- */
125
-
126
- // Info+ always to console
127
130
  baseLogger.add(
128
131
  new winston.transports.Console({
129
- level: "info",
132
+ level: DEBUG_ENABLED ? "debug" : "info",
130
133
  format: winston.format.combine(
131
134
  winston.format.colorize(),
132
135
  winston.format.simple()
@@ -134,19 +137,6 @@ baseLogger.add(
134
137
  })
135
138
  );
136
139
 
137
- // Debug to console ONLY if enabled
138
- if (DEBUG_ENABLED) {
139
- baseLogger.add(
140
- new winston.transports.Console({
141
- level: "debug",
142
- format: winston.format.combine(
143
- winston.format.colorize(),
144
- winston.format.simple()
145
- ),
146
- })
147
- );
148
- }
149
-
150
140
  /* ---------------------------------------------------
151
141
  WRAPPER (MULTI-ARGS + logger.log)
152
142
  --------------------------------------------------- */
@@ -154,10 +144,10 @@ const wrapLogger = (logger) => {
154
144
  const levels = ["info", "warn", "error", "debug"];
155
145
 
156
146
  for (const level of levels) {
157
- const original = logger[level]?.bind(logger);
147
+ const original = logger[level].bind(logger);
158
148
 
159
149
  logger[level] = (...args) => {
160
- // Hard-disable debug when DEBUG is false
150
+ // Hard-disable debug if DEBUG=false
161
151
  if (level === "debug" && !DEBUG_ENABLED) return;
162
152
 
163
153
  const merged = args