logxpert 1.0.2 → 1.0.4-0

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.
package/PATCHNOTE.fr.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Notes de Version
2
2
 
3
+ ## v1.0.3
4
+
5
+ - **Correction de la désactivation de l'horodatage :** Correction du problème où, malgré `enableTimestamp: false`, l'horodatage était toujours affiché. L'horodatage est désormais complètement désactivé en console lorsque requis.
6
+ - **Correction de l'horodatage personnalisé avec décoration :** Résolution des problèmes de formatage lors de l'utilisation de formats d'horodatage personnalisés avec des caractères décoratifs (par exemple, des crochets). Des formats comme `"Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - "` s'affichent correctement.
7
+ - Toutes les améliorations et fonctionnalités précédentes de la v1.0.2 LTS restent intactes.
8
+
3
9
  ## v1.0.2
4
10
 
5
11
  - **Préservation de la Décoration dans l'Horodatage Personnalisé :** Ajout d'une fonction d'assistance dans le module de log qui permet de conserver les caractères de décoration (tels que [], (), {}) dans le `timestampFormat` tel que défini par l'utilisateur. Cette amélioration permet d'utiliser des formats comme `"Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - "` ou `"date: YYYY-MM-DD heure: HH:mm:ss - "` sans que Moment.js n'échappe automatiquement les crochets.
package/PATCHNOTE.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Patch Notes
2
2
 
3
+ ## v1.0.3
4
+
5
+ - **Timestamp Disabling Fix:** Corrected the issue where setting `enableTimestamp: false` still printed a timestamp. Timestamps are now completely disabled in the console output when requested.
6
+ - **Custom Timestamp Decoration Fix:** Resolved formatting glitches when using custom timestamp formats with decorative characters (e.g., square brackets) so that formats like `"This is the date: [YYYY-MM-DD HH:mm:ss] - "` render correctly.
7
+ - All previous enhancements and features from v1.0.2 LTS remain intact.
8
+
3
9
  ## v1.0.2
4
10
 
5
11
  - **Custom Timestamp Decoration Preservation:** Introduced a helper function in the logging module to allow any decoration characters (such as [], (), {}) in the `timestampFormat` to be preserved as supplied by the user. This improvement lets you use formats like `"This is the date: [YYYY-MM-DD HH:mm:ss] - "` or `"date: YYYY-MM-DD heure: HH:mm:ss - "` without Moment.js automatically escaping the brackets.
package/main.js CHANGED
@@ -4,33 +4,34 @@ const { createLogger, format, transports } = require('winston');
4
4
  require('winston-daily-rotate-file');
5
5
 
6
6
  /**
7
- * Helper function to format the timestamp while preserving bracket characters.
8
- * This function replaces all occurrences of '[' and ']' with temporary placeholders
9
- * so that Moment.js does not treat them as escapes. After formatting, it restores them.
7
+ * Helper function to format the timestamp while preserving square brackets.
8
+ * It replaces "[" with "%%LB%%" and "]" with "%%RB%%" to prevent Moment.js from
9
+ * treating the contents as literal text. After formatting, the placeholders are restored.
10
10
  *
11
11
  * @param {string} fmt - The user-defined format string.
12
- * @returns {string} - The formatted timestamp with any decoration brackets preserved.
12
+ * @returns {string} - The formatted timestamp with square brackets preserved.
13
13
  *
14
14
  * Example:
15
- * Input: "Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - "
16
- * Might output: "Voici la date et l'heure: [2025-03-21 15:30:45] - "
15
+ * Input: "This is the date: [YYYY-MM-DD HH:mm:ss] - "
16
+ * Might output: "This is the date: [2025-03-21 15:30:45] - "
17
17
  */
