logxpert 0.2.0 → 0.3.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 lighscent
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,14 @@
1
+ # Notes de Version
2
+
3
+ ## v0.3.0
4
+
5
+ - Ajout du support de l'enregistrement dans des fichiers via [winston](https://github.com/winstonjs/winston) et [winston-daily-rotate-file](https://github.com/winstonjs/winston-daily-rotate-file).
6
+ - Introduction de la méthode `log.settings()` pour configurer l'enregistrement dans les fichiers.
7
+ - Mise à jour des options de configuration pour utiliser `filesName` à la place de l'ancienne propriété.
8
+ - Réglages par défaut :
9
+ - Dossier : `logs`
10
+ - Motif de date (`filesName`) : `YYYY-MM-DD_HH:mm:ss`
11
+ - Rétention maximale des fichiers : `14d`
12
+ - Taille maximale par fichier : `20m`
13
+ - `zippedArchive` : par défaut `false` à moins qu'une autre valeur soit fournie.
14
+ - La journalisation dans la console conserve une sortie colorée et formatée.
package/PATCHNOTE.md ADDED
@@ -0,0 +1,14 @@
1
+ # Patch Notes
2
+
3
+ ## v0.3.0
4
+
5
+ - Added file logging support using winston and winston-daily-rotate-file.
6
+ - Introduced `log.settings()` to configure file logging.
7
+ - Updated configuration options to use `filesName` instead of the previous property name.
8
+ - Default settings:
9
+ - Folder: `logs`
10
+ - Date pattern (`filesName`): `YYYY-MM-DD_HH:mm:ss`
11
+ - Maximum file retention: `14d`
12
+ - Maximum file size: `20m`
13
+ - `zippedArchive`: default is `false` unless provided.
14
+ - Console logging remains with colorful formatted output.
package/README.fr.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # LogXpert
2
2
 
