chromalogger 1.1.2 → 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 +1 -1
- package/README.md +15 -50
- package/chromalog.js +208 -77
- package/index.js +6 -61
- package/package.json +7 -25
- package/.eslintrc.json +0 -18
- package/.prettierrc +0 -9
- package/CHROMA.md +0 -253
- package/CONTRIBUTING.md +0 -43
- package/INFO.md +0 -128
- package/README.fr.md +0 -360
- package/cli.js +0 -87
- package/core/formatters/objectFormatter.js +0 -131
- package/core/loggers/consoleLogger.js +0 -218
- package/core/styles.js +0 -75
- package/core/utils/validate.js +0 -45
- package/test.js +0 -159
- package/utils/chroma.js +0 -42
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,66 +1,31 @@
|
|
|
1
1
|
# ChromaLogger
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://opensource.org/licenses/MIT)
|
|
5
|
-
[](https://github.com/OrssiMp/chromalogger/stargazers)
|
|
3
|
+
> A powerful and colorful logger for Node.js with CLI support
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
ChromaLogger is a powerful and flexible Node.js console logging library with advanced support for colors, styles, and debugging features. Perfect for Node.js application development and debugging.
|
|
10
|
-
|
|
11
|
-
## 🚀 Features
|
|
12
|
-
|
|
13
|
-
- 🌈 Rich color and style support (16+ colors, text formatting)
|
|
14
|
-
- 📊 Built-in log levels (DEBUG, INFO, WARN, ERROR)
|
|
15
|
-
- 🔄 Circular reference detection
|
|
16
|
-
- 📝 Template string support
|
|
17
|
-
- 🛠️ Customizable loggers
|
|
18
|
-
- 💻 CLI tool included
|
|
19
|
-
- 🔌 Extensible architecture
|
|
20
|
-
|
|
21
|
-
## 📦 Installation
|
|
5
|
+
## Installation
|
|
22
6
|
|
|
23
7
|
```bash
|
|
24
|
-
# With npm
|
|
25
8
|
npm install chromalogger
|
|
26
|
-
|
|
27
|
-
# Or with Yarn
|
|
28
|
-
yarn add chromalogger
|
|
29
9
|
```
|
|
30
10
|
|
|
31
|
-
##
|
|
11
|
+
## Usage
|
|
32
12
|
|
|
33
13
|
```javascript
|
|
34
|
-
import {
|
|
35
|
-
|
|
36
|
-
// Basic usage
|
|
37
|
-
log('This is a log message');
|
|
38
|
-
info('Informational message');
|
|
39
|
-
warn('Warning message');
|
|
40
|
-
error('Error message');
|
|
14
|
+
import { logger } from 'chromalogger';
|
|
41
15
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// Template strings
|
|
47
|
-
const user = { name: 'Alice', age: 30 };
|
|
48
|
-
info('User {0} is {1} years old', user.name, user.age);
|
|
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');
|
|
49
20
|
```
|
|
50
21
|
|
|
51
|
-
##
|
|
52
|
-
|
|
53
|
-
For complete documentation, please visit our [GitHub Wiki](https://github.com/yourusername/chromalogger/wiki).
|
|
54
|
-
|
|
55
|
-
## 🤝 Contributing
|
|
56
|
-
|
|
57
|
-
Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) to get started.
|
|
58
|
-
|
|
59
|
-
## 📄 License
|
|
22
|
+
## Features
|
|
60
23
|
|
|
61
|
-
|
|
24
|
+
- Colorful console output
|
|
25
|
+
- Multiple log levels
|
|
26
|
+
- Easy to use API
|
|
27
|
+
- CLI support
|
|
62
28
|
|
|
63
|
-
##
|
|
29
|
+
## License
|
|
64
30
|
|
|
65
|
-
|
|
66
|
-
- Thanks to all contributors who have helped improve this project
|
|
31
|
+
MIT
|
package/chromalog.js
CHANGED
|
@@ -1,77 +1,208 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
//
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
//
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
error
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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,61 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
// Créer les loggers avec leurs styles respectifs
|
|
28
|
-
const log = createLogger();
|
|
29
|
-
const debug = createLogger('dim');
|
|
30
|
-
const info = createLogger('cyan');
|
|
31
|
-
const warn = createLogger('yellow');
|
|
32
|
-
const error = createLogger('red');
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* ChromaLog - A powerful console logger with rich formatting and styling
|
|
36
|
-
*/
|
|
37
|
-
const ChromaLog = {
|
|
38
|
-
// Core
|
|
39
|
-
styles,
|
|
40
|
-
createLogger,
|
|
41
|
-
formatMessage,
|
|
42
|
-
formatObject,
|
|
43
|
-
setLogLevel,
|
|
44
|
-
LOG_LEVELS: { ...LOG_LEVELS },
|
|
45
|
-
|
|
46
|
-
// Loggers
|
|
47
|
-
log: (...args) => log(...args),
|
|
48
|
-
debug: (...args) => debug(...args),
|
|
49
|
-
info: (...args) => info(...args),
|
|
50
|
-
warn: (...args) => warn(...args),
|
|
51
|
-
error: (...args) => error(...args),
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// Exporter les loggers individuellement
|
|
55
|
-
export { log, debug, info, warn, error };
|
|
56
|
-
|
|
57
|
-
// Exporter les fonctions utilitaires
|
|
58
|
-
export { styles, createLogger, formatMessage, formatObject, setLogLevel, LOG_LEVELS };
|
|
59
|
-
|
|
60
|
-
// Exporter par défaut l'objet ChromaLog
|
|
61
|
-
export default ChromaLog;
|
|
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;
|
package/package.json
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chromalogger",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "A colorful and flexible console logger for Node.js with CLI support",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js",
|
|
9
|
+
"chromalog.js"
|
|
10
|
+
],
|
|
10
11
|
"scripts": {
|
|
11
|
-
"test": "node
|
|
12
|
-
"test:watch": "nodemon --watch chromalog.js --watch test.js --exec \"npm test\"",
|
|
13
|
-
"lint": "eslint .",
|
|
14
|
-
"test:chroma": "node chromatest.js",
|
|
15
|
-
"test:cli": "node clitest.js",
|
|
16
|
-
"test:all": "npm run test && npm run test:chroma && npm run test:cli",
|
|
17
|
-
"format": "prettier --write .",
|
|
18
|
-
"fix": "eslint --fix .",
|
|
19
|
-
"coverage": "c8 npm test"
|
|
12
|
+
"test": "node demo.js"
|
|
20
13
|
},
|
|
21
14
|
"keywords": [
|
|
22
15
|
"log",
|
|
@@ -48,16 +41,5 @@
|
|
|
48
41
|
},
|
|
49
42
|
"engines": {
|
|
50
43
|
"node": ">=12.0.0"
|
|
51
|
-
},
|
|
52
|
-
"dependencies": {
|
|
53
|
-
"util": "^0.12.5"
|
|
54
|
-
},
|
|
55
|
-
"devDependencies": {
|
|
56
|
-
"c8": "^10.1.3",
|
|
57
|
-
"eslint": "^8.0.0",
|
|
58
|
-
"eslint-config-prettier": "^10.1.8",
|
|
59
|
-
"eslint-plugin-prettier": "^5.5.4",
|
|
60
|
-
"nodemon": "^3.1.11",
|
|
61
|
-
"prettier": "^3.7.3"
|
|
62
44
|
}
|
|
63
45
|
}
|
package/.eslintrc.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"env": {
|
|
3
|
-
"node": true,
|
|
4
|
-
"es2021": true,
|
|
5
|
-
"browser": true
|
|
6
|
-
},
|
|
7
|
-
"extends": ["eslint:recommended", "prettier"],
|
|
8
|
-
"parserOptions": {
|
|
9
|
-
"ecmaVersion": 2021,
|
|
10
|
-
"sourceType": "module"
|
|
11
|
-
},
|
|
12
|
-
"rules": {
|
|
13
|
-
"no-console": "off",
|
|
14
|
-
"no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
|
|
15
|
-
"prettier/prettier": "error"
|
|
16
|
-
},
|
|
17
|
-
"plugins": ["prettier"]
|
|
18
|
-
}
|