logxpert 1.0.1 → 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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Notes de Version
2
2
 
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
+
3
9
  ## v1.0.1
4
10
 
5
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,8 +18,6 @@
12
18
  - **Documentation:** Mise à jour du README et de la référence API pour plus de clarté et de complétude.
13
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.
14
20
 
15
- ## Versions Précédentes
16
-
17
21
  ### v0.3.2
18
22
  - Modification du motif par défaut de `filesName` passant de `'YYYY-MM-DD_HH:mm:ss'` à `'YYYY-MM-DD'`.
19
23
 
package/PATCHNOTE.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Patch Notes
2
2
 
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
+
3
9
  ## v1.0.1
4
10
 
5
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,8 +18,6 @@
12
18
  - **Documentation:** Updated README and API references for clarity and completeness.
13
19
  - **Backward Compatibility:** Retained all features from previous versions, including methods for general, error, warning, info, and debug logging.
14
20
 
15
- ## Previous Versions
16
-
17
21
  ### v0.3.2
18
22
  - Changed the default `filesName` pattern from `'YYYY-MM-DD_HH:mm:ss'` to `'YYYY-MM-DD'`.
19
23
 
package/README.fr.md CHANGED
@@ -1,6 +1,6 @@
1
- # LogXpert v1.0.1 LTS
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. Dans cette version LTS v1.0.1, nous avons amélioré la personnalisation de l'horodatage en console et apporté plusieurs améliorations.
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). Vous pouvez configurer l'enregistrement dans un fichier ainsi que personnaliser pleinement 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).
50
50
 
51
51
  Exemple de configuration :
52
52
 
@@ -56,10 +56,8 @@ const log = require('logxpert');
56
56
  log.settings({
57
57
  console: {
58
58
  enableTimestamp: true,
59
- // Exemple 1 : Inclure du texte littéral avec des tokens
59
+ // Vous pouvez inclure des caractères de décoration, par exemple :
60
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
61
  timestampPrefix: '',
64
62
  timestampSuffix: ''
65
63
  },
@@ -94,12 +92,12 @@ log.settings({
94
92
  Configure les options d'enregistrement dans un fichier et de personnalisation de la sortie console.
95
93
  **Options Console :**
96
94
  - `enableTimestamp` (boolean) : Active/désactive l'horodatage (par défaut : `true`).
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
+ - `timestampFormat` (string) : Format de l'horodatage incluant tout texte littéral ou décoration (par défaut : `'YYYY-MM-DD HH:mm:ss'`).
98
96
  - `timestampPrefix` (string) : Préfixe de l'horodatage.
99
97
  - `timestampSuffix` (string) : Suffixe de l'horodatage.
100
98
 
101
99
  **Options Fichiers :**
102
- - `folder` (string) : Répertoire où les fichiers de logs seront stockés (par défaut : `'logs'`).
100
+ - `folder` (string) : Répertoire où seront stockés les fichiers de logs (par défaut : `'logs'`).
103
101
  - `filesName` (string) : Motif de date pour le nom des fichiers de logs (par défaut : `'YYYY-MM-DD'`).
104
102
  - `maxFile` (string) : Durée maximale de rétention des fichiers (par défaut : `'14d'`).
105
103
  - `maxSize` (string) : Taille maximale par fichier de log (par défaut : `'20m'`).
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # LogXpert v1.0.1 LTS
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. In this LTS release, v1.0.1, we have enhanced custom console timestamp formatting and made several improvements.
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,7 +46,7 @@ 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 fully 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).
50
50
 
51
51
  Example configuration:
52
52
 
@@ -56,10 +56,8 @@ const log = require('logxpert');
56
56
  log.settings({
57
57
  console: {
58
58
  enableTimestamp: true,
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 - "
59
+ // You can now include decoration characters as desired:
60
+ timestampFormat: "This is the date: [YYYY-MM-DD HH:mm:ss] - ",
63
61
  timestampPrefix: '',
64
62
  timestampSuffix: ''
65
63
  },
@@ -94,7 +92,7 @@ log.settings({
94
92
  Configures file logging and console output options.
95
93
  **Console Options:**
96
94
  - `enableTimestamp` (boolean): Enable/disable timestamp (default: `true`).
97
- - `timestampFormat` (string): Format for the timestamp including literal text if desired (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'`).
98
96
  - `timestampPrefix` (string): Prefix for the timestamp.
99
97
  - `timestampSuffix` (string): Suffix for the timestamp.
100
98
 
package/main.js CHANGED
@@ -3,11 +3,33 @@ const moment = require('moment'); // Add moment as a dependency: npm install mom
3
3
  const { createLogger, format, transports } = require('winston');
4
4
  require('winston-daily-rotate-file');
5
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
+
6
27
  /**
7
28
  * @typedef {Object} ConsoleOptions
8
29
  * @property {boolean} [enableTimestamp=true] - Enable or disable timestamp in console logs.
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:
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:
11
33
  * - "Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - "
12
34
  * - "date: YYYY-MM-DD heure: HH:mm:ss - "
13
35
  */
@@ -35,7 +57,7 @@ const customFormat = format.printf(({ timestamp, level, message }) => {
35
57
  // Default console timestamp format
36
58
  const defaultConsoleFormat = 'YYYY-MM-DD HH:mm:ss';
37
59
 
38
- // Create a default console transport with timestamp enabled using Moment.js
60
+ // Create a default console transport with timestamp enabled using the default format
39
61
  let consoleTransport = new transports.Console({
40
62
  format: format.combine(
41
63
  format.colorize(),
@@ -66,11 +88,12 @@ let fileTransport;
66
88
  *
67
89
  * @param {LogSettingsOptions} options - The settings for both console and file logging.
68
90
  * @example
69
- * // Example: Fully custom console timestamp using a custom format string,
91
+ * // Example: Fully custom console timestamp that preserves decoration,
70
92
  * // and enabling file logging.
71
93
  * log.settings({
72
94
  * console: {
73
95
  * enableTimestamp: true,
96
+ * // You can now include brackets or parentheses as decoration:
74
97
  * timestampFormat: "Voici la date et l'heure: [YYYY-MM-DD HH:mm:ss] - "
75
98
  * },
76
99
  * files: {
@@ -92,13 +115,13 @@ function applySettings(options = {}) {
92
115
  logger.remove(consoleTransport);
93
116
 
94
117
  // Create new console transport based on the provided options.
95
- // The provided timestampFormat is passed directly to moment().
118
+ // Here, we use our helper function to let tokens be replaced while preserving any decoration.
96
119
  consoleTransport = new transports.Console({
97
120
  format: enableTimestamp
98
121
  ? format.combine(
99
122
  format.colorize(),
100
123
  format.timestamp({
101
- format: () => moment().format(timestampFormat)
124
+ format: () => formatCustomTimestamp(timestampFormat)
102
125
  }),
103
126
  customFormat
104
127
  )
@@ -136,7 +159,6 @@ function applySettings(options = {}) {
136
159
  maxSize,
137
160
  maxFiles
138
161
  });
139
-
140
162
  logger.add(fileTransport);
141
163
  }
142
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logxpert",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "A powerful logging library for Node.js",
5
5
  "main": "main.js",
6
6
  "repository": {