18
18
  function formatCustomTimestamp(fmt) {
19
- // Replace square brackets with placeholders
20
- const temp = fmt.replace(/\[/g, '__LB__').replace(/\]/g, '__RB__');
21
- // Let moment replace tokens in the modified string
19
+ // Replace square brackets with temporary placeholders that won't interfere with Moment.js formatting
20
+ const temp = fmt.replace(/\[/g, '%%LB%%').replace(/\]/g, '%%RB%%');
21
+ // Format the timestamp using Moment.js
22
22
  const formatted = moment().format(temp);
23
- // Restore the original bracket characters
24
- return formatted.replace(/__LB__/g, '[').replace(/__RB__/g, ']');
23
+ // Replace the placeholders back with the square brackets
24
+ return formatted.replace(/%%LB%%/g, '[').replace(/%%RB%%/g, ']');
25
25
  }
26
26
 
27
+
27
28
  /**
28
29
  * @typedef {Object} ConsoleOptions
29
30
  * @property {boolean} [enableTimestamp=true] - Enable or disable timestamp in console logs.
30
31
  * @property {string} [timestampFormat='YYYY-MM-DD HH:mm:ss'] - Custom format for the timestamp.
31
32
  * You can include any decoration characters ([], (), {}) without interference.
32
33
  * For example:
33
- * - "Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - "
34
+ * - "This is the date: [YYYY-MM-DD HH:mm:ss] - "
34
35
  * - "date: YYYY-MM-DD heure: HH:mm:ss - "
35
36
  */
36
37
 
