logxpert 0.2.0 → 0.3.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.
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ augustin.pro.prs@gmail.com.
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
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,18 @@
1
+ # Notes de Version
2
+
3
+ ## v0.3.1
4
+
5
+ - Ajout de la création automatique du dossier de logs s'il n'existe pas afin d'éviter l'erreur `ENOENT`.
6
+
7
+ ## v0.3.0
8
+
9
+ - 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).
10
+ - Introduction de la méthode `log.settings()` pour configurer l'enregistrement dans les fichiers.
11
+ - Mise à jour des options de configuration pour utiliser `filesName` à la place de l'ancienne propriété.
12
+ - Réglages par défaut :
13
+ - Dossier : `logs`
14
+ - Motif de date (`filesName`) : `YYYY-MM-DD_HH:mm:ss`
15
+ - Rétention maximale des fichiers : `14d`
16
+ - Taille maximale par fichier : `20m`
17
+ - `zippedArchive` : par défaut `false` à moins qu'une autre valeur soit fournie.
18
+ - La journalisation dans la console conserve une sortie colorée et formatée.
package/PATCHNOTE.md ADDED
@@ -0,0 +1,18 @@
1
+ # Patch Notes
2
+
3
+ ## v0.3.1
4
+
5
+ - Ensure the log folder is created if it does not exist to prevent `ENOENT` errors.
6
+
7
+ ## v0.3.0
8
+
9
+ - Added file logging support using winston and winston-daily-rotate-file.
10
+ - Introduced `log.settings()` to configure file logging.
11
+ - Updated configuration options to use `filesName` instead of the previous property name.
12
+ - Default settings:
13
+ - Folder: `logs`
14
+ - Date pattern (`filesName`): `YYYY-MM-DD_HH:mm:ss`
15
+ - Maximum file retention: `14d`
16
+ - Maximum file size: `20m`
17
+ - `zippedArchive`: default is `false` unless provided.
18
+ - 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,90 @@
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 fs = require('fs');
2
+ const { createLogger, format, transports } = require('winston');
3
+ require('winston-daily-rotate-file');
4
+
5
+ // Custom format for logger
6
+ const customFormat = format.printf(({ timestamp, level, message }) => {
7
+ return `${timestamp} [${level}]: ${message}`;
8
+ });
9
+
10
+ // Create a logger with console transport only
11
+ const logger = createLogger({
12
+ level: 'debug',
13
+ format: format.combine(
14
+ format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
15
+ customFormat
16
+ ),
17
+ transports: [
18
+ new transports.Console({
19
+ format: format.combine(
20
+ format.colorize(),
21
+ format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
22
+ customFormat
23
+ )
24
+ })
25
+ ]
26
+ });
27
+
28
+ // Reference to file transport (added via settings)
29
+ let fileTransport;
30
+
31
+ // Settings function to enable file logging
32
+ // Example usage:
33
+ // log.settings({ files: { folder: 'logs', filesName: 'YYYY-MM-DD_HH:mm:ss', maxFile: '14d', maxSize: '20m', zippedArchive: false }})
34
+ function applySettings(options = {}) {
35
+ if (options.files) {
36
+ // Set defaults if not provided
37
+ const folder = options.files.folder || 'logs';
38
+ const datePattern = options.files.filesName || 'YYYY-MM-DD_HH:mm:ss';
39
+ const maxFiles = options.files.maxFile || '14d';
40
+ const maxSize = options.files.maxSize || '20m';
41
+ const zippedArchive = options.files.zippedArchive !== undefined ? options.files.zippedArchive : false;
9
42
 
10
- function colorText(text, color) {
11
- return `${color}${text}${colors.reset}`;
43
+ // Ensure the log folder exists
44
+ if (!fs.existsSync(folder)) {
45
+ fs.mkdirSync(folder, { recursive: true });
46
+ }
47
+
48
+ // Remove existing file transport if it exists
49
+ if (fileTransport) {
50
+ logger.remove(fileTransport);
51
+ }
52
+
53
+ // Create a new daily rotate file transport with provided/default settings
54
+ fileTransport = new transports.DailyRotateFile({
55
+ filename: `${folder}/application-%DATE%.log`,
56
+ datePattern,
57
+ zippedArchive,
58
+ maxSize,
59
+ maxFiles
60
+ });
61
+
62
+ logger.add(fileTransport);
63
+ }
12
64
  }
13
65
 
66
+ // Create a simplified logging interface
14
67
  function log(message) {
15
- console.log(colorText(message, colors.white));
68
+ logger.info(message);
16
69
  }
17
70
 
18
71
  log.error = function (message) {
19
- console.error(colorText(`Error: ${message}`, colors.red));
72
+ logger.error(message);
20
73
  };
21
74
 
22
75
  log.warn = function (message) {
23
- console.warn(colorText(`Warn: ${message}`, colors.yellow));
76
+ logger.warn(message);
24
77
  };
25
78
 
26
79
  log.info = function (message) {
27
- console.info(colorText(`Info: ${message}`, colors.cyan));
80
+ logger.info(message);
28
81
  };
29
82
 
30
83
  log.debug = function (message) {
31
- console.debug(colorText(`Debug: ${message}`, colors.magenta));
84
+ logger.debug(message);
32
85
  };
33
86
 
87
+ // Expose the settings function for configuring file logging
88
+ log.settings = applySettings;
89
+
34
90
  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.1",
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"
11
+ "license": "MIT",
12
+ "dependencies": {
13
+ "winston": "^3.17.0",
14
+ "winston-daily-rotate-file": "^5.0.0"
15
+ }
12
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.