logxpert 1.0.2 → 1.0.3
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 +6 -0
- package/PATCHNOTE.md +6 -0
- package/main.js +38 -65
- package/package.json +1 -1
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,24 +4,23 @@ 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
|
|
8
|
-
*
|
|
9
|
-
*
|
|
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
|
|
12
|
+
* @returns {string} - The formatted timestamp with square brackets preserved.
|
|
13
13
|
*
|
|
14
14
|
* Example:
|
|
15
|
-
* Input: "
|
|
16
|
-
* Might output: "
|
|
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
|
-
//
|
|
20
|
-
const temp = fmt.replace(/\[/g, '
|
|
21
|
-
// Let moment replace tokens in the modified string
|
|
19
|
+
// Use a placeholder that's unlikely to be parsed by moment
|
|
20
|
+
const temp = fmt.replace(/\[/g, '%%LB%%').replace(/\]/g, '%%RB%%');
|
|
22
21
|
const formatted = moment().format(temp);
|
|
23
|
-
// Restore the original
|
|
24
|
-
return formatted.replace(
|
|
22
|
+
// Restore the original square brackets
|
|
23
|
+
return formatted.replace(/%%LB%%/g, '[').replace(/%%RB%%/g, ']');
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
/**
|
|
@@ -30,7 +29,7 @@ function formatCustomTimestamp(fmt) {
|
|
|
30
29
|
* @property {string} [timestampFormat='YYYY-MM-DD HH:mm:ss'] - Custom format for the timestamp.
|
|
31
30
|
* You can include any decoration characters ([], (), {}) without interference.
|
|
32
31
|
* For example:
|
|
33
|
-
* - "
|
|
32
|
+
* - "This is the date: [YYYY-MM-DD HH:mm:ss] - "
|
|
34
33
|
* - "date: YYYY-MM-DD heure: HH:mm:ss - "
|
|
35
34
|
*/
|
|
36
35
|
|
|
@@ -57,28 +56,24 @@ const customFormat = format.printf(({ timestamp, level, message }) => {
|
|
|
57
56
|
// Default console timestamp format
|
|
58
57
|
const defaultConsoleFormat = 'YYYY-MM-DD HH:mm:ss';
|
|
59
58
|
|
|
60
|
-
// Create
|
|
61
|
-
|
|
59
|
+
// Create the global logger. Its default format will be overridden by the console transport settings.
|
|
60
|
+
const logger = createLogger({
|
|
61
|
+
level: 'debug',
|
|
62
62
|
format: format.combine(
|
|
63
|
-
format.
|
|
64
|
-
format.timestamp({
|
|
65
|
-
format: () => moment().format(defaultConsoleFormat)
|
|
66
|
-
}),
|
|
63
|
+
format.timestamp({ format: () => moment().format(defaultConsoleFormat) }),
|
|
67
64
|
customFormat
|
|
68
65
|
)
|
|
69
66
|
});
|
|
70
67
|
|
|
71
|
-
// Create
|
|
72
|
-
|
|
73
|
-
level: 'debug',
|
|
68
|
+
// Create default console transport (will be replaced via settings)
|
|
69
|
+
let consoleTransport = new transports.Console({
|
|
74
70
|
format: format.combine(
|
|
75
|
-
format.
|
|
76
|
-
|
|
77
|
-
}),
|
|
71
|
+
format.colorize(),
|
|
72
|
+
format.timestamp({ format: () => moment().format(defaultConsoleFormat) }),
|
|
78
73
|
customFormat
|
|
79
|
-
)
|
|
80
|
-
transports: [consoleTransport]
|
|
74
|
+
)
|
|
81
75
|
});
|
|
76
|
+
logger.add(consoleTransport);
|
|
82
77
|
|
|
83
78
|
// Reference to file transport (added via settings)
|
|
84
79
|
let fileTransport;
|
|
@@ -88,13 +83,12 @@ let fileTransport;
|
|
|
88
83
|
*
|
|
89
84
|
* @param {LogSettingsOptions} options - The settings for both console and file logging.
|
|
90
85
|
* @example
|
|
91
|
-
* // Example: Fully custom console timestamp that preserves
|
|
86
|
+
* // Example: Fully custom console timestamp that preserves decorational brackets,
|
|
92
87
|
* // and enabling file logging.
|
|
93
88
|
* log.settings({
|
|
94
89
|
* console: {
|
|
95
90
|
* enableTimestamp: true,
|
|
96
|
-
*
|
|
97
|
-
* timestampFormat: "Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - "
|
|
91
|
+
* timestampFormat: "This is the date: [YYYY-MM-DD HH:mm:ss] - "
|
|
98
92
|
* },
|
|
99
93
|
* files: {
|
|
100
94
|
* folder: 'logs',
|
|
@@ -106,7 +100,6 @@ let fileTransport;
|
|
|
106
100
|
* });
|
|
107
101
|
*/
|
|
108
102
|
function applySettings(options = {}) {
|
|
109
|
-
// Update console transport if configuration is provided
|
|
110
103
|
if (options.console) {
|
|
111
104
|
const enableTimestamp = options.console.enableTimestamp !== undefined ? options.console.enableTimestamp : true;
|
|
112
105
|
const timestampFormat = options.console.timestampFormat || defaultConsoleFormat;
|
|
@@ -114,26 +107,25 @@ function applySettings(options = {}) {
|
|
|
114
107
|
// Remove the current console transport
|
|
115
108
|
logger.remove(consoleTransport);
|
|
116
109
|
|
|
117
|
-
//
|
|
118
|
-
|
|
110
|
+
// Build the console format based on the enableTimestamp flag.
|
|
111
|
+
const consoleFormat = enableTimestamp
|
|
112
|
+
? format.combine(
|
|
113
|
+
format.colorize(),
|
|
114
|
+
format.timestamp({ format: () => formatCustomTimestamp(timestampFormat) }),
|
|
115
|
+
customFormat
|
|
116
|
+
)
|
|
117
|
+
: format.combine(
|
|
118
|
+
format((info) => { delete info.timestamp; return info; })(),
|
|
119
|
+
format.colorize(),
|
|
120
|
+
customFormat
|
|
121
|
+
);
|
|
122
|
+
|
|
119
123
|
consoleTransport = new transports.Console({
|
|
120
|
-
format:
|
|
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
|
-
)
|
|
124
|
+
format: consoleFormat
|
|
132
125
|
});
|
|
133
126
|
logger.add(consoleTransport);
|
|
134
127
|
}
|
|
135
128
|
|
|
136
|
-
// Enable file logging if options.files is provided
|
|
137
129
|
if (options.files) {
|
|
138
130
|
const folder = options.files.folder || 'logs';
|
|
139
131
|
const datePattern = options.files.filesName || 'YYYY-MM-DD';
|
|
@@ -141,17 +133,14 @@ function applySettings(options = {}) {
|
|
|
141
133
|
const maxSize = options.files.maxSize || '20m';
|
|
142
134
|
const zippedArchive = options.files.zippedArchive !== undefined ? options.files.zippedArchive : false;
|
|
143
135
|
|
|
144
|
-
// Ensure the log folder exists
|
|
145
136
|
if (!fs.existsSync(folder)) {
|
|
146
137
|
fs.mkdirSync(folder, { recursive: true });
|
|
147
138
|
}
|
|
148
139
|
|
|
149
|
-
// Remove existing file transport if it exists
|
|
150
140
|
if (fileTransport) {
|
|
151
141
|
logger.remove(fileTransport);
|
|
152
142
|
}
|
|
153
143
|
|
|
154
|
-
// Create a new daily-rotate file transport with provided/default settings
|
|
155
144
|
fileTransport = new transports.DailyRotateFile({
|
|
156
145
|
filename: `${folder}/application-%DATE%.log`,
|
|
157
146
|
datePattern,
|
|
@@ -172,39 +161,23 @@ function log(message) {
|
|
|
172
161
|
logger.info(message);
|
|
173
162
|
}
|
|
174
163
|
|
|
175
|
-
/**
|
|
176
|
-
* Logs an error message.
|
|
177
|
-
* @param {string} message - The error message.
|
|
178
|
-
*/
|
|
179
164
|
log.error = function (message) {
|
|
180
165
|
logger.error(message);
|
|
181
166
|
};
|
|
182
167
|
|
|
183
|
-
/**
|
|
184
|
-
* Logs a warning message.
|
|
185
|
-
* @param {string} message - The warning message.
|
|
186
|
-
*/
|
|
187
168
|
log.warn = function (message) {
|
|
188
169
|
logger.warn(message);
|
|
189
170
|
};
|
|
190
171
|
|
|
191
|
-
/**
|
|
192
|
-
* Logs an informational message.
|
|
193
|
-
* @param {string} message - The informational message.
|
|
194
|
-
*/
|
|
195
172
|
log.info = function (message) {
|
|
196
173
|
logger.info(message);
|
|
197
174
|
};
|
|
198
175
|
|
|
199
|
-
/**
|
|
200
|
-
* Logs a debug message.
|
|
201
|
-
* @param {string} message - The debug message.
|
|
202
|
-
*/
|
|
203
176
|
log.debug = function (message) {
|
|
204
177
|
logger.debug(message);
|
|
205
178
|
};
|
|
206
179
|
|
|
207
|
-
// Expose the settings function for configuring both file logging and console output
|
|
180
|
+
// Expose the settings function for configuring both file logging and console output.
|
|
208
181
|
log.settings = applySettings;
|
|
209
182
|
|
|
210
183
|
module.exports = log;
|