@vingitonga/elysia-winston-logger 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +108 -6
  2. package/package.json +14 -1
package/README.md CHANGED
@@ -1,15 +1,117 @@
1
- # elysia-winston-logger
1
+ # @vingitonga/elysia-winston-logger
2
2
 
3
- To install dependencies:
3
+ A flexible, beautifully formatted Winston logging plugin for ElysiaJS applications
4
+
5
+ This package provides a ready-to-use logger with gorgeous console formatting (powered by Winston), automatic request logging, and the ability to inject your own custom Winston instances.
6
+
7
+ # Installation
8
+
9
+ Since Elysia is built for Bun, the recommended way to install is via Bun:
4
10
 
5
11
  ```bash
6
- bun install
12
+ bun add @vingitonga/elysia-winston-logger
7
13
  ```
8
14
 
9
- To run:
15
+ You can also use npm, pnpm, or yarn:
10
16
 
11
17
  ```bash
12
- bun run index.ts
18
+ npm install @vingitonga/elysia-winston-logger
13
19
  ```
14
20
 
15
- This project was created using `bun init` in bun v1.3.11. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
21
+ # Usage
22
+
23
+ ## Basic Usage (Zero Config)
24
+
25
+ Out of the box, the plugin provides a beautifully formatted console logger that handles objects, errors, and metadata gracefully. Simply import winstonLogger and register it as an Elysia plugin.
26
+
27
+ ```ts
28
+ import { Elysia } from "elysia";
29
+ import { winstonLogger } from "@vingitonga/elysia-winston-logger";
30
+
31
+ const app = new Elysia()
32
+ // 1. Register the plugin
33
+ .use(winstonLogger())
34
+
35
+ // 2. Access the logger from the route context
36
+ .get("/", ({ log }) => {
37
+ log.info("Processing root request...");
38
+
39
+ // Objects and errors are automatically pretty-printed!
40
+ log.error(new Error("Example error formatting"));
41
+ log.debug({ user: "Alice", role: "Admin" });
42
+
43
+ return "Check your console!";
44
+ })
45
+ .listen(3000);
46
+
47
+ console.log(
48
+ `🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`,
49
+ );
50
+ ```
51
+
52
+ ## Advanced Configuration
53
+
54
+ You can customize the log level and format, or even pass in your own completely custom Winston instance.
55
+
56
+ ```ts
57
+ import { Elysia } from "elysia";
58
+ import { createLogger, transports } from "winston";
59
+ import { winstonLogger, LogFormat } from "@vingitonga/elysia-winston-logger";
60
+
61
+ // Option A: Tweak the built-in logger's settings
62
+ const app1 = new Elysia().use(
63
+ winstonLogger(undefined, {
64
+ level: "debug",
65
+ format: LogFormat.JSON,
66
+ }),
67
+ );
68
+
69
+ // Option B: Pass your own completely custom Winston logger
70
+ const myCustomLogger = createLogger({
71
+ level: "warn",
72
+ transports: [
73
+ new transports.File({ filename: "error.log", level: "error" }),
74
+ new transports.Console(),
75
+ ],
76
+ });
77
+
78
+ const app2 = new Elysia().use(winstonLogger(myCustomLogger));
79
+ ```
80
+
81
+ # API Reference
82
+
83
+ ## winstonLogger(customLogger?, options?)
84
+
85
+ The main plugin factory function.
86
+
87
+ - `customLogger` (Optional): A custom winston.Logger instance. If omitted, it falls back to the beautifully formatted defaultLogger.
88
+
89
+ - `options` (Optional): Configuration object.
90
+
91
+ - level (string): The minimum level to log (e.g., 'info', 'debug', 'error'). Defaults to Bun.env.LOG_LEVEL or 'info'.
92
+
93
+ - format: The output format. Accepts values defined in the LogFormat object.
94
+
95
+ ## Context Injection (log)
96
+
97
+ Once registered, the logger is injected into the Elysia context as log.
98
+
99
+ ```ts
100
+ app.post("/users", ({ log, body }) => {
101
+ log.info("Received body:", body);
102
+ });
103
+ ```
104
+
105
+ ## defaultLogger
106
+
107
+ The raw Winston instance used by the plugin under the hood. Exported in case you need to use the exact same logger instance outside of the Elysia request lifecycle (e.g., in background jobs, database connection files, or setup scripts).
108
+
109
+ ```ts
110
+ import { defaultLogger } from "@vingitonga/elysia-winston-logger";
111
+
112
+ defaultLogger.info("Database connected successfully!");
113
+ ```
114
+
115
+ # License
116
+
117
+ ## MIT
package/package.json CHANGED
@@ -1,7 +1,20 @@
1
1
  {
2
2
  "name": "@vingitonga/elysia-winston-logger",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
+ "publishConfig": {
5
+ "registry": "https://registry.npmjs.org/",
6
+ "access": "public"
7
+ },
4
8
  "description": "Winston logger plugin for Elysia",
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/VinGitonga/elysia-winston-logger.git"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/VinGitonga/elysia-winston-logger/issues"
16
+ },
17
+ "homepage": "https://github.com/VinGitonga/elysia-winston-logger#readme",
5
18
  "main": "./dist/index.js",
6
19
  "module": "./dist/index.js",
7
20
  "types": "./dist/index.d.ts",