logxpert 1.0.0 → 1.0.1
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 +5 -1
- package/PATCHNOTE.md +5 -1
- package/README.fr.md +12 -9
- package/README.md +11 -8
- package/main.js +35 -33
- package/package.json +2 -1
package/PATCHNOTE.fr.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# Notes de Version
|
|
2
2
|
|
|
3
|
-
## v1.0.
|
|
3
|
+
## v1.0.1
|
|
4
|
+
|
|
5
|
+
- 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.
|
|
6
|
+
|
|
7
|
+
## v1.0.0
|
|
4
8
|
|
|
5
9
|
- **Stabilité & Support:** Cette version est désormais la version LTS, offrant une API stable pour une utilisation en production sur le long terme.
|
|
6
10
|
- **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.
|
package/PATCHNOTE.md
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
# Patch Notes
|
|
2
2
|
|
|
3
|
-
## v1.0.
|
|
3
|
+
## v1.0.1
|
|
4
|
+
|
|
5
|
+
- 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.
|
|
6
|
+
|
|
7
|
+
## v1.0.0
|
|
4
8
|
|
|
5
9
|
- **Stability & Support:** This release is now the LTS version, providing a stable API for long-term production use.
|
|
6
10
|
- **Enhanced Configuration:** Added advanced configuration for console timestamps, including customizable format, prefix, and suffix.
|
package/README.fr.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# LogXpert v1.0.
|
|
1
|
+
# LogXpert v1.0.1 LTS
|
|
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. Dans cette version LTS v1.0.1, nous avons amélioré la personnalisation de l'horodatage en console et apporté plusieurs améliorations.
|
|
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). Vous pouvez configurer l'enregistrement dans un fichier ainsi que personnaliser l'horodatage en console grâce à `log.settings()`.
|
|
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). Vous pouvez configurer l'enregistrement dans un fichier ainsi que personnaliser pleinement l'horodatage en console grâce à `log.settings()`.
|
|
50
50
|
|
|
51
51
|
Exemple de configuration :
|
|
52
52
|
|
|
@@ -56,9 +56,12 @@ const log = require('logxpert');
|
|
|
56
56
|
log.settings({
|
|
57
57
|
console: {
|
|
58
58
|
enableTimestamp: true,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
// Exemple 1 : Inclure du texte littéral avec des tokens
|
|
60
|
+
timestampFormat: "Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - ",
|
|
61
|
+
// Exemple 2 : Séparer les tokens pour la date et l'heure
|
|
62
|
+
// timestampFormat: "date: YYYY-MM-DD heure: HH:mm:ss - "
|
|
63
|
+
timestampPrefix: '',
|
|
64
|
+
timestampSuffix: ''
|
|
62
65
|
},
|
|
63
66
|
files: {
|
|
64
67
|
folder: 'logs',
|
|
@@ -89,13 +92,13 @@ log.settings({
|
|
|
89
92
|
|
|
90
93
|
- **log.settings(options: object):**
|
|
91
94
|
Configure les options d'enregistrement dans un fichier et de personnalisation de la sortie console.
|
|
92
|
-
**Options Console:**
|
|
95
|
+
**Options Console :**
|
|
93
96
|
- `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'`).
|
|
97
|
+
- `timestampFormat` (string) : Format de l'horodatage (par défaut : `'YYYY-MM-DD HH:mm:ss'`). Vous pouvez inclure du texte littéral si nécessaire.
|
|
95
98
|
- `timestampPrefix` (string) : Préfixe de l'horodatage.
|
|
96
99
|
- `timestampSuffix` (string) : Suffixe de l'horodatage.
|
|
97
100
|
|
|
98
|
-
**Options Fichiers:**
|
|
101
|
+
**Options Fichiers :**
|
|
99
102
|
- `folder` (string) : Répertoire où les fichiers de logs seront stockés (par défaut : `'logs'`).
|
|
100
103
|
- `filesName` (string) : Motif de date pour le nom des fichiers de logs (par défaut : `'YYYY-MM-DD'`).
|
|
101
104
|
- `maxFile` (string) : Durée maximale de rétention des fichiers (par défaut : `'14d'`).
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# LogXpert v1.0.
|
|
1
|
+
# LogXpert v1.0.1 LTS
|
|
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. In this LTS release, v1.0.1, we have enhanced custom console timestamp formatting and made several improvements.
|
|
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). You can configure file logging and customize console timestamps via `log.settings()`.
|
|
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). You can configure file logging and fully customize console timestamps via `log.settings()`.
|
|
50
50
|
|
|
51
|
-
Example configuration
|
|
51
|
+
Example configuration:
|
|
52
52
|
|
|
53
53
|
```js
|
|
54
54
|
const log = require('logxpert');
|
|
@@ -56,9 +56,12 @@ const log = require('logxpert');
|
|
|
56
56
|
log.settings({
|
|
57
57
|
console: {
|
|
58
58
|
enableTimestamp: true,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
// Example 1: Including literal text with tokens
|
|
60
|
+
timestampFormat: "Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - ",
|
|
61
|
+
// Example 2: Separating date and time tokens:
|
|
62
|
+
// timestampFormat: "date: YYYY-MM-DD heure: HH:mm:ss - "
|
|
63
|
+
timestampPrefix: '',
|
|
64
|
+
timestampSuffix: ''
|
|
62
65
|
},
|
|
63
66
|
files: {
|
|
64
67
|
folder: 'logs',
|
|
@@ -91,7 +94,7 @@ log.settings({
|
|
|
91
94
|
Configures file logging and console output options.
|
|
92
95
|
**Console Options:**
|
|
93
96
|
- `enableTimestamp` (boolean): Enable/disable timestamp (default: `true`).
|
|
94
|
-
- `timestampFormat` (string): Format for the timestamp (default: `'YYYY-MM-DD HH:mm:ss'`).
|
|
97
|
+
- `timestampFormat` (string): Format for the timestamp including literal text if desired (default: `'YYYY-MM-DD HH:mm:ss'`).
|
|
95
98
|
- `timestampPrefix` (string): Prefix for the timestamp.
|
|
96
99
|
- `timestampSuffix` (string): Suffix for the timestamp.
|
|
97
100
|
|
package/main.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
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
|
|
|
5
6
|
/**
|
|
6
7
|
* @typedef {Object} ConsoleOptions
|
|
7
8
|
* @property {boolean} [enableTimestamp=true] - Enable or disable timestamp in console logs.
|
|
8
|
-
* @property {string} [timestampFormat='YYYY-MM-DD HH:mm:ss'] -
|
|
9
|
-
*
|
|
10
|
-
*
|
|
9
|
+
* @property {string} [timestampFormat='YYYY-MM-DD HH:mm:ss'] - Moment.js format for the timestamp.
|
|
10
|
+
* You can include literal text as needed. For example:
|
|
11
|
+
* - "Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - "
|
|
12
|
+
* - "date: YYYY-MM-DD heure: HH:mm:ss - "
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -25,16 +27,21 @@ require('winston-daily-rotate-file');
|
|
|
25
27
|
* @property {FilesOptions} [files] - Options for configuring file logging.
|
|
26
28
|
*/
|
|
27
29
|
|
|
28
|
-
// Custom format for logger
|
|
30
|
+
// Custom format for logger output
|
|
29
31
|
const customFormat = format.printf(({ timestamp, level, message }) => {
|
|
30
32
|
return timestamp ? `${timestamp} [${level}]: ${message}` : `[${level}]: ${message}`;
|
|
31
33
|
});
|
|
32
34
|
|
|
33
|
-
//
|
|
35
|
+
// Default console timestamp format
|
|
36
|
+
const defaultConsoleFormat = 'YYYY-MM-DD HH:mm:ss';
|
|
37
|
+
|
|
38
|
+
// Create a default console transport with timestamp enabled using Moment.js
|
|
34
39
|
let consoleTransport = new transports.Console({
|
|
35
40
|
format: format.combine(
|
|
36
41
|
format.colorize(),
|
|
37
|
-
format.timestamp({
|
|
42
|
+
format.timestamp({
|
|
43
|
+
format: () => moment().format(defaultConsoleFormat)
|
|
44
|
+
}),
|
|
38
45
|
customFormat
|
|
39
46
|
)
|
|
40
47
|
});
|
|
@@ -43,7 +50,9 @@ let consoleTransport = new transports.Console({
|
|
|
43
50
|
const logger = createLogger({
|
|
44
51
|
level: 'debug',
|
|
45
52
|
format: format.combine(
|
|
46
|
-
format.timestamp({
|
|
53
|
+
format.timestamp({
|
|
54
|
+
format: () => moment().format(defaultConsoleFormat)
|
|
55
|
+
}),
|
|
47
56
|
customFormat
|
|
48
57
|
),
|
|
49
58
|
transports: [consoleTransport]
|
|
@@ -54,16 +63,15 @@ let fileTransport;
|
|
|
54
63
|
|
|
55
64
|
/**
|
|
56
65
|
* Configures logging settings for both console and file transports.
|
|
57
|
-
*
|
|
58
|
-
* @param {LogSettingsOptions} options - The settings for console and file logging.
|
|
66
|
+
*
|
|
67
|
+
* @param {LogSettingsOptions} options - The settings for both console and file logging.
|
|
59
68
|
* @example
|
|
60
|
-
* //
|
|
69
|
+
* // Example: Fully custom console timestamp using a custom format string,
|
|
70
|
+
* // and enabling file logging.
|
|
61
71
|
* log.settings({
|
|
62
72
|
* console: {
|
|
63
73
|
* enableTimestamp: true,
|
|
64
|
-
* timestampFormat: 'YYYY-MM-DD HH:mm:ss
|
|
65
|
-
* timestampPrefix: '[START] ',
|
|
66
|
-
* timestampSuffix: ' [END]'
|
|
74
|
+
* timestampFormat: "Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - "
|
|
67
75
|
* },
|
|
68
76
|
* files: {
|
|
69
77
|
* folder: 'logs',
|
|
@@ -78,26 +86,20 @@ function applySettings(options = {}) {
|
|
|
78
86
|
// Update console transport if configuration is provided
|
|
79
87
|
if (options.console) {
|
|
80
88
|
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 || '';
|
|
89
|
+
const timestampFormat = options.console.timestampFormat || defaultConsoleFormat;
|
|
84
90
|
|
|
85
91
|
// Remove the current console transport
|
|
86
92
|
logger.remove(consoleTransport);
|
|
87
93
|
|
|
88
|
-
// Create new console transport based on the provided options
|
|
94
|
+
// Create new console transport based on the provided options.
|
|
95
|
+
// The provided timestampFormat is passed directly to moment().
|
|
89
96
|
consoleTransport = new transports.Console({
|
|
90
97
|
format: enableTimestamp
|
|
91
98
|
? format.combine(
|
|
92
99
|
format.colorize(),
|
|
93
|
-
format.timestamp({
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (info.timestamp) {
|
|
97
|
-
info.timestamp = timestampPrefix + info.timestamp + timestampSuffix;
|
|
98
|
-
}
|
|
99
|
-
return info;
|
|
100
|
-
})(),
|
|
100
|
+
format.timestamp({
|
|
101
|
+
format: () => moment().format(timestampFormat)
|
|
102
|
+
}),
|
|
101
103
|
customFormat
|
|
102
104
|
)
|
|
103
105
|
: format.combine(
|
|
@@ -126,7 +128,7 @@ function applySettings(options = {}) {
|
|
|
126
128
|
logger.remove(fileTransport);
|
|
127
129
|
}
|
|
128
130
|
|
|
129
|
-
// Create a new daily
|
|
131
|
+
// Create a new daily-rotate file transport with provided/default settings
|
|
130
132
|
fileTransport = new transports.DailyRotateFile({
|
|
131
133
|
filename: `${folder}/application-%DATE%.log`,
|
|
132
134
|
datePattern,
|
|
@@ -141,8 +143,8 @@ function applySettings(options = {}) {
|
|
|
141
143
|
|
|
142
144
|
/**
|
|
143
145
|
* Logs a general message using the info level.
|
|
144
|
-
*
|
|
145
|
-
* @param {string} message -
|
|
146
|
+
*
|
|
147
|
+
* @param {string} message - The message to be logged.
|
|
146
148
|
*/
|
|
147
149
|
function log(message) {
|
|
148
150
|
logger.info(message);
|
|
@@ -150,7 +152,7 @@ function log(message) {
|
|
|
150
152
|
|
|
151
153
|
/**
|
|
152
154
|
* Logs an error message.
|
|
153
|
-
* @param {string} message -
|
|
155
|
+
* @param {string} message - The error message.
|
|
154
156
|
*/
|
|
155
157
|
log.error = function (message) {
|
|
156
158
|
logger.error(message);
|
|
@@ -158,7 +160,7 @@ log.error = function (message) {
|
|
|
158
160
|
|
|
159
161
|
/**
|
|
160
162
|
* Logs a warning message.
|
|
161
|
-
* @param {string} message -
|
|
163
|
+
* @param {string} message - The warning message.
|
|
162
164
|
*/
|
|
163
165
|
log.warn = function (message) {
|
|
164
166
|
logger.warn(message);
|
|
@@ -166,7 +168,7 @@ log.warn = function (message) {
|
|
|
166
168
|
|
|
167
169
|
/**
|
|
168
170
|
* Logs an informational message.
|
|
169
|
-
* @param {string} message -
|
|
171
|
+
* @param {string} message - The informational message.
|
|
170
172
|
*/
|
|
171
173
|
log.info = function (message) {
|
|
172
174
|
logger.info(message);
|
|
@@ -174,13 +176,13 @@ log.info = function (message) {
|
|
|
174
176
|
|
|
175
177
|
/**
|
|
176
178
|
* Logs a debug message.
|
|
177
|
-
* @param {string} message -
|
|
179
|
+
* @param {string} message - The debug message.
|
|
178
180
|
*/
|
|
179
181
|
log.debug = function (message) {
|
|
180
182
|
logger.debug(message);
|
|
181
183
|
};
|
|
182
184
|
|
|
183
|
-
// Expose the settings function for configuring file logging and console output
|
|
185
|
+
// Expose the settings function for configuring both file logging and console output
|
|
184
186
|
log.settings = applySettings;
|
|
185
187
|
|
|
186
188
|
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.1",
|
|
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
|
}
|