logxpert 1.0.0 → 1.0.2
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 +11 -3
- package/PATCHNOTE.md +11 -3
- package/README.fr.md +11 -10
- package/README.md +9 -8
- package/main.js +58 -34
- package/package.json +2 -1
package/PATCHNOTE.fr.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Notes de Version
|
|
2
2
|
|
|
3
|
-
## v1.0.
|
|
3
|
+
## v1.0.2
|
|
4
|
+
|
|
5
|
+
- **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.
|
|
6
|
+
- **Autres Améliorations et Corrections de Bugs :** Toutes les améliorations et fonctionnalités précédentes de la v1.0.1 LTS restent intactes.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## v1.0.1
|
|
10
|
+
|
|
11
|
+
- Amélioration de la prise en charge des formats d'horodatage personnalisés en console via Moment.js. Les utilisateurs peuvent désormais fournir des formats entièrement personnalisés (ex. : "Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - " ou "date: YYYY-MM-DD heure: HH:mm:ss - ") qui rendent correctement les dates dynamiques et le texte littéral.
|
|
12
|
+
|
|
13
|
+
## v1.0.0
|
|
4
14
|
|
|
5
15
|
- **Stabilité & Support:** Cette version est désormais la version LTS, offrant une API stable pour une utilisation en production sur le long terme.
|
|
6
16
|
- **Configuration Améliorée:** Ajout d'options avancées pour personnaliser l'horodatage en console, incluant le format, le préfixe et le suffixe personnalisables.
|
|
@@ -8,8 +18,6 @@
|
|
|
8
18
|
- **Documentation:** Mise à jour du README et de la référence API pour plus de clarté et de complétude.
|
|
9
19
|
- **Compatibilité Rétroactive:** Conservation de toutes les fonctionnalités des versions précédentes, incluant les méthodes pour la journalisation générale, d'erreur, d'avertissement, d'information et de débogage.
|
|
10
20
|
|
|
11
|
-
## Versions Précédentes
|
|
12
|
-
|
|
13
21
|
### v0.3.2
|
|
14
22
|
- Modification du motif par défaut de `filesName` passant de `'YYYY-MM-DD_HH:mm:ss'` à `'YYYY-MM-DD'`.
|
|
15
23
|
|
package/PATCHNOTE.md
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
# Patch Notes
|
|
2
2
|
|
|
3
|
-
## v1.0.
|
|
3
|
+
## v1.0.2
|
|
4
|
+
|
|
5
|
+
- **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.
|
|
6
|
+
- **Other Enhancements and Bug Fixes:** All previous improvements and features from v1.0.1 LTS remain intact.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## v1.0.1
|
|
10
|
+
|
|
11
|
+
- Improved support for fully custom console timestamp formats using Moment.js. Users can now supply completely custom formats (e.g., "This is the time: [YYYY-MM-DD HH:mm:ss] - " or "date: YYYY-MM-DD heure: HH:mm:ss - ") that correctly render dynamic dates and literal text.
|
|
12
|
+
|
|
13
|
+
## v1.0.0
|
|
4
14
|
|
|
5
15
|
- **Stability & Support:** This release is now the LTS version, providing a stable API for long-term production use.
|
|
6
16
|
- **Enhanced Configuration:** Added advanced configuration for console timestamps, including customizable format, prefix, and suffix.
|
|
@@ -8,8 +18,6 @@
|
|
|
8
18
|
- **Documentation:** Updated README and API references for clarity and completeness.
|
|
9
19
|
- **Backward Compatibility:** Retained all features from previous versions, including methods for general, error, warning, info, and debug logging.
|
|
10
20
|
|
|
11
|
-
## Previous Versions
|
|
12
|
-
|
|
13
21
|
### v0.3.2
|
|
14
22
|
- Changed the default `filesName` pattern from `'YYYY-MM-DD_HH:mm:ss'` to `'YYYY-MM-DD'`.
|
|
15
23
|
|
package/README.fr.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# LogXpert
|
|
1
|
+
# LogXpert
|
|
2
2
|
|
|
3
|
-
LogXpert est une bibliothèque de logs puissante pour Node.js qui offre des méthodes de log simples à utiliser avec une sortie colorée et, en option, l'enregistrement dans un fichier.
|
|
3
|
+
LogXpert est une bibliothèque de logs puissante pour Node.js qui offre des méthodes de log simples à utiliser avec une sortie colorée et, en option, l'enregistrement dans un fichier.
|
|
4
4
|
|
|
5
5
|
## Table des Matières
|
|
6
6
|
- [Installation](#installation)
|
|
@@ -46,7 +46,7 @@ log.debug("Ceci est un message de debug.");
|
|
|
46
46
|
|
|
47
47
|
### Journalisation avancée : Fichiers de logs & Personnalisation de l'horodatage en console
|
|
48
48
|
|
|
49
|
-
LogXpert supporte la journalisation dans des fichiers via [winston](https://github.com/winstonjs/winston) et [winston-daily-rotate-file](https://github.com/winstonjs/winston-daily-rotate-file).
|
|
49
|
+
LogXpert supporte la journalisation dans des fichiers via [winston](https://github.com/winstonjs/winston) et [winston-daily-rotate-file](https://github.com/winstonjs/winston-daily-rotate-file).
|
|
50
50
|
|
|
51
51
|
Exemple de configuration :
|
|
52
52
|
|
|
@@ -56,9 +56,10 @@ const log = require('logxpert');
|
|
|
56
56
|
log.settings({
|
|
57
57
|
console: {
|
|
58
58
|
enableTimestamp: true,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
// Vous pouvez inclure des caractères de décoration, par exemple :
|
|
60
|
+
timestampFormat: "Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - ",
|
|
61
|
+
timestampPrefix: '',
|
|
62
|
+
timestampSuffix: ''
|
|
62
63
|
},
|
|
63
64
|
files: {
|
|
64
65
|
folder: 'logs',
|
|
@@ -89,14 +90,14 @@ log.settings({
|
|
|
89
90
|
|
|
90
91
|
- **log.settings(options: object):**
|
|
91
92
|
Configure les options d'enregistrement dans un fichier et de personnalisation de la sortie console.
|
|
92
|
-
**Options Console:**
|
|
93
|
+
**Options Console :**
|
|
93
94
|
- `enableTimestamp` (boolean) : Active/désactive l'horodatage (par défaut : `true`).
|
|
94
|
-
- `timestampFormat` (string) : Format de l'horodatage (par défaut : `'YYYY-MM-DD HH:mm:ss'`).
|
|
95
|
+
- `timestampFormat` (string) : Format de l'horodatage incluant tout texte littéral ou décoration (par défaut : `'YYYY-MM-DD HH:mm:ss'`).
|
|
95
96
|
- `timestampPrefix` (string) : Préfixe de l'horodatage.
|
|
96
97
|
- `timestampSuffix` (string) : Suffixe de l'horodatage.
|
|
97
98
|
|
|
98
|
-
**Options Fichiers:**
|
|
99
|
-
- `folder` (string) : Répertoire où les fichiers de logs
|
|
99
|
+
**Options Fichiers :**
|
|
100
|
+
- `folder` (string) : Répertoire où seront stockés les fichiers de logs (par défaut : `'logs'`).
|
|
100
101
|
- `filesName` (string) : Motif de date pour le nom des fichiers de logs (par défaut : `'YYYY-MM-DD'`).
|
|
101
102
|
- `maxFile` (string) : Durée maximale de rétention des fichiers (par défaut : `'14d'`).
|
|
102
103
|
- `maxSize` (string) : Taille maximale par fichier de log (par défaut : `'20m'`).
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# LogXpert
|
|
1
|
+
# LogXpert
|
|
2
2
|
|
|
3
|
-
LogXpert is a powerful logging library for Node.js that provides easy-to-use logging methods with colorful formatted output and optional file logging support
|
|
3
|
+
LogXpert is a powerful logging library for Node.js that provides easy-to-use logging methods with colorful formatted output and optional file logging support
|
|
4
4
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
- [Installation](#installation)
|
|
@@ -46,9 +46,9 @@ log.debug('This is a debug message.');
|
|
|
46
46
|
|
|
47
47
|
### Advanced Logging: File Output & Custom Console Timestamp
|
|
48
48
|
|
|
49
|
-
LogXpert supports file logging using [winston](https://github.com/winstonjs/winston) and [winston-daily-rotate-file](https://github.com/winstonjs/winston-daily-rotate-file).
|
|
49
|
+
LogXpert supports file logging using [winston](https://github.com/winstonjs/winston) and [winston-daily-rotate-file](https://github.com/winstonjs/winston-daily-rotate-file).
|
|
50
50
|
|
|
51
|
-
Example configuration
|
|
51
|
+
Example configuration:
|
|
52
52
|
|
|
53
53
|
```js
|
|
54
54
|
const log = require('logxpert');
|
|
@@ -56,9 +56,10 @@ const log = require('logxpert');
|
|
|
56
56
|
log.settings({
|
|
57
57
|
console: {
|
|
58
58
|
enableTimestamp: true,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
// You can now include decoration characters as desired:
|
|
60
|
+
timestampFormat: "This is the date: [YYYY-MM-DD HH:mm:ss] - ",
|
|
61
|
+
timestampPrefix: '',
|
|
62
|
+
timestampSuffix: ''
|
|
62
63
|
},
|
|
63
64
|
files: {
|
|
64
65
|
folder: 'logs',
|
|
@@ -91,7 +92,7 @@ log.settings({
|
|
|
91
92
|
Configures file logging and console output options.
|
|
92
93
|
**Console Options:**
|
|
93
94
|
- `enableTimestamp` (boolean): Enable/disable timestamp (default: `true`).
|
|
94
|
-
- `timestampFormat` (string): Format for the timestamp (default: `'YYYY-MM-DD HH:mm:ss'`).
|
|
95
|
+
- `timestampFormat` (string): Format for the timestamp including any desired literal text or decoration (default: `'YYYY-MM-DD HH:mm:ss'`).
|
|
95
96
|
- `timestampPrefix` (string): Prefix for the timestamp.
|
|
96
97
|
- `timestampSuffix` (string): Suffix for the timestamp.
|
|
97
98
|
|
package/main.js
CHANGED
|
@@ -1,13 +1,37 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
|
+
const moment = require('moment'); // Add moment as a dependency: npm install moment
|
|
2
3
|
const { createLogger, format, transports } = require('winston');
|
|
3
4
|
require('winston-daily-rotate-file');
|
|
4
5
|
|
|
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.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} fmt - The user-defined format string.
|
|
12
|
+
* @returns {string} - The formatted timestamp with any decoration brackets preserved.
|
|
13
|
+
*
|
|
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] - "
|
|
17
|
+
*/
|
|
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
|
|
22
|
+
const formatted = moment().format(temp);
|
|
23
|
+
// Restore the original bracket characters
|
|
24
|
+
return formatted.replace(/__LB__/g, '[').replace(/__RB__/g, ']');
|
|
25
|
+
}
|
|
26
|
+
|
|
5
27
|
/**
|
|
6
28
|
* @typedef {Object} ConsoleOptions
|
|
7
29
|
* @property {boolean} [enableTimestamp=true] - Enable or disable timestamp in console logs.
|
|
8
|
-
* @property {string} [timestampFormat='YYYY-MM-DD HH:mm:ss'] -
|
|
9
|
-
*
|
|
10
|
-
*
|
|
30
|
+
* @property {string} [timestampFormat='YYYY-MM-DD HH:mm:ss'] - Custom format for the timestamp.
|
|
31
|
+
* You can include any decoration characters ([], (), {}) without interference.
|
|
32
|
+
* For example:
|
|
33
|
+
* - "Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - "
|
|
34
|
+
* - "date: YYYY-MM-DD heure: HH:mm:ss - "
|
|
11
35
|
*/
|
|
12
36
|
|
|
13
37
|
/**
|
|
@@ -25,16 +49,21 @@ require('winston-daily-rotate-file');
|
|
|
25
49
|
* @property {FilesOptions} [files] - Options for configuring file logging.
|
|
26
50
|
*/
|
|
27
51
|
|
|
28
|
-
// Custom format for logger
|
|
52
|
+
// Custom format for logger output
|
|
29
53
|
const customFormat = format.printf(({ timestamp, level, message }) => {
|
|
30
54
|
return timestamp ? `${timestamp} [${level}]: ${message}` : `[${level}]: ${message}`;
|
|
31
55
|
});
|
|
32
56
|
|
|
33
|
-
//
|
|
57
|
+
// Default console timestamp format
|
|
58
|
+
const defaultConsoleFormat = 'YYYY-MM-DD HH:mm:ss';
|
|
59
|
+
|
|
60
|
+
// Create a default console transport with timestamp enabled using the default format
|
|
34
61
|
let consoleTransport = new transports.Console({
|
|
35
62
|
format: format.combine(
|
|
36
63
|
format.colorize(),
|
|
37
|
-
format.timestamp({
|
|
64
|
+
format.timestamp({
|
|
65
|
+
format: () => moment().format(defaultConsoleFormat)
|
|
66
|
+
}),
|
|
38
67
|
customFormat
|
|
39
68
|
)
|
|
40
69
|
});
|
|
@@ -43,7 +72,9 @@ let consoleTransport = new transports.Console({
|
|
|
43
72
|
const logger = createLogger({
|
|
44
73
|
level: 'debug',
|
|
45
74
|
format: format.combine(
|
|
46
|
-
format.timestamp({
|
|
75
|
+
format.timestamp({
|
|
76
|
+
format: () => moment().format(defaultConsoleFormat)
|
|
77
|
+
}),
|
|
47
78
|
customFormat
|
|
48
79
|
),
|
|
49
80
|
transports: [consoleTransport]
|
|
@@ -54,16 +85,16 @@ let fileTransport;
|
|
|
54
85
|
|
|
55
86
|
/**
|
|
56
87
|
* Configures logging settings for both console and file transports.
|
|
57
|
-
*
|
|
58
|
-
* @param {LogSettingsOptions} options - The settings for console and file logging.
|
|
88
|
+
*
|
|
89
|
+
* @param {LogSettingsOptions} options - The settings for both console and file logging.
|
|
59
90
|
* @example
|
|
60
|
-
* //
|
|
91
|
+
* // Example: Fully custom console timestamp that preserves decoration,
|
|
92
|
+
* // and enabling file logging.
|
|
61
93
|
* log.settings({
|
|
62
94
|
* console: {
|
|
63
95
|
* enableTimestamp: true,
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* timestampSuffix: ' [END]'
|
|
96
|
+
* // You can now include brackets or parentheses as decoration:
|
|
97
|
+
* timestampFormat: "Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - "
|
|
67
98
|
* },
|
|
68
99
|
* files: {
|
|
69
100
|
* folder: 'logs',
|
|
@@ -78,26 +109,20 @@ function applySettings(options = {}) {
|
|
|
78
109
|
// Update console transport if configuration is provided
|
|
79
110
|
if (options.console) {
|
|
80
111
|
const enableTimestamp = options.console.enableTimestamp !== undefined ? options.console.enableTimestamp : true;
|
|
81
|
-
const timestampFormat = options.console.timestampFormat ||
|
|
82
|
-
const timestampPrefix = options.console.timestampPrefix || '';
|
|
83
|
-
const timestampSuffix = options.console.timestampSuffix || '';
|
|
112
|
+
const timestampFormat = options.console.timestampFormat || defaultConsoleFormat;
|
|
84
113
|
|
|
85
114
|
// Remove the current console transport
|
|
86
115
|
logger.remove(consoleTransport);
|
|
87
116
|
|
|
88
|
-
// Create new console transport based on the provided options
|
|
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.
|
|
89
119
|
consoleTransport = new transports.Console({
|
|
90
120
|
format: enableTimestamp
|
|
91
121
|
? format.combine(
|
|
92
122
|
format.colorize(),
|
|
93
|
-
format.timestamp({
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (info.timestamp) {
|
|
97
|
-
info.timestamp = timestampPrefix + info.timestamp + timestampSuffix;
|
|
98
|
-
}
|
|
99
|
-
return info;
|
|
100
|
-
})(),
|
|
123
|
+
format.timestamp({
|
|
124
|
+
format: () => formatCustomTimestamp(timestampFormat)
|
|
125
|
+
}),
|
|
101
126
|
customFormat
|
|
102
127
|
)
|
|
103
128
|
: format.combine(
|
|
@@ -126,7 +151,7 @@ function applySettings(options = {}) {
|
|
|
126
151
|
logger.remove(fileTransport);
|
|
127
152
|
}
|
|
128
153
|
|
|
129
|
-
// Create a new daily
|
|
154
|
+
// Create a new daily-rotate file transport with provided/default settings
|
|
130
155
|
fileTransport = new transports.DailyRotateFile({
|
|
131
156
|
filename: `${folder}/application-%DATE%.log`,
|
|
132
157
|
datePattern,
|
|
@@ -134,15 +159,14 @@ function applySettings(options = {}) {
|
|
|
134
159
|
maxSize,
|
|
135
160
|
maxFiles
|
|
136
161
|
});
|
|
137
|
-
|
|
138
162
|
logger.add(fileTransport);
|
|
139
163
|
}
|
|
140
164
|
}
|
|
141
165
|
|
|
142
166
|
/**
|
|
143
167
|
* Logs a general message using the info level.
|
|
144
|
-
*
|
|
145
|
-
* @param {string} message -
|
|
168
|
+
*
|
|
169
|
+
* @param {string} message - The message to be logged.
|
|
146
170
|
*/
|
|
147
171
|
function log(message) {
|
|
148
172
|
logger.info(message);
|
|
@@ -150,7 +174,7 @@ function log(message) {
|
|
|
150
174
|
|
|
151
175
|
/**
|
|
152
176
|
* Logs an error message.
|
|
153
|
-
* @param {string} message -
|
|
177
|
+
* @param {string} message - The error message.
|
|
154
178
|
*/
|
|
155
179
|
log.error = function (message) {
|
|
156
180
|
logger.error(message);
|
|
@@ -158,7 +182,7 @@ log.error = function (message) {
|
|
|
158
182
|
|
|
159
183
|
/**
|
|
160
184
|
* Logs a warning message.
|
|
161
|
-
* @param {string} message -
|
|
185
|
+
* @param {string} message - The warning message.
|
|
162
186
|
*/
|
|
163
187
|
log.warn = function (message) {
|
|
164
188
|
logger.warn(message);
|
|
@@ -166,7 +190,7 @@ log.warn = function (message) {
|
|
|
166
190
|
|
|
167
191
|
/**
|
|
168
192
|
* Logs an informational message.
|
|
169
|
-
* @param {string} message -
|
|
193
|
+
* @param {string} message - The informational message.
|
|
170
194
|
*/
|
|
171
195
|
log.info = function (message) {
|
|
172
196
|
logger.info(message);
|
|
@@ -174,13 +198,13 @@ log.info = function (message) {
|
|
|
174
198
|
|
|
175
199
|
/**
|
|
176
200
|
* Logs a debug message.
|
|
177
|
-
* @param {string} message -
|
|
201
|
+
* @param {string} message - The debug message.
|
|
178
202
|
*/
|
|
179
203
|
log.debug = function (message) {
|
|
180
204
|
logger.debug(message);
|
|
181
205
|
};
|
|
182
206
|
|
|
183
|
-
// Expose the settings function for configuring file logging and console output
|
|
207
|
+
// Expose the settings function for configuring both file logging and console output
|
|
184
208
|
log.settings = applySettings;
|
|
185
209
|
|
|
186
210
|
module.exports = log;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "logxpert",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A powerful logging library for Node.js",
|
|
5
5
|
"main": "main.js",
|
|
6
6
|
"repository": {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
"author": "https://github.com/lighscent",
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"dependencies": {
|
|
13
|
+
"moment": "^2.30.1",
|
|
13
14
|
"winston": "^3.17.0",
|
|
14
15
|
"winston-daily-rotate-file": "^5.0.0"
|
|
15
16
|
}
|