chromalogger 1.1.1 → 1.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Votre Nom
3
+ Copyright (c) 2025 Orssi Mp
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,254 +1,31 @@
1
- # ChromaLogger
2
-
3
- [![npm version](https://img.shields.io/npm/v/chromalogger.svg?style=flat)](https://www.npmjs.com/package/chromalogger)
4
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
- [![GitHub stars](https://img.shields.io/github/stars/OrssiMp/chromalogger.svg?style=social)](https://github.com/OrssiMp/chromalogger/stargazers)
6
-
7
- ChromaLogger est une bibliothèque Node.js puissante et flexible pour la journalisation de console avec un support avancé des couleurs et des styles. Parfaite pour le développement et le débogage d'applications Node.js.
8
-
9
- ## ✨ Fonctionnalités
10
-
11
- - 🎨 Messages de console colorés et stylisés
12
- - 📊 Plusieurs niveaux de logs (log, debug, info, warn, error)
13
- - 🛠️ Interface de ligne de commande (CLI) intégrée
14
- - 🔧 Personnalisation facile des styles et formats
15
- - 📦 Compatible ES Modules et CommonJS
16
- - 🚀 Légère et sans dépendances inutiles
17
-
18
- ## 📦 Installation
19
-
20
- ```bash
21
- # Avec npm
22
- npm install chromalogger
23
-
24
- # Ou avec Yarn
25
- yarn add chromalogger
26
- ```
27
-
28
- ## 🎨 Utilisation de la fonction `chroma`
29
-
30
- La fonction `chroma` vous permet de créer des messages colorés avec une grande flexibilité :
31
-
32
- ```javascript
33
- import { chroma } from 'chromalogger';
34
-
35
- // Utilisation de base
36
- console.log(chroma('Texte en rouge', 'red'));
37
- console.log(chroma('Texte en vert sur fond jaune', 'green', 'bgYellow'));
38
-
39
- // Chaînage des styles
40
- console.log(chroma('Texte en gras et souligné', 'bold', 'underline'));
41
-
42
- // Avec des templates strings
43
- const user = 'Alice';
44
- console.log(chroma`Bonjour ${user}, ceci est un ${'message important'.red.bold} !`);
45
-
46
- // Styles disponibles :
47
- // Couleurs : black, red, green, yellow, blue, magenta, cyan, white
48
- // Arrière-plans : bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite
49
- // Styles : bright, dim, italic, underline, blink, reverse, hidden, strikethrough
50
- ```
51
-
52
- ## 🚀 Utilisation de base
53
-
54
- ### Avec ES Modules (recommandé)
55
-
56
- ```javascript
57
- import { log, info, warn, error, createLogger } from 'chromalogger';
58
-
59
- // Utilisation des loggers prédéfinis
60
- log('Message standard');
61
- info('Information importante');
62
- warn('Attention !');
63
- error('Erreur critique !');
64
-
65
- // Création d'un logger personnalisé
66
- const customLogger = createLogger('magenta', 'underline');
67
- customLogger('Message personnalisé');
68
- ```
69
-
70
- ### Avec CommonJS
71
-
72
- ```javascript
73
- const { log, info, warn, error } = require('chromalogger');
74
-
75
- // Utilisation des loggers
76
- log('Message standard');
77
- info('Information');
78
- warn('Avertissement');
79
- error('Erreur');
80
- ```
81
-
82
- ## 🛠️ Interface en Ligne de Commande (CLI)
83
-
84
- ChromaLogger inclut un utilitaire en ligne de commande `clog` :
85
-
86
- ```bash
87
- # Afficher l'aide
88
- npx clog --help ou clog --help
89
-
90
- # Afficher un message simple
91
- npx clog "Mon message" ou clog "Mon message"
92
-
93
- # Utiliser des couleurs et styles
94
- npx clog --color red --style bright "Message d'erreur important" / clog --color red --style bright "Message d'erreur important"
95
-
96
- clog --color red --style bright "Message d'erreur important" / clog --color red --style bright "Message d'erreur important"
97
- ```
98
-
99
- ## 📚 Documentation Complète
100
-
101
- Pour plus d'informations sur les fonctionnalités avancées, consultez la [documentation complète](https://github.com/OrssiMp/chromalogger#readme).
102
-
103
- ## 🤝 Contribuer
104
-
105
- Les contributions sont les bienvenues ! Voici comment contribuer :
106
-
107
- 1. Forkez le projet
108
- 2. Créez une branche pour votre fonctionnalité (`git checkout -b feature/AmazingFeature`)
109
- 3. Committez vos changements (`git commit -m 'Add some AmazingFeature'`)
110
- 4. Poussez vers la branche (`git push origin feature/AmazingFeature`)
111
- 5. Ouvrez une Pull Request
112
-
113
- ## 📄 Licence
114
-
115
- Distribué sous licence MIT. Voir le fichier `LICENSE` pour plus d'informations.
116
-
117
- ## 📞 Contact
118
-
119
- Orssi Mp - [@OrssiMp](https://github.com/OrssiMp) - orssimpiere5@gmail.com
120
-
121
- Lien du projet : [https://github.com/OrssiMp/chromalogger](https://github.com/OrssiMp/chromalogger)
122
-
123
- // Couleurs de base
124
- logger.red('Ceci est en rouge');
125
- logger.green('Ceci est en vert');
126
- logger.blue('Ceci est en bleu');
127
- logger.yellow('Ceci est en jaune');
128
-
129
- ````
130
-
131
- ### Avec CommonJS
132
-
133
- ```javascript
134
- const logger = require('logcolor-js');
135
-
136
- // Arrière-plans colorés
137
- logger.bgRed(' Fond rouge ');
138
- logger.bgGreen(' Fond vert ');
139
- logger.bgBlue(' Fond bleu ');
140
- ````
141
-
142
- ## Fonctionnalités
143
-
144
- ### Couleurs de texte
145
-
146
- - `red(text)` - Texte rouge
147
- - `green(text)` - Texte vert
148
- - `blue(text)` - Texte bleu
149
- - `yellow(text)` - Texte jaune
150
- - `white(text)` - Texte blanc
151
- - `black(text)` - Texte noir
152
- - `magenta(text)` - Texte magenta
153
- - `cyan(text)` - Texte cyan
154
-
155
- ### Arrière-plans
156
-
157
- - `bgRed(text)` - Fond rouge
158
- - `bgGreen(text)` - Fond vert
159
- - `bgBlue(text)` - Fond bleu
160
- - `bgYellow(text)` - Fond jaune
161
- - `bgWhite(text)` - Fond blanc
162
- - `bgBlack(text)` - Fond noir
163
- - `bgMagenta(text)` - Fond magenta
164
- - `bgCyan(text)` - Fond cyan
165
-
166
- ### Styles de texte
167
-
168
- - `bold(text)` - Texte en gras
169
- - `underline(text)` - Texte souligné
170
- - `italic(text)` - Texte en italique
171
- - `inverse(text)` - Inverse les couleurs
172
- - `strikethrough(text)` - Texte barré
173
-
174
- ### Niveaux de log
175
-
176
- - `setLogLevel(level)` - Définit le niveau de log ('DEBUG', 'INFO', 'WARN', 'ERROR')
177
- - `debug(...args)` - Message de débogage
178
- - `info(...args)` - Information
179
- - `warn(...args)` - Avertissement
180
- - `error(...args)` - Erreur
181
- - `success(...args)` - Succès (alias pour info avec icône de succès)
182
- - `warning(...args)` - Avertissement (alias pour warn avec icône d'avertissement)
183
-
184
- ## Exemples avancés
185
-
186
- ### Combinaison de styles
187
-
188
- ```javascript
189
- // Combinaison de styles
190
- logger.bold(logger.red('Texte en gras et rouge'));
191
- logger.bgBlue(logger.white('Texte blanc sur fond bleu'));
192
- ```
193
-
194
- ### Niveaux de log
195
-
196
- ```javascript
197
- // Définir le niveau de log (par défaut: 'INFO')
198
- logger.setLogLevel('DEBUG');
199
-
200
- // Messages de log
201
- logger.debug('Message de débogage');
202
- logger.info('Information');
203
- logger.warn('Avertissement');
204
- logger.error('Erreur');
205
- ```
206
-
207
- ### Avec des objets et tableaux
208
-
209
- ```javascript
210
- // Objets
211
- const user = {
212
- name: 'John',
213
- age: 30,
214
- roles: ['admin', 'user'],
215
- };
216
- logger.info('Utilisateur:', user);
217
-
218
- // Tableaux
219
- const numbers = [1, 2, 3, 4, 5];
220
- logger.info('Nombres:', numbers);
221
-
222
- // Références circulaires
223
- const obj1 = { name: 'Objet 1' };
224
- const obj2 = { name: 'Objet 2', ref: obj1 };
225
- obj1.ref = obj2;
226
- logger.info('Objet avec référence circulaire:', obj1);
227
- ```
228
-
229
- ## Personnalisation
230
-
231
- ### Styles personnalisés
232
-
233
- ```javascript
234
- // Accès direct aux codes ANSI
235
- console.log(
236
- `${logger.styles.bold}${logger.styles.red}Texte en gras et rouge${logger.styles.reset}`
237
- );
238
- ```
239
-
240
- ### Templates
241
-
242
- ```javascript
243
- const name = 'Alice';
244
- const age = 30;
245
- logger.info('Nom: {0}, Âge: {1}', name, age);
246
- ```
247
-
248
- ## Contribution
249
-
250
- Les contributions sont les bienvenues ! N'hésitez pas à ouvrir une issue ou une pull request.
251
-
252
- ## Licence
253
-
254
- MIT
1
+ # ChromaLogger
2
+
3
+ > A powerful and colorful logger for Node.js with CLI support
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install chromalogger
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```javascript
14
+ import { logger } from 'chromalogger';
15
+
16
+ logger.info('This is an info message');
17
+ logger.success('Operation completed successfully!');
18
+ logger.warn('This is a warning');
19
+ logger.error('An error occurred');
20
+ ```
21
+
22
+ ## Features
23
+
24
+ - Colorful console output
25
+ - Multiple log levels
26
+ - Easy to use API
27
+ - CLI support
28
+
29
+ ## License
30
+
31
+ MIT
package/chromalog.js CHANGED
@@ -1,77 +1,208 @@
1
- /**
2
- * Chromalog - A colorful console logger with formatting and styling
3
- * @module chromalog
4
- */
5
-
6
- // Import core modules
7
- import * as styles from './core/styles.js';
8
-
9
- // Import logger functions
10
- import {
11
- createLogger,
12
- formatMessage,
13
- setLogLevel,
14
- LOG_LEVELS,
15
- } from './core/loggers/consoleLogger.js';
16
-
17
- // Import formatters
18
- import { formatObject } from './core/formatters/objectFormatter.js';
19
-
20
- // Import chroma utility
21
- import chroma from './utils/chroma.js';
22
-
23
- // Create default logger instances
24
- const log = createLogger();
25
- const debug = createLogger('dim');
26
- const info = createLogger('blue');
27
- const warn = createLogger('yellow');
28
- const error = createLogger('red');
29
-
30
- // Main chromalog object
31
- const chromalog = {
32
- // Core
33
- styles,
34
- chroma,
35
-
36
- // Main logger methods
37
- createLogger,
38
- formatMessage,
39
- formatObject,
40
- setLogLevel,
41
-
42
- // Log levels
43
- LOG_LEVELS,
44
-
45
- // Pre-configured loggers
46
- log,
47
- debug,
48
- info,
49
- warn,
50
- error,
51
- };
52
-
53
- // Export everything
54
- export {
55
- // Core
56
- styles,
57
- chroma,
58
-
59
- // Main logger methods
60
- createLogger,
61
- formatMessage,
62
- formatObject,
63
- setLogLevel,
64
-
65
- // Log levels
66
- LOG_LEVELS,
67
-
68
- // Pre-configured loggers
69
- log,
70
- debug,
71
- info,
72
- warn,
73
- error,
74
-
75
- // Default export
76
- chromalog as default,
77
- };
1
+ // ChromaLogger - A colorful console logger for Node.js
2
+
3
+ // Import styles
4
+ import {
5
+ textColors,
6
+ bgColors,
7
+ textStyles
8
+ } from './styles/index.js';
9
+
10
+ // Combine all styles for backward compatibility
11
+ const colors = {
12
+ ...textColors,
13
+ ...bgColors,
14
+ ...textStyles
15
+ };
16
+
17
+ // Main logger class
18
+ class Logger {
19
+ constructor() {
20
+ this.timestamp = false;
21
+ }
22
+
23
+ // Format the log message with color and style
24
+ format(style, ...args) {
25
+ const timestamp = this.timestamp ? `[${new Date().toISOString()}] ` : '';
26
+ // Si style est un tableau, on combine les styles
27
+ const styleStr = Array.isArray(style)
28
+ ? style.join('')
29
+ : style;
30
+ return `${timestamp}${styleStr}${args.join(' ')}${colors.reset}`;
31
+ }
32
+
33
+ // Log methods with different colors
34
+ log(...args) {
35
+ console.log(this.format(colors.reset, ...args));
36
+ }
37
+
38
+ info(...args) {
39
+ console.log(this.format(colors.cyan, ...args));
40
+ }
41
+
42
+ success(...args) {
43
+ console.log(this.format(colors.green, '✓', ...args));
44
+ }
45
+
46
+ warn(...args) {
47
+ console.warn(this.format(colors.yellow, '⚠', ...args));
48
+ }
49
+
50
+ error(...args) {
51
+ console.error(this.format(colors.red, '✗', ...args));
52
+ }
53
+
54
+ // Background color methods
55
+ bgBlack(...args) {
56
+ this._currentBg = colors.bgBlack;
57
+ if (args.length > 0) {
58
+ console.log(this.format(this._currentBg, ...args));
59
+ this._currentBg = undefined;
60
+ }
61
+ return this;
62
+ }
63
+
64
+ bgRed(...args) {
65
+ this._currentBg = colors.bgRed;
66
+ if (args.length > 0) {
67
+ console.log(this.format(this._currentBg, ...args));
68
+ this._currentBg = undefined;
69
+ }
70
+ return this;
71
+ }
72
+
73
+ bgGreen(...args) {
74
+ this._currentBg = colors.bgGreen;
75
+ if (args.length > 0) {
76
+ console.log(this.format(this._currentBg, ...args));
77
+ this._currentBg = undefined;
78
+ }
79
+ return this;
80
+ }
81
+
82
+ bgYellow(...args) {
83
+ this._currentBg = colors.bgYellow;
84
+ if (args.length > 0) {
85
+ console.log(this.format(this._currentBg, ...args));
86
+ this._currentBg = undefined;
87
+ }
88
+ return this;
89
+ }
90
+
91
+ bgBlue(...args) {
92
+ this._currentBg = colors.bgBlue;
93
+ if (args.length > 0) {
94
+ console.log(this.format(this._currentBg, ...args));
95
+ this._currentBg = undefined;
96
+ }
97
+ return this;
98
+ }
99
+
100
+ bgMagenta(...args) {
101
+ this._currentBg = colors.bgMagenta;
102
+ if (args.length > 0) {
103
+ console.log(this.format(this._currentBg, ...args));
104
+ this._currentBg = undefined;
105
+ }
106
+ return this;
107
+ }
108
+
109
+ bgCyan(...args) {
110
+ this._currentBg = colors.bgCyan;
111
+ if (args.length > 0) {
112
+ console.log(this.format(this._currentBg, ...args));
113
+ this._currentBg = undefined;
114
+ }
115
+ return this;
116
+ }
117
+
118
+ bgWhite(...args) {
119
+ this._currentBg = colors.bgWhite;
120
+ if (args.length > 0) {
121
+ console.log(this.format(this._currentBg, ...args));
122
+ this._currentBg = undefined;
123
+ }
124
+ return this;
125
+ }
126
+
127
+ // Text color methods
128
+ black(...args) { return this._applyTextColor(colors.black, ...args); }
129
+ red(...args) { return this._applyTextColor(colors.red, ...args); }
130
+ green(...args) { return this._applyTextColor(colors.green, ...args); }
131
+ yellow(...args) { return this._applyTextColor(colors.yellow, ...args); }
132
+ blue(...args) { return this._applyTextColor(colors.blue, ...args); }
133
+ magenta(...args) { return this._applyTextColor(colors.magenta, ...args); }
134
+ cyan(...args) { return this._applyTextColor(colors.cyan, ...args); }
135
+ white(...args) { return this._applyTextColor(colors.white, ...args); }
136
+
137
+ // Text style methods
138
+ bright(...args) { return this._applyTextStyle(colors.bright, ...args); }
139
+ dim(...args) { return this._applyTextStyle(colors.dim, ...args); }
140
+ italic(...args) { return this._applyTextStyle(colors.italic, ...args); }
141
+ underline(...args) { return this._applyTextStyle(colors.underline, ...args); }
142
+ blink(...args) { return this._applyTextStyle(colors.blink, ...args); }
143
+ reverse(...args) { return this._applyTextStyle(colors.reverse, ...args); }
144
+ hidden(...args) { return this._applyTextStyle(colors.hidden, ...args); }
145
+
146
+ // Helper methods for chaining
147
+ _applyTextColor(color, ...args) {
148
+ this._currentFg = color;
149
+ if (args.length > 0) {
150
+ this._logWithCurrentStyles(...args);
151
+ }
152
+ return this;
153
+ }
154
+
155
+ _applyTextStyle(style, ...args) {
156
+ if (!this._currentStyles) this._currentStyles = [];
157
+ this._currentStyles.push(style);
158
+ if (args.length > 0) {
159
+ this._logWithCurrentStyles(...args);
160
+ }
161
+ return this;
162
+ }
163
+
164
+ _logWithCurrentStyles(...args) {
165
+ const styles = [];
166
+ if (this._currentBg) styles.push(this._currentBg);
167
+ if (this._currentFg) styles.push(this._currentFg);
168
+ if (this._currentStyles) styles.push(...this._currentStyles);
169
+
170
+ console.log(this.format(styles, ...args));
171
+
172
+ // Reset styles after logging
173
+ this._currentBg = undefined;
174
+ this._currentFg = undefined;
175
+ this._currentStyles = [];
176
+ }
177
+
178
+ // Combined styles
179
+ errorHighlight(...args) {
180
+ console.error(this.format([colors.bright, colors.bgRed, colors.white], '✗', ...args));
181
+ }
182
+
183
+ successHighlight(...args) {
184
+ console.log(this.format([colors.bright, colors.bgGreen, colors.black], '✓', ...args));
185
+ }
186
+
187
+ warningHighlight(...args) {
188
+ console.warn(this.format([colors.bright, colors.bgYellow, colors.black], '⚠', ...args));
189
+ }
190
+
191
+ infoHighlight(...args) {
192
+ console.log(this.format([colors.bright, colors.bgBlue, colors.white], 'ℹ', ...args));
193
+ }
194
+
195
+ // Enable/disable timestamps
196
+ setTimestamp(enabled = true) {
197
+ this.timestamp = enabled;
198
+ return this;
199
+ }
200
+ }
201
+
202
+ // Create a default logger instance
203
+ const logger = new Logger();
204
+
205
+ // Export the logger class and default instance
206
+ export { Logger, logger };
207
+
208
+ export default logger;
package/index.js CHANGED
@@ -1,101 +1,6 @@
1
- /**
2
- * ChromaLog - A powerful console logger with rich formatting and styling
3
- * @module chromalog
4
- * @example
5
- * // Importation de base
6
- * import chromalog from './index.js';
7
- *
8
- * // Utilisation des loggers prédéfinis
9
- * chromalog.info('Message informatif');
10
- * chromalog.error('Erreur critique!');
11
- *
12
- * // Création d'un logger personnalisé
13
- * const myLogger = chromalog.createLogger('green', 'underline');
14
- * myLogger('Message personnalisé');
15
- */
16
-
17
- // Import core modules
18
- import * as styles from './core/styles.js';
19
- import {
20
- createLogger,
21
- formatMessage,
22
- setLogLevel,
23
- LOG_LEVELS,
24
- } from './core/loggers/consoleLogger.js';
25
- import { formatObject } from './core/formatters/objectFormatter.js';
26
-
27
- /**
28
- * Logger de base sans style particulier
29
- * @type {Function}
30
- */
31
- const log = createLogger();
32
-
33
- /**
34
- * Logger pour les messages de débogage (style atténué)
35
- * @type {Function}
36
- */
37
- const debug = createLogger('dim');
38
-
39
- /**
40
- * Logger pour les messages informatifs (style cyan)
41
- * @type {Function}
42
- */
43
- const info = createLogger('cyan');
44
-
45
- /**
46
- * Logger pour les avertissements (style jaune)
47
- * @type {Function}
48
- */
49
- const warn = createLogger('yellow');
50
-
51
- /**
52
- * Logger pour les erreurs (style rouge)
53
- * @type {Function}
54
- */
55
- const error = createLogger('red');
56
-
57
- // Export par défaut avec toutes les fonctionnalités
58
- const ChromaLog = {
59
- // Core
60
- styles,
61
-
62
- // Main logger methods
63
- createLogger,
64
- formatMessage,
65
- formatObject,
66
- setLogLevel,
67
-
68
- // Log levels
69
- LOG_LEVELS,
70
-
71
- // Pre-configured loggers
72
- log,
73
- debug,
74
- info,
75
- warn,
76
- error,
77
- };
78
-
79
- export default ChromaLog;
80
-
81
- // Export nommé pour l'import déstructuré
82
- export {
83
- // Core
84
- styles,
85
-
86
- // Main logger methods
87
- createLogger,
88
- formatMessage,
89
- formatObject,
90
- setLogLevel,
91
-
92
- // Log levels
93
- LOG_LEVELS,
94
-
95
- // Pre-configured loggers
96
- log,
97
- debug,
98
- info,
99
- warn,
100
- error,
101
- };
1
+ // Import and re-export the logger from chromalog.js
2
+ export * from './chromalog.js';
3
+
4
+ // Set default export to be the default logger instance
5
+ import { logger } from './chromalog.js';
6
+ export default logger;