3
- LogXpert est une bibliothèque de log puissante pour Node.js qui offre des méthodes de log simples à utiliser avec un affichage coloré et formaté.
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. Cette documentation explique l'installation et l'utilisation du module.
4
+
5
+ ## Table des Matières
6
+ - [Installation](#installation)
7
+ - [Utilisation](#utilisation)
8
+ - [Journalisation de base](#journalisation-de-base)
9
+ - [Journalisation avancée : Fichiers de logs](#journalisation-avancee-fichiers-de-logs)
10
+ - [Référence API](#référence-api)
11
+ - [Informations Supplémentaires](#informations-supplémentaires)
12
+ - [Licence](#licence)
4
13
 
5
14
  ## Installation
6
15
 
@@ -12,31 +21,79 @@ npm install logxpert
12
21
 
13
22
  ## Utilisation
14
23
 
15
- Importez LogXpert dans votre projet :
24
+ ### Journalisation de base
25
+
26
+ Importez LogXpert dans votre projet et utilisez-le pour enregistrer des messages :
16
27
 
17
28
  ```js
18
29
  const log = require('logxpert');
19
30
 
20
- // Log global
31
+ // Journalisation d'un message général
21
32
  log('Ceci est un message de log général.');
22
33
 
23
- // Log d'erreur
34
+ // Journalisation d'un message d'erreur
24
35
  log.error("Ceci est un message d'erreur.");
25
36
 
26
- // Log d'avertissement
37
+ // Journalisation d'un message d'avertissement
27
38
  log.warn("Ceci est un message d'avertissement.");
28
39
 
29
- // Log d'info
40
+ // Journalisation d'un message d'information
30
41
  log.info("Ceci est un message d'information.");
31
42
 
32
- // Log de debug
43
+ // Journalisation d'un message de debug
33
44
  log.debug("Ceci est un message de debug.");
34
45
  ```
35
46
 
36
- ## Structure du Projet
47
+ ### Journalisation avancée : Fichiers de logs
48
+
49
+ LogXpert supporte l'enregistrement des logs dans des fichiers à l'aide de [winston](https://github.com/winstonjs/winston) et [winston-daily-rotate-file](https://github.com/winstonjs/winston-daily-rotate-file). Pour activer l'enregistrement dans un fichier, configurez les paramètres via la méthode `log.settings()`. Si non configuré, seule la journalisation dans la console est active.
50
+
51
+ Exemple de configuration pour activer l'enregistrement dans un fichier :
52
+
53
+ ```js
54
+ const log = require('logxpert');
55
+
56
+ log.settings({
57
+ files: {
58
+ folder: 'logs',
59
+ filesName: 'YYYY-MM-DD_HH:mm:ss',
60
+ maxFile: '14d',
61
+ maxSize: '20m',
62
+ zippedArchive: true
63
+ }
64
+ });
65
+ ```
66
+
67
+ ## Référence API
68
+
69
+ - **log(message: string):**
70
+ Enregistre un message général avec le niveau `info`.
71
+
72
+ - **log.error(message: string):**
73
+ Enregistre un message d'erreur.
74
+
75
+ - **log.warn(message: string):**
76
+ Enregistre un message d'avertissement.
77
+
78
+ - **log.info(message: string):**
79
+ Enregistre un message d'information.
80
+
81
+ - **log.debug(message: string):**
82
+ Enregistre un message de debug.
83
+
84
+ - **log.settings(options: Object):**
85
+ Configure les options d'enregistrement des logs dans un fichier. L'objet doit contenir la propriété `files` avec les options suivantes :
86
+
87
+ - `folder` (string) : Répertoire où les fichiers de logs seront stockés (par défaut : `'logs'`).
88
+ - `filesName` (string) : Motif de date utilisé dans le nom des fichiers de log (par défaut : `'YYYY-MM-DD_HH:mm:ss'`).
89
+ - `maxFile` (string) : Durée de rétention maximale des fichiers (par défaut : `'14d'`).
90
+ - `maxSize` (string) : Taille maximale par fichier de log (par défaut : `'20m'`).
91
+ - `zippedArchive` (boolean) : Archive les logs au format zip (par défaut : `false`).
92
+
93
+ ## Informations Supplémentaires
37
94
 
38
- - [main.js](c:\Users\x\Desktop\powerlogs\main.js) - Point d'entrée avec la fonctionnalité de log.
39
- - [package.json](c:\Users\x\Desktop\powerlogs\package.json) - Configuration du package.
95
+ - [Version Anglaise](./README.md)
96
+ - [Notes de Version](./PATCHNOTE.fr.md)
40
97
 
41
98
  ## Licence
42
99
 
package/README.md CHANGED
@@ -1,6 +1,101 @@
1
1
  # LogXpert
2
2
 
3
- Please choose your language:
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. This documentation explains the installation and usage of the module.
4
4
 
5
- - [English Version](./README.en.md)
6
- - [Version Française](./README.fr.md)
5
+ ## Table of Contents
6
+ - [Installation](#installation)
7
+ - [Usage](#usage)
8
+ - [Basic Logging](#basic-logging)
9
+ - [Advanced Logging: File Output](#advanced-logging-file-output)
10
+ - [API Reference](#api-reference)
11
+ - [Additional Information](#additional-information)
12
+ - [License](#license)
13
+
14
+ ## Installation
15
+
16
+ You can install LogXpert using npm:
17
+
18
+ ```sh
19
+ npm install logxpert
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ### Basic Logging
25
+
26
+ Import LogXpert in your project and use it to log messages:
27
+
28
+ ```js
29
+ const log = require('logxpert');
30
+
31
+ // Log a general message
32
+ log('This is a general log message.');
33
+
34
+ // Log an error message
35
+ log.error('This is an error message.');
36
+
37
+ // Log a warning message
38
+ log.warn('This is a warning message.');
39
+
40
+ // Log an informational message
41
+ log.info('This is an informational message.');
42
+
43
+ // Log a debug message
44
+ log.debug('This is a debug message.');
45
+ ```
46
+
47
+ ### Advanced Logging: File Output
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). To enable file logging, you can configure it with custom settings via the `log.settings()` method. If not configured, only console logging is active.
50
+
51
+ Example configuration to enable file logging:
52
+
53
+ ```js
54
+ const log = require('logxpert');
55
+
56
+ log.settings({
57
+ files: {
58
+ folder: 'logs',
59
+ filesName: 'YYYY-MM-DD_HH:mm:ss',
60
+ maxFile: '14d',
61
+ maxSize: '20m',
62
+ zippedArchive: true
63
+ }
64
+ });
65
+ ```
66
+
67
+ ### API Reference
68
+
69
+ - **log(message: string):**
70
+ Logs a general message using the `info` level.
71
+
72
+ - **log.error(message: string):**
73
+ Logs an error message.
74
+
75
+ - **log.warn(message: string):**
76
+ Logs a warning message.
77
+
78
+ - **log.info(message: string):**
79
+ Logs an informational message.
80
+
81
+ - **log.debug(message: string):**
82
+ Logs a debug message.
83
+
84
+ - **log.settings(options: Object):**
85
+ Configures the file logging options. Accepts an object with a `files` property.
86
+ **Options**:
87
+
88
+ - `folder` (string): Directory where log files will be stored (default: `'logs'`).
89
+ - `filesName` (string): Date pattern used in the log file name (default: `'YYYY-MM-DD_HH:mm:ss'`).
90
+ - `maxFile` (string): Maximum file retention (default: `'14d'`).
91
+ - `maxSize` (string): Maximum size per log file (default: `'20m'`).
92
+ - `zippedArchive` (boolean): Whether to archive the logs in zipped format (default: `false`).
93
+
94
+ ## Additional Information
95
+
96
+ - [French Version](./README.fr.md)
97
+ - [Patch Notes](./PATCHNOTE.md)
98
+
99
+ ## License
100
+
101
+ This project is licensed under the MIT License.
package/main.js CHANGED
@@ -1,34 +1,84 @@
1
- const colors = {
2
- reset: "\x1b[0m",
3
- red: "\x1b[31m",
4
- yellow: "\x1b[33m",
5
- cyan: "\x1b[36m",
6
- magenta: "\x1b[35m",
7
- white: "\x1b[37m"
8
- };
1
+ const { createLogger, format, transports } = require('winston');
2
+ require('winston-daily-rotate-file');
3
+
4
+ // Custom format for logger
5
+ const customFormat = format.printf(({ timestamp, level, message }) => {
6
+ return `${timestamp} [${level}]: ${message}`;
7
+ });
8
+
9
+ // Create a logger with console transport only
10
+ const logger = createLogger({
11
+ level: 'debug',
12
+ format: format.combine(
13
+ format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
14
+ customFormat
15
+ ),
16
+ transports: [
17
+ new transports.Console({
18
+ format: format.combine(
19
+ format.colorize(),
20
+ format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
21
+ customFormat
22
+ )
23
+ })
24
+ ]
25
+ });
26
+
27
+ // Reference to file transport (added via settings)
28
+ let fileTransport;
9
29
 
10
- function colorText(text, color) {
11
- return `${color}${text}${colors.reset}`;
30
+ // Settings function to enable file logging
31
+ // Example usage:
32
+ // log.settings({ files: { folder: 'logs', filesName: 'YYYY-MM-DD_HH:mm:ss', maxFile: '14d', maxSize: '20m', zippedArchive: true }})
33
+ function applySettings(options = {}) {
34
+ if (options.files) {
35
+ // Set defaults if not provided
36
+ const folder = options.files.folder || 'logs';
37
+ const datePattern = options.files.filesName || 'YYYY-MM-DD_HH:mm:ss';
38
+ const maxFiles = options.files.maxFile || '14d';
39
+ const maxSize = options.files.maxSize || '20m';
40
+ const zippedArchive = options.files.zippedArchive !== undefined ? options.files.zippedArchive : false;
41
+
42
+ // Remove existing file transport if it exists
43
+ if (fileTransport) {
44
+ logger.remove(fileTransport);
45
+ }
46
+
47
+ // Create a new daily rotate file transport with provided/default settings
48
+ fileTransport = new transports.DailyRotateFile({
49
+ filename: `${folder}/application-%DATE%.log`,
50
+ datePattern,
51
+ zippedArchive,
52
+ maxSize,
53
+ maxFiles
54
+ });
55
+
56
+ logger.add(fileTransport);
57
+ }
12
58
  }
13
59
 
60
+ // Create a simplified logging interface
14
61
  function log(message) {
15
- console.log(colorText(message, colors.white));
62
+ logger.info(message);
16
63
  }
17
64
 
18
65
  log.error = function (message) {
19
- console.error(colorText(`Error: ${message}`, colors.red));
66
+ logger.error(message);
20
67
  };
21
68
 
22
69
  log.warn = function (message) {
23
- console.warn(colorText(`Warn: ${message}`, colors.yellow));
70
+ logger.warn(message);
24
71
  };
25
72
 
26
73
  log.info = function (message) {
27
- console.info(colorText(`Info: ${message}`, colors.cyan));
74
+ logger.info(message);
28
75
  };
29
76
 
30
77
  log.debug = function (message) {
31
- console.debug(colorText(`Debug: ${message}`, colors.magenta));
78
+ logger.debug(message);
32
79
  };
33
80
 
81
+ // Expose the settings function for configuring file logging
82
+ log.settings = applySettings;
83
+
34
84
  module.exports = log;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logxpert",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "A powerful logging library for Node.js",
5
5
  "main": "main.js",
6
6
  "repository": {
@@ -8,5 +8,9 @@
8
8
  "url": "git+https://github.com/lighscent/LogXpert.git"
9
9
  },
10
10
  "author": "https://github.com/lighscent",
11
- "license": "MIT"
12
- }
11
+ "license": "MIT",
12
+ "dependencies": {
13
+ "winston": "^3.17.0",
14
+ "winston-daily-rotate-file": "^5.0.0"
15
+ }
16
+ }
package/README.en.md DELETED
@@ -1,43 +0,0 @@
1
- # LogXpert
2
-
3
- LogXpert is a powerful logging library for Node.js that provides easy-to-use logging methods with colorful formatted output.
4
-
5
- ## Installation
6
-
7
- Install LogXpert using npm:
8
-
9
- ```sh
10
- npm install logxpert
11
- ```
12
-
13
- ## Usage
14
-
15
- Import LogXpert in your project:
16
-
17
- ```js
18
- const log = require('logxpert');
19
-
20
- // Global log
21
- log('This is a general log message.');
22
-
23
- // Error log
24
- log.error('This is an error message.');
25
-
26
- // Warning log
27
- log.warn('This is a warning message.');
28
-
29
- // Info log
30
- log.info('This is an informational message.');
31
-
32
- // Debug log
33
- log.debug('This is a debug message.');
34
- ```
35
-
36
- ## Project Structure
37
-
38
- - [main.js](c:\Users\x\Desktop\powerlogs\main.js) - Entry point with the logging functionality.
39
- - [package.json](c:\Users\x\Desktop\powerlogs\package.json) - Package configuration.
40
-
41
- ## License
42
-
43
- This project is licensed under the MIT License.