@@ -57,28 +58,24 @@ const customFormat = format.printf(({ timestamp, level, message }) => {
57
58
  // Default console timestamp format
58
59
  const defaultConsoleFormat = 'YYYY-MM-DD HH:mm:ss';
59
60
 
60
- // Create a default console transport with timestamp enabled using the default format
61
- let consoleTransport = new transports.Console({
61
+ // Create the global logger. Its default format will be overridden by the console transport settings.
62
+ const logger = createLogger({
63
+ level: 'debug',
62
64
  format: format.combine(
63
- format.colorize(),
64
- format.timestamp({
65
- format: () => moment().format(defaultConsoleFormat)
66
- }),
65
+ format.timestamp({ format: () => moment().format(defaultConsoleFormat) }),
67
66
  customFormat
68
67
  )
69
68
  });
70
69
 
71
- // Create a logger with the default console transport
72
- const logger = createLogger({
73
- level: 'debug',
70
+ // Create default console transport (will be replaced via settings)
71
+ let consoleTransport = new transports.Console({
74
72
  format: format.combine(
75
- format.timestamp({
76
- format: () => moment().format(defaultConsoleFormat)
77
- }),
73
+ format.colorize(),
74
+ format.timestamp({ format: () => moment().format(defaultConsoleFormat) }),
78
75
  customFormat
79
- ),
80
- transports: [consoleTransport]
76
+ )
81
77
  });
78
+ logger.add(consoleTransport);
82
79
 
83
80
  // Reference to file transport (added via settings)
84
81
  let fileTransport;
@@ -88,13 +85,12 @@ let fileTransport;
88
85
  *
89
86
  * @param {LogSettingsOptions} options - The settings for both console and file logging.
90
87
  * @example
91
- * // Example: Fully custom console timestamp that preserves decoration,
88
+ * // Example: Fully custom console timestamp that preserves decorational brackets,
92
89
  * // and enabling file logging.
93
90
  * log.settings({
94
91
  * console: {
95
92
  * enableTimestamp: true,
96
- * // You can now include brackets or parentheses as decoration:
97
- * timestampFormat: "Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - "
93
+ * timestampFormat: "This is the date: [YYYY-MM-DD HH:mm:ss] - "
98
94
  * },
99
95
  * files: {
100
96
  * folder: 'logs',
@@ -106,7 +102,6 @@ let fileTransport;
106
102
  * });
107
103
  */
108
104
  function applySettings(options = {}) {
109
- // Update console transport if configuration is provided
110
105
  if (options.console) {
111
106
  const enableTimestamp = options.console.enableTimestamp !== undefined ? options.console.enableTimestamp : true;
112
107
  const timestampFormat = options.console.timestampFormat || defaultConsoleFormat;
@@ -114,26 +109,25 @@ function applySettings(options = {}) {
114
109
  // Remove the current console transport
115
110
  logger.remove(consoleTransport);
116
111
 
117
- // Create new console transport based on the provided options.
118
- // Here, we use our helper function to let tokens be replaced while preserving any decoration.
112
+ // Build the console format based on the enableTimestamp flag.
113
+ const consoleFormat = enableTimestamp
114
+ ? format.combine(
115
+ format.colorize(),
116
+ format.timestamp({ format: () => formatCustomTimestamp(timestampFormat) }),
117
+ customFormat
118
+ )
119
+ : format.combine(
120
+ format((info) => { delete info.timestamp; return info; })(),
121
+ format.colorize(),
122
+ customFormat
123
+ );
124
+
119
125
  consoleTransport = new transports.Console({
120
- format: enableTimestamp
121
- ? format.combine(
122
- format.colorize(),
123
- format.timestamp({
124
- format: () => formatCustomTimestamp(timestampFormat)
125
- }),
126
- customFormat
127
- )
128
- : format.combine(
129
- format.colorize(),
130
- customFormat
131
- )
126
+ format: consoleFormat
132
127
  });
133
128
  logger.add(consoleTransport);
134
129
  }
135
130
 
136
- // Enable file logging if options.files is provided
137
131
  if (options.files) {
138
132
  const folder = options.files.folder || 'logs';
139
133
  const datePattern = options.files.filesName || 'YYYY-MM-DD';
@@ -141,17 +135,14 @@ function applySettings(options = {}) {
141
135
  const maxSize = options.files.maxSize || '20m';
142
136
  const zippedArchive = options.files.zippedArchive !== undefined ? options.files.zippedArchive : false;
143
137
 
144
- // Ensure the log folder exists
145
138
  if (!fs.existsSync(folder)) {
146
139
  fs.mkdirSync(folder, { recursive: true });
147
140
  }
148
141
 
149
- // Remove existing file transport if it exists
150
142
  if (fileTransport) {
151
143
  logger.remove(fileTransport);
152
144
  }
153
145
 
154
- // Create a new daily-rotate file transport with provided/default settings
155
146
  fileTransport = new transports.DailyRotateFile({
156
147
  filename: `${folder}/application-%DATE%.log`,
157
148
  datePattern,
@@ -172,39 +163,23 @@ function log(message) {
172
163
  logger.info(message);
173
164
  }
174
165
 
175
- /**
176
- * Logs an error message.
177
- * @param {string} message - The error message.
178
- */
179
166
  log.error = function (message) {
180
167
  logger.error(message);
181
168
  };
182
169
 
183
- /**
184
- * Logs a warning message.
185
- * @param {string} message - The warning message.
186
- */
187
170
  log.warn = function (message) {
188
171
  logger.warn(message);
189
172
  };
190
173
 
191
- /**
192
- * Logs an informational message.
193
- * @param {string} message - The informational message.
194
- */
195
174
  log.info = function (message) {
196
175
  logger.info(message);
197
176
  };
198
177
 
199
- /**
200
- * Logs a debug message.
201
- * @param {string} message - The debug message.
202
- */
203
178
  log.debug = function (message) {
204
179
  logger.debug(message);
205
180
  };
206
181
 
207
- // Expose the settings function for configuring both file logging and console output
182
+ // Expose the settings function for configuring both file logging and console output.
208
183
  log.settings = applySettings;
209
184
 
210
185
  module.exports = log;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logxpert",
3
- "version": "1.0.2",
3
+ "version": "1.0.4-0",
4
4
  "description": "A powerful logging library for Node.js",
5
5
  "main": "main.js",
6
6
  "repository": {
@@ -14,4 +14,4 @@
14
14
  "winston": "^3.17.0",
15
15
  "winston-daily-rotate-file": "^5.0.0"
16
16
  }
17
- }
17
+ }