@wlix/logger 1.0.0 → 1.0.2
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 +19 -11
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,23 +4,31 @@ A tiny file-based logger for Node.js projects. It writes logs to daily files and
|
|
|
4
4
|
|
|
5
5
|
## How it works
|
|
6
6
|
|
|
7
|
-
- When you create a
|
|
8
|
-
- Each day gets its own log file named `DD-MM-YYYY.log`.
|
|
9
|
-
- Every log line
|
|
10
|
-
- Logs are then written to the file
|
|
7
|
+
- When you create a logger instance, it makes sure the logs directory exists.
|
|
8
|
+
- Each calendar day gets its own log file named `DD-MM-YYYY.log`.
|
|
9
|
+
- Every log line has UTC time (or UTC offset), log type (info, warn, or error), and message.
|
|
10
|
+
- Logs are then written to the appropriate log file.
|
|
11
11
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
|
-
-
|
|
15
|
-
- Use `
|
|
14
|
+
- Use `createLogger()` to create a new logger.
|
|
15
|
+
- Use the returned function with `"info" | "warn" | "error"` and your message.
|
|
16
16
|
- Files are written to the `./logs` dir by default.
|
|
17
17
|
|
|
18
18
|
```ts
|
|
19
|
-
import {
|
|
19
|
+
import { createLogger } from "./Logger";
|
|
20
20
|
|
|
21
|
-
const logger =
|
|
21
|
+
const logger = createLogger();
|
|
22
22
|
|
|
23
|
-
logger
|
|
24
|
-
logger
|
|
25
|
-
logger
|
|
23
|
+
logger("info", "Connected to server");
|
|
24
|
+
logger("warn", "Memory is low");
|
|
25
|
+
logger("error", "Something went wrong");
|
|
26
26
|
```
|
|
27
|
+
|
|
28
|
+
## Configuration
|
|
29
|
+
|
|
30
|
+
| Option | Type | Default | Description |
|
|
31
|
+
| ------------- | ----------------------- | ---------- | ---------------------------------------------------------------- |
|
|
32
|
+
| `logsPath` | `string` | `"./logs"` | Path of the directory where log files are stored |
|
|
33
|
+
| `logToStdout` | `boolean` | `true` | Whether to print logs to the console |
|
|
34
|
+
| `timezone` | `"UTC"` \| `UTC±number` | `"UTC"` | Timezone for log timestamps, e.g., `"UTC"`, `"UTC+3"`, `"UTC-6"` |
|
package/index.d.ts
CHANGED
|
@@ -28,6 +28,6 @@ export interface LoggerConfig {
|
|
|
28
28
|
* @param config Optional logger configuration.
|
|
29
29
|
* @returns A function to log messages: log(type, message)
|
|
30
30
|
*/
|
|
31
|
-
export declare function
|
|
31
|
+
export declare function createLogger(
|
|
32
32
|
config?: LoggerConfig
|
|
33
33
|
): (type: "info" | "warn" | "error", message: string) => void;
|
package/index.js
CHANGED
|
@@ -14,7 +14,7 @@ const { join } = require("path");
|
|
|
14
14
|
* @param {LoggerConfig} config Optional logger configuration.
|
|
15
15
|
* @returns {(type: "info" | "warn" | "error", message: string) => void} Function to log messages
|
|
16
16
|
*/
|
|
17
|
-
function
|
|
17
|
+
function createLogger(config = {}) {
|
|
18
18
|
const logsPath = config.logsPath ?? "./logs";
|
|
19
19
|
const logToStdout = config.logToStdout ?? true;
|
|
20
20
|
const timezone = config.timezone ?? "UTC";
|
|
@@ -73,4 +73,4 @@ function Logger(config = {}) {
|
|
|
73
73
|
return log;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
module.exports = { Logger };
|
|
76
|
+
module.exports = { Logger: createLogger };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wlix/logger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A simple logger.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"access": "public"
|
|
15
15
|
},
|
|
16
16
|
"author": "wlix",
|
|
17
|
-
"license": "
|
|
17
|
+
"license": "MIT",
|
|
18
18
|
"scripts": {
|
|
19
19
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
20
20
|
}
|