scribelog 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/LICENSE +21 -0
- package/README.md +208 -0
- package/dist/format.d.ts +30 -0
- package/dist/format.js +245 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +52 -0
- package/dist/index.js.map +1 -0
- package/dist/levels.d.ts +15 -0
- package/dist/levels.js +18 -0
- package/dist/levels.js.map +1 -0
- package/dist/logger.d.ts +43 -0
- package/dist/logger.js +253 -0
- package/dist/logger.js.map +1 -0
- package/dist/transports/console.d.ts +13 -0
- package/dist/transports/console.js +86 -0
- package/dist/transports/console.js.map +1 -0
- package/dist/types.d.ts +53 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +6 -0
- package/dist/utils.js +20 -0
- package/dist/utils.js.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 tolongames
|
|
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.
|
package/README.md
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# Scribelog 🪵📝
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/scribelog)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
**Scribelog** is an advanced, highly configurable logging library for Node.js applications, written in TypeScript. It offers flexible formatting, support for multiple destinations (transports), child loggers, and automatic error catching.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## ✨ Key Features
|
|
11
|
+
|
|
12
|
+
- **Logging Levels:** Standard levels (`error`, `warn`, `info`, `http`, `verbose`, `debug`, `silly`).
|
|
13
|
+
- **Flexible Formatting:** Composable formatters (`simple`, `json`, `timestamp`, `metadata`, `errors`, etc.) with configuration options. Console color support.
|
|
14
|
+
- **Transports:** Built-in `ConsoleTransport`. Architecture ready for future extensions (e.g., `FileTransport`).
|
|
15
|
+
- **Child Loggers:** Create loggers that inherit parent configuration with additional, fixed context (`logger.child({...})`).
|
|
16
|
+
- **Error Handling:** Automatically logs uncaught exceptions and unhandled promise rejections with an option to exit the process.
|
|
17
|
+
- **Written in TypeScript:** Type-safe and developer-friendly.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## 📦 Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install scribelog
|
|
25
|
+
# or
|
|
26
|
+
yarn add scribelog
|
|
27
|
+
# or
|
|
28
|
+
pnpm add scribelog
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 🚀 Basic Usage
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { createLogger, format, transports } from 'scribelog';
|
|
37
|
+
|
|
38
|
+
const logger = createLogger();
|
|
39
|
+
|
|
40
|
+
logger.info('Application started.');
|
|
41
|
+
logger.warn('Low memory warning!', { freeMemory: 100 });
|
|
42
|
+
logger.error(new Error('Could not connect to the database.'));
|
|
43
|
+
|
|
44
|
+
const userLogger = logger.child({ userId: 'user-123' });
|
|
45
|
+
userLogger.debug('Fetching user data.');
|
|
46
|
+
|
|
47
|
+
const jsonLogger = createLogger({
|
|
48
|
+
level: 'debug',
|
|
49
|
+
format: format.json(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
jsonLogger.debug('Debugging operation X', { operationId: 'op-xyz' });
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## ⚙️ Configuration
|
|
58
|
+
|
|
59
|
+
Create a logger using `createLogger(options?: LoggerOptions)`
|
|
60
|
+
|
|
61
|
+
**LoggerOptions:**
|
|
62
|
+
|
|
63
|
+
| Option | Type | Default | Description |
|
|
64
|
+
|---------------------|---------------------------|------------------|-------------|
|
|
65
|
+
| `level` | `string` | `'info'` | Minimum level to log |
|
|
66
|
+
| `format` | `LogFormat` | `simple` | Formatter pipeline |
|
|
67
|
+
| `transports` | `Transport[]` | `Console` | Where to send logs |
|
|
68
|
+
| `defaultMeta` | `Record<string, any>` | `undefined` | Metadata included in all logs |
|
|
69
|
+
| `handleExceptions` | `boolean` | `false` | Logs uncaught exceptions |
|
|
70
|
+
| `handleRejections` | `boolean` | `false` | Logs unhandled promise rejections |
|
|
71
|
+
| `exitOnError` | `boolean` | `true` | Exits process on fatal errors |
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 📊 Logging Levels
|
|
76
|
+
|
|
77
|
+
```text
|
|
78
|
+
error: 0
|
|
79
|
+
warn: 1
|
|
80
|
+
info: 2
|
|
81
|
+
http: 3
|
|
82
|
+
verbose: 4
|
|
83
|
+
debug: 5
|
|
84
|
+
silly: 6
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Set the `level` option to control minimum log severity.
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## 🎨 Formatting
|
|
92
|
+
|
|
93
|
+
Formatters modify the log info object before sending it to transports. You can combine them using `format.combine(...)`.
|
|
94
|
+
|
|
95
|
+
### Core Formatters
|
|
96
|
+
|
|
97
|
+
- `format.timestamp({ alias?, format? })`
|
|
98
|
+
- `format.level({ alias? })`
|
|
99
|
+
- `format.message({ alias? })`
|
|
100
|
+
- `format.errors({ stack?: boolean })`
|
|
101
|
+
- `format.metadata({ alias?: string, exclude?: string[] })`
|
|
102
|
+
|
|
103
|
+
### Terminal Formatters
|
|
104
|
+
|
|
105
|
+
- `format.json({ space?: string | number })`
|
|
106
|
+
- `format.simple({ colors?: boolean })`
|
|
107
|
+
|
|
108
|
+
### Example: Combined Formatter
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
const myFormat = format.combine(
|
|
112
|
+
format.errors({ stack: true }),
|
|
113
|
+
format.timestamp({ format: 'HH:mm:ss' }),
|
|
114
|
+
format.level(),
|
|
115
|
+
format.message(),
|
|
116
|
+
format.metadata({ alias: 'meta' }),
|
|
117
|
+
format.json({ space: 2 })
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const logger = createLogger({ format: myFormat });
|
|
121
|
+
|
|
122
|
+
logger.info('Log with custom format', { userId: 1, data: { ok: true } });
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## 📤 Transports
|
|
128
|
+
|
|
129
|
+
Transports define where the logs are sent.
|
|
130
|
+
|
|
131
|
+
### ConsoleTransport
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
new transports.Console({
|
|
135
|
+
level: 'error',
|
|
136
|
+
format: format.json(),
|
|
137
|
+
useStdErrLevels: ['error']
|
|
138
|
+
});
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Example
|
|
142
|
+
|
|
143
|
+
```ts
|
|
144
|
+
const logger = createLogger({
|
|
145
|
+
level: 'debug',
|
|
146
|
+
transports: [
|
|
147
|
+
new transports.Console({ level: 'info' }),
|
|
148
|
+
new transports.Console({
|
|
149
|
+
level: 'error',
|
|
150
|
+
format: format.json(),
|
|
151
|
+
useStdErrLevels: ['error']
|
|
152
|
+
})
|
|
153
|
+
]
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## 🌱 Child Loggers
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
const mainLogger = createLogger({ defaultMeta: { service: 'main-app' } });
|
|
163
|
+
|
|
164
|
+
function handleRequest(requestId: string) {
|
|
165
|
+
const requestLogger = mainLogger.child({ requestId });
|
|
166
|
+
|
|
167
|
+
requestLogger.info('Processing request started.');
|
|
168
|
+
try {
|
|
169
|
+
if (Math.random() > 0.5) throw new Error('Random error');
|
|
170
|
+
requestLogger.info('Request processed successfully.');
|
|
171
|
+
} catch (err) {
|
|
172
|
+
requestLogger.error(err);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## 🛠️ Error Handling
|
|
180
|
+
|
|
181
|
+
Enable automatic global error logging:
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
const logger = createLogger({
|
|
185
|
+
handleExceptions: true,
|
|
186
|
+
handleRejections: true,
|
|
187
|
+
// exitOnError: false
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
By default, `exitOnError: true` will terminate the process after logging a fatal error.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## 📚 Future Work
|
|
196
|
+
|
|
197
|
+
- Add `FileTransport` with rotation
|
|
198
|
+
- More built-in formatters (e.g., `splat`, `printf`)
|
|
199
|
+
- Advanced color customization
|
|
200
|
+
- Custom logging levels
|
|
201
|
+
- Better async handling in transports
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## 📄 License
|
|
206
|
+
|
|
207
|
+
MIT
|
|
208
|
+
See [LICENSE](./LICENSE) for details.
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { LogFormat } from './types';
|
|
2
|
+
interface TimestampOptions {
|
|
3
|
+
alias?: string;
|
|
4
|
+
format?: string | ((date: Date) => string);
|
|
5
|
+
}
|
|
6
|
+
export declare const timestamp: (options?: TimestampOptions) => LogFormat;
|
|
7
|
+
export declare const level: (options?: {
|
|
8
|
+
alias?: string;
|
|
9
|
+
}) => LogFormat;
|
|
10
|
+
export declare const message: (options?: {
|
|
11
|
+
alias?: string;
|
|
12
|
+
}) => LogFormat;
|
|
13
|
+
interface ErrorsOptions {
|
|
14
|
+
stack?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare const errors: (options?: ErrorsOptions) => LogFormat;
|
|
17
|
+
export declare const metadata: (options?: {
|
|
18
|
+
alias?: string;
|
|
19
|
+
exclude?: string[];
|
|
20
|
+
}) => LogFormat;
|
|
21
|
+
export declare const json: (options?: {
|
|
22
|
+
space?: string | number;
|
|
23
|
+
}) => LogFormat;
|
|
24
|
+
export declare const simple: (options?: {
|
|
25
|
+
colors?: boolean;
|
|
26
|
+
}) => LogFormat;
|
|
27
|
+
export declare const combine: (...formats: LogFormat[]) => LogFormat;
|
|
28
|
+
export declare const defaultJsonFormat: LogFormat;
|
|
29
|
+
export declare const defaultSimpleFormat: LogFormat;
|
|
30
|
+
export {};
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.defaultSimpleFormat = exports.defaultJsonFormat = exports.combine = exports.simple = exports.json = exports.metadata = exports.errors = exports.message = exports.level = exports.timestamp = void 0;
|
|
7
|
+
const util_1 = require("util");
|
|
8
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
+
const date_fns_1 = require("date-fns");
|
|
10
|
+
// Symbole wewnętrzne
|
|
11
|
+
const LEVEL = Symbol.for('level');
|
|
12
|
+
const MESSAGE = Symbol.for('message');
|
|
13
|
+
const timestamp = (options = {}) => {
|
|
14
|
+
const { alias = 'timestamp', format: formatOption } = options;
|
|
15
|
+
return (info) => {
|
|
16
|
+
const ts = info.timestamp instanceof Date ? info.timestamp : new Date();
|
|
17
|
+
let formattedTs;
|
|
18
|
+
if (typeof formatOption === 'function') {
|
|
19
|
+
try {
|
|
20
|
+
formattedTs = formatOption(ts);
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
console.error('[scribelog] Error in custom timestamp format function:', e);
|
|
24
|
+
formattedTs = ts.toISOString();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else if (typeof formatOption === 'string') {
|
|
28
|
+
try {
|
|
29
|
+
formattedTs = (0, date_fns_1.format)(ts, formatOption);
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
console.error('[scribelog] Invalid date format provided:', formatOption, e);
|
|
33
|
+
formattedTs = ts.toISOString();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
formattedTs = ts.toISOString();
|
|
38
|
+
}
|
|
39
|
+
info[alias] = formattedTs;
|
|
40
|
+
if (!(info.originalTimestamp instanceof Date)) {
|
|
41
|
+
info.originalTimestamp = ts;
|
|
42
|
+
}
|
|
43
|
+
if (alias !== 'timestamp' && info.timestamp instanceof Date) {
|
|
44
|
+
delete info.timestamp;
|
|
45
|
+
}
|
|
46
|
+
return info;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
exports.timestamp = timestamp;
|
|
50
|
+
const level = (options = {}) => {
|
|
51
|
+
const { alias = 'level' } = options;
|
|
52
|
+
return (info) => {
|
|
53
|
+
if (info.level) {
|
|
54
|
+
info[alias] = info.level;
|
|
55
|
+
}
|
|
56
|
+
return info; // Zawsze zwracaj info
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
exports.level = level;
|
|
60
|
+
const message = (options = {}) => {
|
|
61
|
+
const { alias = 'message' } = options;
|
|
62
|
+
return (info) => {
|
|
63
|
+
if (info.message !== undefined) {
|
|
64
|
+
info[alias] = info.message;
|
|
65
|
+
}
|
|
66
|
+
return info; // Zawsze zwracaj info
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
exports.message = message;
|
|
70
|
+
const errors = (options = {}) => {
|
|
71
|
+
const includeStack = options.stack !== false;
|
|
72
|
+
return (info) => {
|
|
73
|
+
let error = undefined;
|
|
74
|
+
let errorKey = undefined;
|
|
75
|
+
if (info.error instanceof Error) {
|
|
76
|
+
error = info.error;
|
|
77
|
+
errorKey = 'error';
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
for (const key in info) {
|
|
81
|
+
if (info[key] instanceof Error) {
|
|
82
|
+
error = info[key];
|
|
83
|
+
errorKey = key;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (error && errorKey) {
|
|
89
|
+
if (info.message === undefined || info.message === '') {
|
|
90
|
+
info.message = error.message;
|
|
91
|
+
}
|
|
92
|
+
info.errorName = error.name;
|
|
93
|
+
if (includeStack) {
|
|
94
|
+
info.stack = error.stack;
|
|
95
|
+
}
|
|
96
|
+
Object.getOwnPropertyNames(error).forEach((key) => {
|
|
97
|
+
if (key !== 'message' &&
|
|
98
|
+
key !== 'name' &&
|
|
99
|
+
key !== 'stack' &&
|
|
100
|
+
!(key in info)) {
|
|
101
|
+
info[key] = error[key];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
if (error.originalReason) {
|
|
105
|
+
info.originalReason = error.originalReason;
|
|
106
|
+
}
|
|
107
|
+
delete info[errorKey];
|
|
108
|
+
}
|
|
109
|
+
return info; // Zawsze zwracaj info
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
exports.errors = errors;
|
|
113
|
+
const metadata = (options = {}) => {
|
|
114
|
+
const { alias, exclude = [] } = options;
|
|
115
|
+
// --- POCZĄTEK ZMIANY: Usunięto 'originalReason' ---
|
|
116
|
+
const standardAliases = [
|
|
117
|
+
'timestamp',
|
|
118
|
+
'level',
|
|
119
|
+
'message',
|
|
120
|
+
'originalTimestamp',
|
|
121
|
+
'errorName',
|
|
122
|
+
'stack',
|
|
123
|
+
/* 'originalReason', */ 'exception',
|
|
124
|
+
'eventType',
|
|
125
|
+
];
|
|
126
|
+
// --- KONIEC ZMIANY ---
|
|
127
|
+
if (alias)
|
|
128
|
+
standardAliases.push(alias);
|
|
129
|
+
const forbidden = new Set([...standardAliases, ...exclude]);
|
|
130
|
+
return (info) => {
|
|
131
|
+
const meta = {};
|
|
132
|
+
for (const key in info) {
|
|
133
|
+
if (typeof key !== 'symbol' &&
|
|
134
|
+
!forbidden.has(key) &&
|
|
135
|
+
Object.prototype.hasOwnProperty.call(info, key)) {
|
|
136
|
+
meta[key] = info[key];
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (alias) {
|
|
140
|
+
info[alias] = meta;
|
|
141
|
+
for (const key in meta) {
|
|
142
|
+
if (!forbidden.has(key)) {
|
|
143
|
+
delete info[key];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return info; // Zawsze zwracaj info
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
exports.metadata = metadata;
|
|
151
|
+
// --- Formaty Końcowe ---
|
|
152
|
+
const json = (options) => {
|
|
153
|
+
return (info) => {
|
|
154
|
+
const logObject = Object.assign({}, info);
|
|
155
|
+
delete logObject[LEVEL];
|
|
156
|
+
delete logObject[MESSAGE];
|
|
157
|
+
delete logObject.originalTimestamp;
|
|
158
|
+
if (logObject.timestamp instanceof Date) {
|
|
159
|
+
logObject.timestamp = logObject.timestamp.toISOString();
|
|
160
|
+
}
|
|
161
|
+
return JSON.stringify(logObject, null, options === null || options === void 0 ? void 0 : options.space);
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
exports.json = json;
|
|
165
|
+
const simple = (options = {}) => {
|
|
166
|
+
const colorsOption = options.colors;
|
|
167
|
+
const timestampColorFn = chalk_1.default.gray;
|
|
168
|
+
return (info) => {
|
|
169
|
+
const supportsColorInfo = chalk_1.default.supportsColor;
|
|
170
|
+
const useColors = colorsOption !== undefined
|
|
171
|
+
? colorsOption
|
|
172
|
+
: supportsColorInfo
|
|
173
|
+
? supportsColorInfo.hasBasic
|
|
174
|
+
: false;
|
|
175
|
+
const shouldUseColors = useColors && chalk_1.default.level > 0;
|
|
176
|
+
const levelColorFnMap = {
|
|
177
|
+
error: chalk_1.default.red,
|
|
178
|
+
warn: chalk_1.default.yellow,
|
|
179
|
+
info: chalk_1.default.green,
|
|
180
|
+
http: chalk_1.default.magenta,
|
|
181
|
+
verbose: chalk_1.default.cyan,
|
|
182
|
+
debug: chalk_1.default.blue,
|
|
183
|
+
silly: chalk_1.default.gray,
|
|
184
|
+
};
|
|
185
|
+
const levelStr = (info.level || 'unknown');
|
|
186
|
+
const msgStr = info.message !== undefined ? info.message : '';
|
|
187
|
+
const timestampStr = typeof info.timestamp === 'string'
|
|
188
|
+
? info.timestamp
|
|
189
|
+
: info.originalTimestamp instanceof Date
|
|
190
|
+
? info.originalTimestamp.toISOString()
|
|
191
|
+
: new Date().toISOString();
|
|
192
|
+
const coloredLevel = shouldUseColors && levelColorFnMap[levelStr]
|
|
193
|
+
? levelColorFnMap[levelStr](`[${levelStr.toUpperCase()}]`)
|
|
194
|
+
: `[${levelStr.toUpperCase()}]`;
|
|
195
|
+
const coloredTimestamp = shouldUseColors
|
|
196
|
+
? timestampColorFn(timestampStr)
|
|
197
|
+
: timestampStr;
|
|
198
|
+
const meta = {};
|
|
199
|
+
// --- POCZĄTEK ZMIANY: Usunięto 'originalReason' ---
|
|
200
|
+
const forbidden = new Set([
|
|
201
|
+
'timestamp',
|
|
202
|
+
'level',
|
|
203
|
+
'message',
|
|
204
|
+
'originalTimestamp',
|
|
205
|
+
'errorName',
|
|
206
|
+
'stack',
|
|
207
|
+
/* 'originalReason', */ 'exception',
|
|
208
|
+
'eventType',
|
|
209
|
+
]);
|
|
210
|
+
// --- KONIEC ZMIANY ---
|
|
211
|
+
for (const key in info) {
|
|
212
|
+
if (typeof key !== 'symbol' &&
|
|
213
|
+
!forbidden.has(key) &&
|
|
214
|
+
Object.prototype.hasOwnProperty.call(info, key)) {
|
|
215
|
+
meta[key] = info[key];
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
const metaString = Object.keys(meta).length
|
|
219
|
+
? ` ${(0, util_1.inspect)(meta, { colors: shouldUseColors, depth: null })}`
|
|
220
|
+
: '';
|
|
221
|
+
const stackString = info.stack && !metaString.includes(info.stack) ? `\n${info.stack}` : '';
|
|
222
|
+
return `${coloredTimestamp} ${coloredLevel}: ${msgStr}${metaString}${stackString}`;
|
|
223
|
+
};
|
|
224
|
+
};
|
|
225
|
+
exports.simple = simple;
|
|
226
|
+
// --- Funkcja Kompozycyjna ---
|
|
227
|
+
const combine = (...formats) => {
|
|
228
|
+
return (info) => {
|
|
229
|
+
let currentInfo = Object.assign({}, info);
|
|
230
|
+
for (const format of formats) {
|
|
231
|
+
const result = format(currentInfo);
|
|
232
|
+
if (typeof result === 'string') {
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
currentInfo =
|
|
236
|
+
typeof result === 'object' && result !== null ? result : currentInfo;
|
|
237
|
+
}
|
|
238
|
+
return currentInfo;
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
exports.combine = combine;
|
|
242
|
+
// --- Predefiniowane Formaty ---
|
|
243
|
+
exports.defaultJsonFormat = (0, exports.combine)((0, exports.errors)({ stack: true }), (0, exports.timestamp)(), (0, exports.level)(), (0, exports.message)(), (0, exports.metadata)(), (0, exports.json)());
|
|
244
|
+
exports.defaultSimpleFormat = (0, exports.combine)((0, exports.errors)({ stack: true }), (0, exports.timestamp)(), (0, exports.level)(), (0, exports.message)(), (0, exports.metadata)(), (0, exports.simple)());
|
|
245
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":";;;;;;AAEA,+BAA+B;AAC/B,kDAA0B;AAC1B,uCAAgD;AAEhD,qBAAqB;AACrB,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAClC,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;AAW/B,MAAM,SAAS,GAAG,CAAC,UAA4B,EAAE,EAAa,EAAE;IACrE,MAAM,EAAE,KAAK,GAAG,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAC9D,OAAO,CAAC,IAAyB,EAAuB,EAAE;QACxD,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,YAAY,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;QACxE,IAAI,WAAmB,CAAC;QACxB,IAAI,OAAO,YAAY,KAAK,UAAU,EAAE,CAAC;YACvC,IAAI,CAAC;gBACH,WAAW,GAAG,YAAY,CAAC,EAAE,CAAC,CAAC;YACjC,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACX,OAAO,CAAC,KAAK,CACX,wDAAwD,EACxD,CAAC,CACF,CAAC;gBACF,WAAW,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;YACjC,CAAC;QACH,CAAC;aAAM,IAAI,OAAO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|
|
|
1
|
+
import { createLogger as _createLogger, Scribelog as _Scribelog } from './logger';
|
|
2
|
+
import type { LoggerInterface as _LoggerInterface, LoggerOptions as _LoggerOptions } from './types';
|
|
3
|
+
import { standardLevels, LogLevel, LogLevels } from './levels';
|
|
4
|
+
import type { LogInfo, Transport as _Transport, LogFormat as _LogFormat } from './types';
|
|
5
|
+
import { ConsoleTransport as _ConsoleTransport } from './transports/console';
|
|
6
|
+
import type { ConsoleTransportOptions as _ConsoleTransportOptions } from './transports/console';
|
|
7
|
+
import * as _format from './format';
|
|
8
|
+
export declare const createLogger: typeof _createLogger;
|
|
9
|
+
export declare const Scribelog: typeof _Scribelog;
|
|
10
|
+
export type Logger = _LoggerInterface;
|
|
11
|
+
export type LoggerOptions = _LoggerOptions;
|
|
12
|
+
export { standardLevels };
|
|
13
|
+
export type { LogLevel, LogLevels };
|
|
14
|
+
export declare const transports: {
|
|
15
|
+
Console: typeof _ConsoleTransport;
|
|
16
|
+
};
|
|
17
|
+
export type Transport = _Transport;
|
|
18
|
+
export type ConsoleTransportOptions = _ConsoleTransportOptions;
|
|
19
|
+
export declare const format: typeof _format;
|
|
20
|
+
export type LogFormat = _LogFormat;
|
|
21
|
+
export type { LogInfo };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.format = exports.transports = exports.standardLevels = exports.Scribelog = exports.createLogger = void 0;
|
|
37
|
+
// src/index.ts
|
|
38
|
+
const logger_1 = require("./logger");
|
|
39
|
+
const levels_1 = require("./levels");
|
|
40
|
+
Object.defineProperty(exports, "standardLevels", { enumerable: true, get: function () { return levels_1.standardLevels; } });
|
|
41
|
+
const console_1 = require("./transports/console");
|
|
42
|
+
const _format = __importStar(require("./format"));
|
|
43
|
+
// Eksportuj główne funkcje i klasy
|
|
44
|
+
exports.createLogger = logger_1.createLogger;
|
|
45
|
+
exports.Scribelog = logger_1.Scribelog;
|
|
46
|
+
// Eksportuj transporty
|
|
47
|
+
exports.transports = {
|
|
48
|
+
Console: console_1.ConsoleTransport,
|
|
49
|
+
};
|
|
50
|
+
// Eksportuj formatery
|
|
51
|
+
exports.format = _format;
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,eAAe;AACf,qCAGkB;AAMlB,qCAA+D;AAmBtD,+FAnBA,uBAAc,OAmBA;AAbvB,kDAA6E;AAE7E,kDAAoC;AAEpC,mCAAmC;AACtB,QAAA,YAAY,GAAG,qBAAa,CAAC;AAC7B,QAAA,SAAS,GAAG,kBAAU,CAAC;AAUpC,uBAAuB;AACV,QAAA,UAAU,GAAG;IACxB,OAAO,EAAE,0BAAiB;CAC3B,CAAC;AAIF,sBAAsB;AACT,QAAA,MAAM,GAAG,OAAO,CAAC"}
|
package/dist/levels.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Definicje standardowych poziomów logowania (zgodne z npm).
|
|
3
|
+
* Niższa wartość oznacza wyższy priorytet.
|
|
4
|
+
*/
|
|
5
|
+
export declare const standardLevels: {
|
|
6
|
+
error: number;
|
|
7
|
+
warn: number;
|
|
8
|
+
info: number;
|
|
9
|
+
http: number;
|
|
10
|
+
verbose: number;
|
|
11
|
+
debug: number;
|
|
12
|
+
silly: number;
|
|
13
|
+
};
|
|
14
|
+
export type LogLevel = keyof typeof standardLevels;
|
|
15
|
+
export type LogLevels = Record<string, number>;
|
package/dist/levels.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/levels.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.standardLevels = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Definicje standardowych poziomów logowania (zgodne z npm).
|
|
7
|
+
* Niższa wartość oznacza wyższy priorytet.
|
|
8
|
+
*/
|
|
9
|
+
exports.standardLevels = {
|
|
10
|
+
error: 0,
|
|
11
|
+
warn: 1,
|
|
12
|
+
info: 2,
|
|
13
|
+
http: 3,
|
|
14
|
+
verbose: 4,
|
|
15
|
+
debug: 5,
|
|
16
|
+
silly: 6,
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=levels.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"levels.js","sourceRoot":"","sources":["../src/levels.ts"],"names":[],"mappings":";AAAA,gBAAgB;;;AAEhB;;;GAGG;AACU,QAAA,cAAc,GAAG;IAC5B,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,OAAO,EAAE,CAAC;IACV,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;CACT,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { LogLevel, LogLevels } from './levels';
|
|
2
|
+
import type { LoggerOptions, LogInfo, Transport, LoggerInterface as _LoggerInterface } from './types';
|
|
3
|
+
type LogEntryInput = Omit<LogInfo, 'timestamp'> & {
|
|
4
|
+
timestamp?: Date;
|
|
5
|
+
};
|
|
6
|
+
export type LoggerInterface = _LoggerInterface;
|
|
7
|
+
export declare class Scribelog implements LoggerInterface {
|
|
8
|
+
levels: LogLevels;
|
|
9
|
+
level: LogLevel;
|
|
10
|
+
private transports;
|
|
11
|
+
private format;
|
|
12
|
+
private defaultMeta?;
|
|
13
|
+
private options;
|
|
14
|
+
private exitOnError;
|
|
15
|
+
private exceptionHandler?;
|
|
16
|
+
private rejectionHandler?;
|
|
17
|
+
constructor(options?: LoggerOptions);
|
|
18
|
+
error(message: string, meta?: Record<string, any>): void;
|
|
19
|
+
warn(message: string, meta?: Record<string, any>): void;
|
|
20
|
+
info(message: string, meta?: Record<string, any>): void;
|
|
21
|
+
http(message: string, meta?: Record<string, any>): void;
|
|
22
|
+
verbose(message: string, meta?: Record<string, any>): void;
|
|
23
|
+
debug(message: string, meta?: Record<string, any>): void;
|
|
24
|
+
silly(message: string, meta?: Record<string, any>): void;
|
|
25
|
+
log(level: LogLevel, message: string, meta?: Record<string, any>): void;
|
|
26
|
+
logEntry(entry: LogEntryInput): void;
|
|
27
|
+
isLevelEnabled(level: LogLevel): boolean;
|
|
28
|
+
addTransport(transport: Transport): void;
|
|
29
|
+
child(childMeta: Record<string, any>): LoggerInterface;
|
|
30
|
+
/**
|
|
31
|
+
* Metoda do logowania błędów przechwyconych przez listenery process.on.
|
|
32
|
+
* Tworzy specjalny obiekt LogInfo z metadanymi błędu.
|
|
33
|
+
*/
|
|
34
|
+
private logError;
|
|
35
|
+
/**
|
|
36
|
+
* Usuwa listenery wyjątków dodane przez ten logger.
|
|
37
|
+
*/
|
|
38
|
+
removeExceptionHandlers(): void;
|
|
39
|
+
private processAndTransport;
|
|
40
|
+
private isTransportLevelEnabled;
|
|
41
|
+
}
|
|
42
|
+
export declare function createLogger(options?: LoggerOptions): LoggerInterface;
|
|
43
|
+
export {};
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
36
|
+
var t = {};
|
|
37
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
38
|
+
t[p] = s[p];
|
|
39
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
40
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
41
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
42
|
+
t[p[i]] = s[p[i]];
|
|
43
|
+
}
|
|
44
|
+
return t;
|
|
45
|
+
};
|
|
46
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
+
exports.Scribelog = void 0;
|
|
48
|
+
exports.createLogger = createLogger;
|
|
49
|
+
// src/logger.ts
|
|
50
|
+
const levels_1 = require("./levels");
|
|
51
|
+
const console_1 = require("./transports/console");
|
|
52
|
+
const format = __importStar(require("./format"));
|
|
53
|
+
// Importuj funkcję pomocniczą do wychodzenia z procesu
|
|
54
|
+
const utils_1 = require("./utils");
|
|
55
|
+
// Klasa Scribelog
|
|
56
|
+
class Scribelog {
|
|
57
|
+
constructor(options = {}) {
|
|
58
|
+
this.options = Object.assign({}, options); // Zapisz kopię opcji
|
|
59
|
+
this.levels = options.levels || levels_1.standardLevels;
|
|
60
|
+
this.level = options.level || 'info';
|
|
61
|
+
this.transports =
|
|
62
|
+
options.transports && options.transports.length > 0
|
|
63
|
+
? options.transports
|
|
64
|
+
: [new console_1.ConsoleTransport()]; // Domyślnie ConsoleTransport
|
|
65
|
+
// Użyj formatu z opcji lub domyślnego simple (który teraz zawiera errors())
|
|
66
|
+
this.format = options.format || format.defaultSimpleFormat;
|
|
67
|
+
this.defaultMeta = options.defaultMeta;
|
|
68
|
+
// Ustaw flagę exitOnError
|
|
69
|
+
this.exitOnError = options.exitOnError !== false;
|
|
70
|
+
// Konfiguracja obsługi nieprzechwyconych wyjątków
|
|
71
|
+
if (options.handleExceptions) {
|
|
72
|
+
this.exceptionHandler = (err) => {
|
|
73
|
+
// Wywołaj logError, przekazując callback do ewentualnego wyjścia
|
|
74
|
+
this.logError('uncaughtException', err, () => {
|
|
75
|
+
if (this.exitOnError) {
|
|
76
|
+
(0, utils_1._internalExit)(1); // Użyj _internalExit
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
// Ostrożnie z removeAllListeners w produkcji!
|
|
81
|
+
process.removeAllListeners('uncaughtException');
|
|
82
|
+
process.on('uncaughtException', this.exceptionHandler);
|
|
83
|
+
}
|
|
84
|
+
// Konfiguracja obsługi nieprzechwyconych odrzuceń promisów
|
|
85
|
+
if (options.handleRejections) {
|
|
86
|
+
this.rejectionHandler = (reason, _promise) => {
|
|
87
|
+
// Stwórz obiekt Error, nawet jeśli reason nim nie jest
|
|
88
|
+
const error = reason instanceof Error
|
|
89
|
+
? reason
|
|
90
|
+
: new Error(String(reason !== null && reason !== void 0 ? reason : 'Unhandled Rejection'));
|
|
91
|
+
if (!(reason instanceof Error)) {
|
|
92
|
+
error.originalReason = reason;
|
|
93
|
+
}
|
|
94
|
+
// Wywołaj logError, przekazując callback
|
|
95
|
+
this.logError('unhandledRejection', error, () => {
|
|
96
|
+
if (this.exitOnError) {
|
|
97
|
+
(0, utils_1._internalExit)(1); // Użyj _internalExit
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
// Ostrożnie z removeAllListeners w produkcji!
|
|
102
|
+
process.removeAllListeners('unhandledRejection');
|
|
103
|
+
process.on('unhandledRejection', this.rejectionHandler);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Metody poziomów (delegują do log)
|
|
107
|
+
error(message, meta) {
|
|
108
|
+
this.log('error', message, meta);
|
|
109
|
+
}
|
|
110
|
+
warn(message, meta) {
|
|
111
|
+
this.log('warn', message, meta);
|
|
112
|
+
}
|
|
113
|
+
info(message, meta) {
|
|
114
|
+
this.log('info', message, meta);
|
|
115
|
+
}
|
|
116
|
+
http(message, meta) {
|
|
117
|
+
this.log('http', message, meta);
|
|
118
|
+
}
|
|
119
|
+
verbose(message, meta) {
|
|
120
|
+
this.log('verbose', message, meta);
|
|
121
|
+
}
|
|
122
|
+
debug(message, meta) {
|
|
123
|
+
this.log('debug', message, meta);
|
|
124
|
+
}
|
|
125
|
+
silly(message, meta) {
|
|
126
|
+
this.log('silly', message, meta);
|
|
127
|
+
}
|
|
128
|
+
// Metoda log (główna logika dla standardowych wywołań)
|
|
129
|
+
log(level, message, meta) {
|
|
130
|
+
// Sprawdź najpierw poziom głównego loggera
|
|
131
|
+
if (!this.isLevelEnabled(level))
|
|
132
|
+
return;
|
|
133
|
+
const timestamp = new Date();
|
|
134
|
+
// Połącz metadane
|
|
135
|
+
const metaData = Object.assign(Object.assign({}, (this.defaultMeta || {})), (meta || {}));
|
|
136
|
+
// Stwórz podstawowy obiekt LogInfo
|
|
137
|
+
const logEntry = Object.assign({ level, message, timestamp }, metaData);
|
|
138
|
+
// Przekaż do przetworzenia i wysłania
|
|
139
|
+
this.processAndTransport(logEntry);
|
|
140
|
+
}
|
|
141
|
+
// Metoda logEntry (dla przekazywania gotowych obiektów)
|
|
142
|
+
logEntry(entry) {
|
|
143
|
+
const { level, message, timestamp: inputTimestamp } = entry, rest = __rest(entry, ["level", "message", "timestamp"]);
|
|
144
|
+
// Sprawdź poziom głównego loggera
|
|
145
|
+
if (!this.isLevelEnabled(level))
|
|
146
|
+
return;
|
|
147
|
+
const timestamp = inputTimestamp instanceof Date ? inputTimestamp : new Date();
|
|
148
|
+
// Połącz metadane
|
|
149
|
+
const metaData = Object.assign(Object.assign({}, (this.defaultMeta || {})), rest);
|
|
150
|
+
// Stwórz obiekt LogInfo
|
|
151
|
+
const logEntry = Object.assign({ level, message, timestamp }, metaData);
|
|
152
|
+
// Przekaż do przetworzenia i wysłania
|
|
153
|
+
this.processAndTransport(logEntry);
|
|
154
|
+
}
|
|
155
|
+
// Metoda sprawdzająca poziom głównego loggera
|
|
156
|
+
isLevelEnabled(level) {
|
|
157
|
+
const targetLevelValue = this.levels[level];
|
|
158
|
+
const currentLevelValue = this.levels[this.level];
|
|
159
|
+
if (targetLevelValue === undefined || currentLevelValue === undefined)
|
|
160
|
+
return false;
|
|
161
|
+
return targetLevelValue <= currentLevelValue;
|
|
162
|
+
}
|
|
163
|
+
// Metoda dodająca transport
|
|
164
|
+
addTransport(transport) {
|
|
165
|
+
this.transports.push(transport);
|
|
166
|
+
}
|
|
167
|
+
// Metoda tworząca logger potomny
|
|
168
|
+
child(childMeta) {
|
|
169
|
+
const newDefaultMeta = Object.assign(Object.assign({}, (this.defaultMeta || {})), childMeta);
|
|
170
|
+
// Tworzy nową instancję z odziedziczonymi opcjami i nowymi meta
|
|
171
|
+
const childLogger = new Scribelog(Object.assign(Object.assign({}, this.options), { transports: this.transports, defaultMeta: newDefaultMeta }));
|
|
172
|
+
return childLogger;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Metoda do logowania błędów przechwyconych przez listenery process.on.
|
|
176
|
+
* Tworzy specjalny obiekt LogInfo z metadanymi błędu.
|
|
177
|
+
*/
|
|
178
|
+
logError(eventType, error, callback) {
|
|
179
|
+
try {
|
|
180
|
+
// Stwórz podstawowy obiekt LogInfo
|
|
181
|
+
// Formater `errors()` (używany w domyślnych formatach) zajmie się rozpakowaniem 'error'
|
|
182
|
+
const logEntry = Object.assign({ level: 'error',
|
|
183
|
+
// Wiadomość teraz będzie pochodzić z format.message(), który weźmie error.message
|
|
184
|
+
message: error.message || 'Unknown error', timestamp: new Date(),
|
|
185
|
+
// Dodaj metadane specyficzne dla błędu, aby format.errors() je znalazł
|
|
186
|
+
error: error, exception: true, eventType: eventType }, (this.defaultMeta || {}));
|
|
187
|
+
// processAndTransport zastosuje odpowiedni format (np. defaultSimpleFormat),
|
|
188
|
+
// który zawiera format.errors() przetwarzający pole 'error'.
|
|
189
|
+
this.processAndTransport(logEntry);
|
|
190
|
+
}
|
|
191
|
+
catch (logErr) {
|
|
192
|
+
// Awaryjne logowanie, jeśli główny mechanizm zawiedzie
|
|
193
|
+
console.error('[scribelog] Error occurred during error logging:', logErr);
|
|
194
|
+
console.error('[scribelog] Original error was:', error);
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
// Zawsze wywołaj callback, który może zawierać logikę wyjścia
|
|
198
|
+
callback();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Usuwa listenery wyjątków dodane przez ten logger.
|
|
203
|
+
*/
|
|
204
|
+
removeExceptionHandlers() {
|
|
205
|
+
if (this.exceptionHandler) {
|
|
206
|
+
process.removeListener('uncaughtException', this.exceptionHandler);
|
|
207
|
+
this.exceptionHandler = undefined; // Wyczyść referencję
|
|
208
|
+
}
|
|
209
|
+
if (this.rejectionHandler) {
|
|
210
|
+
process.removeListener('unhandledRejection', this.rejectionHandler);
|
|
211
|
+
this.rejectionHandler = undefined; // Wyczyść referencję
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
// Metoda przetwarzająca i wysyłająca log do transportów
|
|
215
|
+
processAndTransport(logEntry) {
|
|
216
|
+
// Iteruj przez transporty
|
|
217
|
+
for (const transport of this.transports) {
|
|
218
|
+
// Sprawdź, czy poziom logu jest wystarczający dla TEGO transportu
|
|
219
|
+
if (this.isTransportLevelEnabled(transport, logEntry.level)) {
|
|
220
|
+
// Wybierz format: transportu lub domyślny loggera
|
|
221
|
+
const formatToUse = transport.format || this.format;
|
|
222
|
+
// Zastosuj format do KOPII obiektu logEntry
|
|
223
|
+
const processedOutput = formatToUse(Object.assign({}, logEntry));
|
|
224
|
+
// Wywołaj metodę log transportu
|
|
225
|
+
try {
|
|
226
|
+
transport.log(processedOutput);
|
|
227
|
+
}
|
|
228
|
+
catch (err) {
|
|
229
|
+
// Loguj błąd transportu do konsoli
|
|
230
|
+
console.error('[scribelog] Error in transport:', err);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// Metoda sprawdzająca poziom transportu
|
|
236
|
+
isTransportLevelEnabled(transport, entryLevel) {
|
|
237
|
+
const transportLevel = transport.level;
|
|
238
|
+
if (!transportLevel)
|
|
239
|
+
return true; // Jeśli transport nie ma limitu, przepuść
|
|
240
|
+
const transportLevelValue = this.levels[transportLevel];
|
|
241
|
+
const entryLevelValue = this.levels[entryLevel];
|
|
242
|
+
if (transportLevelValue === undefined || entryLevelValue === undefined)
|
|
243
|
+
return false; // Nieznany poziom
|
|
244
|
+
// Przepuść, jeśli poziom logu <= poziom transportu
|
|
245
|
+
return entryLevelValue <= transportLevelValue;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
exports.Scribelog = Scribelog;
|
|
249
|
+
// Fabryka do tworzenia loggera
|
|
250
|
+
function createLogger(options) {
|
|
251
|
+
return new Scribelog(options);
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;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+
import type { Transport, LogLevel, LogFormat } from '../types';
|
|
2
|
+
export interface ConsoleTransportOptions {
|
|
3
|
+
level?: LogLevel;
|
|
4
|
+
format?: LogFormat;
|
|
5
|
+
useStdErrLevels?: LogLevel[];
|
|
6
|
+
}
|
|
7
|
+
export declare class ConsoleTransport implements Transport {
|
|
8
|
+
level?: LogLevel;
|
|
9
|
+
format?: LogFormat;
|
|
10
|
+
private useStdErrLevels;
|
|
11
|
+
constructor(options?: ConsoleTransportOptions);
|
|
12
|
+
log(processedEntry: Record<string, any> | string): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ConsoleTransport = void 0;
|
|
40
|
+
const format = __importStar(require("../format"));
|
|
41
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
42
|
+
class ConsoleTransport {
|
|
43
|
+
constructor(options = {}) {
|
|
44
|
+
this.level = options.level;
|
|
45
|
+
this.format = options.format; // Format specyficzny dla tego transportu
|
|
46
|
+
this.useStdErrLevels = new Set(options.useStdErrLevels || ['error']);
|
|
47
|
+
}
|
|
48
|
+
log(processedEntry) {
|
|
49
|
+
let output;
|
|
50
|
+
let entryLevel = undefined;
|
|
51
|
+
// Ustal, czy używać kolorów dla fallbacku format.simple()
|
|
52
|
+
const useColors = chalk_1.default.supportsColor
|
|
53
|
+
? chalk_1.default.supportsColor.hasBasic
|
|
54
|
+
: false;
|
|
55
|
+
if (typeof processedEntry === 'string') {
|
|
56
|
+
output = processedEntry;
|
|
57
|
+
// Prosta próba odgadnięcia poziomu ze stringa
|
|
58
|
+
const upperCaseEntry = output.toUpperCase();
|
|
59
|
+
if (upperCaseEntry.includes('[ERROR]'))
|
|
60
|
+
entryLevel = 'error';
|
|
61
|
+
else if (upperCaseEntry.includes('[WARN]'))
|
|
62
|
+
entryLevel = 'warn';
|
|
63
|
+
// ...
|
|
64
|
+
}
|
|
65
|
+
else if (typeof processedEntry === 'object' && processedEntry !== null) {
|
|
66
|
+
// Odczytaj poziom z obiektu (powinien być dodany przez format.level())
|
|
67
|
+
if (processedEntry.level && typeof processedEntry.level === 'string') {
|
|
68
|
+
entryLevel = processedEntry.level;
|
|
69
|
+
}
|
|
70
|
+
// Zastosuj format.simple jako fallback do konwersji obiektu na string
|
|
71
|
+
output = format.simple({ colors: useColors })(processedEntry);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return; // Ignoruj inne typy
|
|
75
|
+
}
|
|
76
|
+
// Wybierz strumień wyjścia
|
|
77
|
+
if (entryLevel && this.useStdErrLevels.has(entryLevel)) {
|
|
78
|
+
console.error(output);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
console.log(output);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.ConsoleTransport = ConsoleTransport;
|
|
86
|
+
//# sourceMappingURL=console.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console.js","sourceRoot":"","sources":["../../src/transports/console.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,kDAAoC;AACpC,kDAA0B;AAQ1B,MAAa,gBAAgB;IAK3B,YAAY,UAAmC,EAAE;QAC/C,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,yCAAyC;QACvE,IAAI,CAAC,eAAe,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,eAAe,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IACvE,CAAC;IAED,GAAG,CAAC,cAA4C;QAC9C,IAAI,MAAc,CAAC;QACnB,IAAI,UAAU,GAAyB,SAAS,CAAC;QAEjD,0DAA0D;QAC1D,MAAM,SAAS,GAAG,eAAK,CAAC,aAAa;YACnC,CAAC,CAAC,eAAK,CAAC,aAAa,CAAC,QAAQ;YAC9B,CAAC,CAAC,KAAK,CAAC;QAEV,IAAI,OAAO,cAAc,KAAK,QAAQ,EAAE,CAAC;YACvC,MAAM,GAAG,cAAc,CAAC;YACxB,8CAA8C;YAC9C,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;YAC5C,IAAI,cAAc,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAAE,UAAU,GAAG,OAAO,CAAC;iBACxD,IAAI,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC;gBAAE,UAAU,GAAG,MAAM,CAAC;YAChE,MAAM;QACR,CAAC;aAAM,IAAI,OAAO,cAAc,KAAK,QAAQ,IAAI,cAAc,KAAK,IAAI,EAAE,CAAC;YACzE,uEAAuE;YACvE,IAAI,cAAc,CAAC,KAAK,IAAI,OAAO,cAAc,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;gBACrE,UAAU,GAAG,cAAc,CAAC,KAAiB,CAAC;YAChD,CAAC;YACD,sEAAsE;YACtE,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,cAAc,CAAW,CAAC;QAC1E,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,oBAAoB;QAC9B,CAAC;QAED,2BAA2B;QAC3B,IAAI,UAAU,IAAI,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YACvD,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;CACF;AA7CD,4CA6CC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { LogLevel as _LogLevel, LogLevels } from './levels';
|
|
2
|
+
export type LogLevel = _LogLevel;
|
|
3
|
+
export interface LogInfo {
|
|
4
|
+
level: LogLevel;
|
|
5
|
+
message: string;
|
|
6
|
+
timestamp: Date;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Funkcja formatująca. Przyjmuje obiekt (początkowo LogInfo,
|
|
11
|
+
* potem wynik poprzedniego formatera) i zwraca zmodyfikowany obiekt lub string.
|
|
12
|
+
*/
|
|
13
|
+
export type LogFormat = (info: Record<string, any>) => Record<string, any> | string;
|
|
14
|
+
export interface Transport {
|
|
15
|
+
log(processedEntry: Record<string, any> | string): void;
|
|
16
|
+
level?: LogLevel;
|
|
17
|
+
format?: LogFormat;
|
|
18
|
+
}
|
|
19
|
+
export interface LoggerOptions {
|
|
20
|
+
level?: LogLevel;
|
|
21
|
+
levels?: LogLevels;
|
|
22
|
+
format?: LogFormat;
|
|
23
|
+
transports?: Transport[];
|
|
24
|
+
defaultMeta?: Record<string, any>;
|
|
25
|
+
/** Czy logger ma przechwytywać i logować nieobsłużone wyjątki. Domyślnie: false */
|
|
26
|
+
handleExceptions?: boolean;
|
|
27
|
+
/** Czy logger ma przechwytywać i logować nieobsłużone odrzucenia promisów. Domyślnie: false */
|
|
28
|
+
handleRejections?: boolean;
|
|
29
|
+
/** Czy zakończyć proces po nieobsłużonym wyjątku/odrzuceniu (jeśli handleExceptions/handleRejections jest true). Domyślnie: true */
|
|
30
|
+
exitOnError?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export type LoggerInterface = {
|
|
33
|
+
logEntry(entry: Omit<LogInfo, 'timestamp'> & {
|
|
34
|
+
timestamp?: Date;
|
|
35
|
+
}): void;
|
|
36
|
+
log(level: LogLevel, message: string, meta?: Record<string, any>): void;
|
|
37
|
+
error(message: string, meta?: Record<string, any>): void;
|
|
38
|
+
warn(message: string, meta?: Record<string, any>): void;
|
|
39
|
+
info(message: string, meta?: Record<string, any>): void;
|
|
40
|
+
http(message: string, meta?: Record<string, any>): void;
|
|
41
|
+
verbose(message: string, meta?: Record<string, any>): void;
|
|
42
|
+
debug(message: string, meta?: Record<string, any>): void;
|
|
43
|
+
silly(message: string, meta?: Record<string, any>): void;
|
|
44
|
+
level: LogLevel;
|
|
45
|
+
levels: LogLevels;
|
|
46
|
+
isLevelEnabled(level: LogLevel): boolean;
|
|
47
|
+
addTransport(transport: Transport): void;
|
|
48
|
+
/**
|
|
49
|
+
* Tworzy nowy logger potomny.
|
|
50
|
+
* @param defaultMeta - Obiekt z domyślnymi metadanymi dla loggera potomnego.
|
|
51
|
+
*/
|
|
52
|
+
child(defaultMeta: Record<string, any>): LoggerInterface;
|
|
53
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/utils.d.ts
ADDED
package/dist/utils.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// src/utils.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports._internalExit = _internalExit;
|
|
5
|
+
/**
|
|
6
|
+
* Wewnętrzna funkcja do kończenia procesu.
|
|
7
|
+
* Umożliwia mockowanie w testach.
|
|
8
|
+
* @param code - Kod wyjścia (domyślnie 1).
|
|
9
|
+
*/
|
|
10
|
+
function _internalExit(code = 1) {
|
|
11
|
+
// Daj krótki czas transportom asynchronicznym na zapisanie logów
|
|
12
|
+
// To nadal jest uproszczenie.
|
|
13
|
+
setTimeout(() => {
|
|
14
|
+
process.exit(code);
|
|
15
|
+
}, 500).unref(); // unref(), aby nie blokować normalnego zamykania, jeśli nic innego nie działa
|
|
16
|
+
// Aby zadowolić typ 'never', rzucamy błędem, chociaż proces powinien się zakończyć wcześniej.
|
|
17
|
+
// W praktyce ten kod nie powinien zostać osiągnięty.
|
|
18
|
+
throw new Error(`Exiting with code ${code}`);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";AAAA,eAAe;;AAOf,sCAUC;AAfD;;;;GAIG;AACH,SAAgB,aAAa,CAAC,OAAe,CAAC;IAC5C,iEAAiE;IACjE,8BAA8B;IAC9B,UAAU,CAAC,GAAG,EAAE;QACd,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,8EAA8E;IAE/F,8FAA8F;IAC9F,qDAAqD;IACrD,MAAM,IAAI,KAAK,CAAC,qBAAqB,IAAI,EAAE,CAAC,CAAC;AAC/C,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "scribelog",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "An advanced, configurable logger for Node.js applications.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md",
|
|
10
|
+
"LICENSE"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc",
|
|
14
|
+
"lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
15
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
|
16
|
+
"test": "jest",
|
|
17
|
+
"clean": "rimraf dist",
|
|
18
|
+
"prepublishOnly": "npm run clean && npm test && npm run lint && npm run build"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [
|
|
21
|
+
"log",
|
|
22
|
+
"logs",
|
|
23
|
+
"logger",
|
|
24
|
+
"logging",
|
|
25
|
+
"typescript",
|
|
26
|
+
"node",
|
|
27
|
+
"nodejs",
|
|
28
|
+
"console",
|
|
29
|
+
"format",
|
|
30
|
+
"error",
|
|
31
|
+
"exception",
|
|
32
|
+
"scribe",
|
|
33
|
+
"scribelog"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"author": "tolongames",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@types/jest": "^29.5.12",
|
|
42
|
+
"@types/node": "^20.11.24",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^7.1.1",
|
|
44
|
+
"@typescript-eslint/parser": "^7.1.1",
|
|
45
|
+
"eslint": "^8.57.0",
|
|
46
|
+
"eslint-config-prettier": "^9.1.0",
|
|
47
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
48
|
+
"jest": "^29.7.0",
|
|
49
|
+
"prettier": "^3.2.5",
|
|
50
|
+
"rimraf": "^6.0.1",
|
|
51
|
+
"ts-jest": "^29.1.2",
|
|
52
|
+
"typescript": "^5.3.3"
|
|
53
|
+
},
|
|
54
|
+
"repository": {
|
|
55
|
+
"type": "git",
|
|
56
|
+
"url": "git+https://github.com/tolongames/scribelog.git"
|
|
57
|
+
},
|
|
58
|
+
"bugs": {
|
|
59
|
+
"url": "https://github.com/tolongames/scribelog/issues"
|
|
60
|
+
},
|
|
61
|
+
"homepage": "https://github.com/tolongames/scribelog#readme",
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=16.0.0"
|
|
64
|
+
},
|
|
65
|
+
"dependencies": {
|
|
66
|
+
"chalk": "^4.1.2",
|
|
67
|
+
"date-fns": "^2.30.0"
|
|
68
|
+
}
|
|
69
|
+
}
|