terminal-prettier 1.0.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/README.md +44 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +79 -0
- package/package.json +35 -0
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# terminal-pretty-logger
|
|
2
|
+
|
|
3
|
+
A small TypeScript logger for terminals: ISO timestamps, emoji level icons, and optional ANSI colors—aimed at command-line tools and local development.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install terminal-pretty-logger
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import logger from 'terminal-pretty-logger';
|
|
15
|
+
|
|
16
|
+
logger.info('Application started');
|
|
17
|
+
logger.debug('Debug information', { key: 'value' });
|
|
18
|
+
logger.warn('Warning message');
|
|
19
|
+
logger.error('Error occurred', new Error('Something went wrong'));
|
|
20
|
+
logger.fatal('Fatal error');
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Log levels
|
|
24
|
+
|
|
25
|
+
| Level | Purpose |
|
|
26
|
+
| ------- | ----------------------- |
|
|
27
|
+
| `trace` | Very detailed tracing |
|
|
28
|
+
| `debug` | Debugging |
|
|
29
|
+
| `info` | General information |
|
|
30
|
+
| `warn` | Warnings |
|
|
31
|
+
| `error` | Errors |
|
|
32
|
+
| `fatal` | Unrecoverable failures |
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
36
|
+
- Per-level colors in supported terminals
|
|
37
|
+
- Emoji icons for quick scanning
|
|
38
|
+
- ISO-8601 timestamps on each line
|
|
39
|
+
- Written in TypeScript with bundled type declarations
|
|
40
|
+
- No runtime dependencies beyond Node
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
2
|
+
declare class Logger {
|
|
3
|
+
private colors;
|
|
4
|
+
private levelIcons;
|
|
5
|
+
private formatTimestamp;
|
|
6
|
+
private formatMessage;
|
|
7
|
+
trace(message: string, ...args: unknown[]): void;
|
|
8
|
+
debug(message: string, ...args: unknown[]): void;
|
|
9
|
+
info(message: string, ...args: unknown[]): void;
|
|
10
|
+
warn(message: string, ...args: unknown[]): void;
|
|
11
|
+
error(message: string, ...args: unknown[]): void;
|
|
12
|
+
fatal(message: string, ...args: unknown[]): void;
|
|
13
|
+
log(level: LogLevel, message: string, ...args: unknown[]): void;
|
|
14
|
+
}
|
|
15
|
+
export declare const logger: Logger;
|
|
16
|
+
export default logger;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = void 0;
|
|
4
|
+
class Logger {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.colors = {
|
|
7
|
+
reset: '\x1b[0m',
|
|
8
|
+
trace: '\x1b[90m',
|
|
9
|
+
debug: '\x1b[36m',
|
|
10
|
+
info: '\x1b[32m',
|
|
11
|
+
warn: '\x1b[33m',
|
|
12
|
+
error: '\x1b[31m',
|
|
13
|
+
fatal: '\x1b[35m',
|
|
14
|
+
};
|
|
15
|
+
this.levelIcons = {
|
|
16
|
+
trace: '🔍',
|
|
17
|
+
debug: '🐛',
|
|
18
|
+
info: 'ℹ️',
|
|
19
|
+
warn: '⚠️',
|
|
20
|
+
error: '❌',
|
|
21
|
+
fatal: '💀',
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
formatTimestamp() {
|
|
25
|
+
const now = new Date();
|
|
26
|
+
return now.toISOString();
|
|
27
|
+
}
|
|
28
|
+
formatMessage(level, message, options = {}) {
|
|
29
|
+
const { timestamp = true, colorize = true } = options;
|
|
30
|
+
const color = colorize ? this.colors[level] : '';
|
|
31
|
+
const reset = colorize ? this.colors.reset : '';
|
|
32
|
+
const icon = this.levelIcons[level];
|
|
33
|
+
const time = timestamp ? `[${this.formatTimestamp()}]` : '';
|
|
34
|
+
const levelStr = level.toUpperCase().padEnd(5);
|
|
35
|
+
return `${color}${time} ${icon} ${levelStr}${reset} ${message}`;
|
|
36
|
+
}
|
|
37
|
+
trace(message, ...args) {
|
|
38
|
+
console.log(this.formatMessage('trace', message), ...args);
|
|
39
|
+
}
|
|
40
|
+
debug(message, ...args) {
|
|
41
|
+
console.log(this.formatMessage('debug', message), ...args);
|
|
42
|
+
}
|
|
43
|
+
info(message, ...args) {
|
|
44
|
+
console.log(this.formatMessage('info', message), ...args);
|
|
45
|
+
}
|
|
46
|
+
warn(message, ...args) {
|
|
47
|
+
console.warn(this.formatMessage('warn', message), ...args);
|
|
48
|
+
}
|
|
49
|
+
error(message, ...args) {
|
|
50
|
+
console.error(this.formatMessage('error', message), ...args);
|
|
51
|
+
}
|
|
52
|
+
fatal(message, ...args) {
|
|
53
|
+
console.error(this.formatMessage('fatal', message), ...args);
|
|
54
|
+
}
|
|
55
|
+
log(level, message, ...args) {
|
|
56
|
+
switch (level) {
|
|
57
|
+
case 'trace':
|
|
58
|
+
this.trace(message, ...args);
|
|
59
|
+
break;
|
|
60
|
+
case 'debug':
|
|
61
|
+
this.debug(message, ...args);
|
|
62
|
+
break;
|
|
63
|
+
case 'info':
|
|
64
|
+
this.info(message, ...args);
|
|
65
|
+
break;
|
|
66
|
+
case 'warn':
|
|
67
|
+
this.warn(message, ...args);
|
|
68
|
+
break;
|
|
69
|
+
case 'error':
|
|
70
|
+
this.error(message, ...args);
|
|
71
|
+
break;
|
|
72
|
+
case 'fatal':
|
|
73
|
+
this.fatal(message, ...args);
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
exports.logger = new Logger();
|
|
79
|
+
exports.default = exports.logger;
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "terminal-prettier",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Pretty terminal logger for CLIs: ISO timestamps, level icons, and colorized output with zero runtime deps",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"prepublishOnly": "npm run build",
|
|
14
|
+
"start": "ts-node index.ts"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"logger",
|
|
18
|
+
"cli",
|
|
19
|
+
"console",
|
|
20
|
+
"terminal",
|
|
21
|
+
"logging",
|
|
22
|
+
"colorized",
|
|
23
|
+
"pretty",
|
|
24
|
+
"formatter",
|
|
25
|
+
"timestamp"
|
|
26
|
+
],
|
|
27
|
+
"author": "snapbar",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^25.3.0",
|
|
31
|
+
"ts-node": "^10.9.2",
|
|
32
|
+
"tsup": "^8.5.1",
|
|
33
|
+
"typescript": "^5.9.3"
|
|
34
|
+
}
|
|
35
|
+
}
|