@logtape/adaptor-winston 1.0.0-dev.257
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 +20 -0
- package/README.md +218 -0
- package/deno.json +40 -0
- package/dist/_virtual/rolldown_runtime.cjs +30 -0
- package/dist/install.cjs +6 -0
- package/dist/install.d.cts +1 -0
- package/dist/install.d.ts +1 -0
- package/dist/install.js +7 -0
- package/dist/install.js.map +1 -0
- package/dist/mod.cjs +120 -0
- package/dist/mod.d.cts +300 -0
- package/dist/mod.d.cts.map +1 -0
- package/dist/mod.d.ts +300 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +119 -0
- package/dist/mod.js.map +1 -0
- package/install.ts +87 -0
- package/mod.test.ts +415 -0
- package/mod.ts +453 -0
- package/package.json +79 -0
- package/tsdown.config.ts +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright 2024 Hong Minhee
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
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, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
<!-- deno-fmt-ignore-file -->
|
|
2
|
+
|
|
3
|
+
@logtape/adaptor-winston
|
|
4
|
+
========================
|
|
5
|
+
|
|
6
|
+
[![JSR][JSR badge]][JSR]
|
|
7
|
+
[![npm][npm badge]][npm]
|
|
8
|
+
|
|
9
|
+
*@logtape/adaptor-winston* is a [LogTape] adapter that forwards log records to
|
|
10
|
+
[winston] loggers, enabling seamless integration between LogTape-enabled libraries
|
|
11
|
+
and applications using winston for logging infrastructure.
|
|
12
|
+
|
|
13
|
+
[JSR]: https://jsr.io/@logtape/adaptor-winston
|
|
14
|
+
[JSR badge]: https://jsr.io/badges/@logtape/adaptor-winston
|
|
15
|
+
[npm]: https://www.npmjs.com/package/@logtape/adaptor-winston
|
|
16
|
+
[npm badge]: https://img.shields.io/npm/v/@logtape/adaptor-winston?logo=npm
|
|
17
|
+
[LogTape]: https://logtape.org/
|
|
18
|
+
[winston]: https://github.com/winstonjs/winston
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
Installation
|
|
22
|
+
------------
|
|
23
|
+
|
|
24
|
+
~~~~ sh
|
|
25
|
+
deno add jsr:@logtape/adaptor-winston # for Deno
|
|
26
|
+
npm add @logtape/adaptor-winston # for npm
|
|
27
|
+
pnpm add @logtape/adaptor-winston # for pnpm
|
|
28
|
+
yarn add @logtape/adaptor-winston # for Yarn
|
|
29
|
+
bun add @logtape/adaptor-winston # for Bun
|
|
30
|
+
~~~~
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
Quick start
|
|
34
|
+
-----------
|
|
35
|
+
|
|
36
|
+
The simplest way to integrate LogTape with winston is to import the auto-installer:
|
|
37
|
+
|
|
38
|
+
~~~~ typescript
|
|
39
|
+
import "@logtape/adaptor-winston/install";
|
|
40
|
+
|
|
41
|
+
// That's it! All LogTape logs will now be routed to winston's default logger
|
|
42
|
+
import { getLogger } from "@logtape/logtape";
|
|
43
|
+
const logger = getLogger("my-app");
|
|
44
|
+
logger.info("This will be logged through winston");
|
|
45
|
+
~~~~
|
|
46
|
+
|
|
47
|
+
You can also use it with Node.js's `-r` flag:
|
|
48
|
+
|
|
49
|
+
~~~~ sh
|
|
50
|
+
node -r @logtape/adaptor-winston/install app.js
|
|
51
|
+
~~~~
|
|
52
|
+
|
|
53
|
+
For custom winston loggers or configuration options, see the [Usage](#usage) section below.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
Usage
|
|
57
|
+
-----
|
|
58
|
+
|
|
59
|
+
### Using the install() function
|
|
60
|
+
|
|
61
|
+
If you need a custom winston logger or configuration options, you can use
|
|
62
|
+
the `install()` function:
|
|
63
|
+
|
|
64
|
+
~~~~ typescript
|
|
65
|
+
import winston from "winston";
|
|
66
|
+
import { install } from "@logtape/adaptor-winston";
|
|
67
|
+
|
|
68
|
+
// With a custom winston logger
|
|
69
|
+
const customLogger = winston.createLogger({
|
|
70
|
+
level: "info",
|
|
71
|
+
format: winston.format.combine(
|
|
72
|
+
winston.format.timestamp(),
|
|
73
|
+
winston.format.json()
|
|
74
|
+
),
|
|
75
|
+
transports: [
|
|
76
|
+
new winston.transports.Console(),
|
|
77
|
+
new winston.transports.File({ filename: "app.log" })
|
|
78
|
+
]
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
install(customLogger);
|
|
82
|
+
~~~~
|
|
83
|
+
|
|
84
|
+
You can also pass configuration options:
|
|
85
|
+
|
|
86
|
+
~~~~ typescript
|
|
87
|
+
import { install } from "@logtape/adaptor-winston";
|
|
88
|
+
|
|
89
|
+
// With default winston logger but custom options
|
|
90
|
+
install({
|
|
91
|
+
category: {
|
|
92
|
+
position: "start",
|
|
93
|
+
decorator: "[]",
|
|
94
|
+
separator: "."
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Or with both custom logger and options
|
|
99
|
+
install(customLogger, {
|
|
100
|
+
category: { position: "start", decorator: "[]" }
|
|
101
|
+
});
|
|
102
|
+
~~~~
|
|
103
|
+
|
|
104
|
+
### Manual configuration
|
|
105
|
+
|
|
106
|
+
For full control over the winston integration, configure LogTape manually:
|
|
107
|
+
|
|
108
|
+
~~~~ typescript
|
|
109
|
+
import { configure } from "@logtape/logtape";
|
|
110
|
+
import { getWinstonSink } from "@logtape/adaptor-winston";
|
|
111
|
+
import winston from "winston";
|
|
112
|
+
|
|
113
|
+
const winstonLogger = winston.createLogger({
|
|
114
|
+
level: "info",
|
|
115
|
+
format: winston.format.combine(
|
|
116
|
+
winston.format.timestamp(),
|
|
117
|
+
winston.format.json()
|
|
118
|
+
),
|
|
119
|
+
transports: [
|
|
120
|
+
new winston.transports.Console(),
|
|
121
|
+
new winston.transports.File({ filename: "app.log" })
|
|
122
|
+
]
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
await configure({
|
|
126
|
+
sinks: {
|
|
127
|
+
winston: getWinstonSink(winstonLogger, {
|
|
128
|
+
category: {
|
|
129
|
+
position: "start",
|
|
130
|
+
decorator: "[]",
|
|
131
|
+
separator: "."
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
},
|
|
135
|
+
loggers: [
|
|
136
|
+
{ category: "my-library", sinks: ["winston"] }
|
|
137
|
+
]
|
|
138
|
+
});
|
|
139
|
+
~~~~
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
Level mapping
|
|
143
|
+
-------------
|
|
144
|
+
|
|
145
|
+
LogTape log levels are mapped to winston levels as follows:
|
|
146
|
+
|
|
147
|
+
| LogTape Level | winston Level |
|
|
148
|
+
|---------------|---------------|
|
|
149
|
+
| `trace` | `silly` |
|
|
150
|
+
| `debug` | `debug` |
|
|
151
|
+
| `info` | `info` |
|
|
152
|
+
| `warning` | `warn` |
|
|
153
|
+
| `error` | `error` |
|
|
154
|
+
| `fatal` | `error` |
|
|
155
|
+
|
|
156
|
+
You can customize this mapping:
|
|
157
|
+
|
|
158
|
+
~~~~ typescript
|
|
159
|
+
import { install } from "@logtape/adaptor-winston";
|
|
160
|
+
|
|
161
|
+
install({
|
|
162
|
+
levelsMap: {
|
|
163
|
+
"trace": "debug", // Map trace to debug instead of silly
|
|
164
|
+
"debug": "debug",
|
|
165
|
+
"info": "info",
|
|
166
|
+
"warning": "warn",
|
|
167
|
+
"error": "error",
|
|
168
|
+
"fatal": "error"
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
~~~~
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
Category formatting
|
|
175
|
+
-------------------
|
|
176
|
+
|
|
177
|
+
The adapter supports flexible category formatting options:
|
|
178
|
+
|
|
179
|
+
~~~~typescript
|
|
180
|
+
import { install } from "@logtape/adaptor-winston";
|
|
181
|
+
|
|
182
|
+
// Hide categories completely
|
|
183
|
+
install({ category: false });
|
|
184
|
+
|
|
185
|
+
// Use default formatting (category with ":" separator)
|
|
186
|
+
install({ category: true });
|
|
187
|
+
|
|
188
|
+
// Custom formatting
|
|
189
|
+
install({
|
|
190
|
+
category: {
|
|
191
|
+
position: "end", // "start" or "end"
|
|
192
|
+
decorator: "[]", // "[]", "()", "<>", "{}", ":", "-", "|", "/", ""
|
|
193
|
+
separator: "::" // custom separator for multi-part categories
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
~~~~
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
Value formatting
|
|
200
|
+
----------------
|
|
201
|
+
|
|
202
|
+
Customize how interpolated values are formatted in log messages:
|
|
203
|
+
|
|
204
|
+
~~~~ typescript
|
|
205
|
+
import { install } from "@logtape/adaptor-winston";
|
|
206
|
+
|
|
207
|
+
install({
|
|
208
|
+
valueFormatter: (value) => JSON.stringify(value, null, 2)
|
|
209
|
+
});
|
|
210
|
+
~~~~
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
Docs
|
|
214
|
+
----
|
|
215
|
+
|
|
216
|
+
See the [API reference] on JSR for further details.
|
|
217
|
+
|
|
218
|
+
[API reference]: https://jsr.io/@logtape/adaptor-winston/doc
|
package/deno.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@logtape/adaptor-winston",
|
|
3
|
+
"version": "1.0.0-dev.257+f86501ac",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./mod.ts",
|
|
7
|
+
"./install": "./install.ts"
|
|
8
|
+
},
|
|
9
|
+
"imports": {
|
|
10
|
+
"winston": "npm:winston@^3.17.0"
|
|
11
|
+
},
|
|
12
|
+
"exclude": [
|
|
13
|
+
"coverage/",
|
|
14
|
+
"npm/",
|
|
15
|
+
".dnt-import-map.json"
|
|
16
|
+
],
|
|
17
|
+
"tasks": {
|
|
18
|
+
"build": "pnpm build",
|
|
19
|
+
"test": "deno test --allow-env",
|
|
20
|
+
"test:node": {
|
|
21
|
+
"dependencies": [
|
|
22
|
+
"build"
|
|
23
|
+
],
|
|
24
|
+
"command": "node --experimental-transform-types --test"
|
|
25
|
+
},
|
|
26
|
+
"test:bun": {
|
|
27
|
+
"dependencies": [
|
|
28
|
+
"build"
|
|
29
|
+
],
|
|
30
|
+
"command": "bun test"
|
|
31
|
+
},
|
|
32
|
+
"test-all": {
|
|
33
|
+
"dependencies": [
|
|
34
|
+
"test",
|
|
35
|
+
"test:node",
|
|
36
|
+
"test:bun"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
|
|
25
|
+
Object.defineProperty(exports, '__toESM', {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return __toESM;
|
|
29
|
+
}
|
|
30
|
+
});
|
package/dist/install.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/install.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.js","names":[],"sources":["../install.ts"],"sourcesContent":["/**\n * Auto-installation module for @logtape/adaptor-winston.\n *\n * This module automatically configures LogTape to route all log records\n * to winston's default logger when imported. This provides the simplest\n * possible integration - just import this module and all LogTape-enabled\n * libraries will immediately start logging through winston.\n *\n * @example Automatic installation via import\n * ```typescript\n * // Simply import this module to automatically set up winston adapter\n * import \"@logtape/adaptor-winston/install\";\n *\n * // Now all LogTape logs will be routed to winston's default logger\n * import { getLogger } from \"@logtape/logtape\";\n * const logger = getLogger(\"my-app\");\n * logger.info(\"This will be logged through winston\");\n * ```\n *\n * @example Usage in package.json scripts\n * ```json\n * {\n * \"scripts\": {\n * \"start\": \"node -r @logtape/adaptor-winston/install app.js\"\n * }\n * }\n * ```\n *\n * @example Usage with module bundlers\n * ```typescript\n * // webpack.config.js or similar\n * module.exports = {\n * entry: [\n * '@logtape/adaptor-winston/install',\n * './src/index.js'\n * ]\n * };\n * ```\n *\n * > [!NOTE]\n * > This module uses winston's default logger with default configuration.\n * > If you need a custom winston logger or configuration options (category\n * > formatting, level mapping, etc.), use the `install()` function from the\n * > main module instead:\n *\n * @example Custom winston logger\n * ```typescript\n * import winston from \"winston\";\n * import { install } from \"@logtape/adaptor-winston\";\n *\n * const customLogger = winston.createLogger({\n * transports: [new winston.transports.File({ filename: \"app.log\" })]\n * });\n *\n * install(customLogger);\n * ```\n *\n * @example Custom configuration options\n * ```typescript\n * import { install } from \"@logtape/adaptor-winston\";\n *\n * install({\n * category: { position: \"start\", decorator: \"[]\" }\n * });\n * ```\n *\n * @example Custom logger with custom options\n * ```typescript\n * import winston from \"winston\";\n * import { install } from \"@logtape/adaptor-winston\";\n *\n * const customLogger = winston.createLogger({\n * transports: [new winston.transports.Console()]\n * });\n *\n * install(customLogger, {\n * category: { position: \"start\", decorator: \"[]\" }\n * });\n * ```\n *\n * @module\n * @since 1.0.0\n */\n\nimport { install } from \"./mod.ts\";\n\ninstall();\n"],"mappings":";;;AAsFA,SAAS"}
|
package/dist/mod.cjs
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const __logtape_logtape = require_rolldown_runtime.__toESM(require("@logtape/logtape"));
|
|
3
|
+
const winston = require_rolldown_runtime.__toESM(require("winston"));
|
|
4
|
+
const node_util = require_rolldown_runtime.__toESM(require("node:util"));
|
|
5
|
+
|
|
6
|
+
//#region mod.ts
|
|
7
|
+
const DEFAULT_LEVELS_MAP = {
|
|
8
|
+
"trace": "silly",
|
|
9
|
+
"debug": "debug",
|
|
10
|
+
"info": "info",
|
|
11
|
+
"warning": "warn",
|
|
12
|
+
"error": "error",
|
|
13
|
+
"fatal": "error"
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Creates a LogTape sink that forwards log records to a winston logger.
|
|
17
|
+
*
|
|
18
|
+
* This function creates a sink function that can be used with LogTape's
|
|
19
|
+
* configuration system. The sink will format LogTape log records and
|
|
20
|
+
* forward them to the provided winston logger instance.
|
|
21
|
+
*
|
|
22
|
+
* @example Basic usage
|
|
23
|
+
* ```typescript
|
|
24
|
+
* import winston from "winston";
|
|
25
|
+
* import { configure } from "@logtape/logtape";
|
|
26
|
+
* import { getWinstonSink } from "@logtape/adaptor-winston";
|
|
27
|
+
*
|
|
28
|
+
* const winstonLogger = winston.createLogger({
|
|
29
|
+
* level: "info",
|
|
30
|
+
* format: winston.format.combine(
|
|
31
|
+
* winston.format.timestamp(),
|
|
32
|
+
* winston.format.json()
|
|
33
|
+
* ),
|
|
34
|
+
* transports: [new winston.transports.Console()]
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* await configure({
|
|
38
|
+
* sinks: {
|
|
39
|
+
* winston: getWinstonSink(winstonLogger)
|
|
40
|
+
* },
|
|
41
|
+
* loggers: [
|
|
42
|
+
* { category: ["myapp"], sinks: ["winston"] }
|
|
43
|
+
* ]
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @example With custom options
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const sink = getWinstonSink(winstonLogger, {
|
|
50
|
+
* category: {
|
|
51
|
+
* separator: ".",
|
|
52
|
+
* position: "start",
|
|
53
|
+
* decorator: "[]"
|
|
54
|
+
* },
|
|
55
|
+
* levelsMap: {
|
|
56
|
+
* "trace": "debug", // Map trace to debug instead of silly
|
|
57
|
+
* "debug": "debug",
|
|
58
|
+
* "info": "info",
|
|
59
|
+
* "warning": "warn",
|
|
60
|
+
* "error": "error",
|
|
61
|
+
* "fatal": "error"
|
|
62
|
+
* }
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* @param logger The winston logger instance to forward logs to. Must implement
|
|
67
|
+
* the Logger interface with error, warn, info, http, verbose,
|
|
68
|
+
* debug, and silly methods.
|
|
69
|
+
* @param options Configuration options for the sink behavior.
|
|
70
|
+
* @returns A sink function that can be used with LogTape's configure() function.
|
|
71
|
+
* @since 1.0.0
|
|
72
|
+
*/
|
|
73
|
+
function getWinstonSink(logger, options = {}) {
|
|
74
|
+
const { levelsMap = DEFAULT_LEVELS_MAP, valueFormatter = node_util.inspect } = options;
|
|
75
|
+
const categoryOptions = !options.category ? void 0 : typeof options.category === "object" ? options.category : {};
|
|
76
|
+
const category = categoryOptions == null ? void 0 : {
|
|
77
|
+
separator: categoryOptions.separator ?? "·",
|
|
78
|
+
position: categoryOptions.position ?? "start",
|
|
79
|
+
decorator: categoryOptions.decorator ?? ":"
|
|
80
|
+
};
|
|
81
|
+
return (record) => {
|
|
82
|
+
const level = levelsMap[record.level];
|
|
83
|
+
let message = "";
|
|
84
|
+
if (category?.position === "start" && record.category.length > 0) {
|
|
85
|
+
const joinedCategory = record.category.join(category.separator);
|
|
86
|
+
message += category.decorator === "[]" ? `[${joinedCategory}] ` : category.decorator === "()" ? `(${joinedCategory}) ` : category.decorator === "<>" ? `<${joinedCategory}> ` : category.decorator === "{}" ? `{${joinedCategory}} ` : category.decorator === ":" ? `${joinedCategory}: ` : category.decorator === "-" ? `${joinedCategory} - ` : category.decorator === "|" ? `${joinedCategory} | ` : category.decorator === "/" ? `${joinedCategory} / ` : `${joinedCategory} `;
|
|
87
|
+
}
|
|
88
|
+
for (let i = 0; i < record.message.length; i += 2) {
|
|
89
|
+
message += record.message[i];
|
|
90
|
+
if (i + 1 < record.message.length) message += valueFormatter(record.message[i + 1]);
|
|
91
|
+
}
|
|
92
|
+
if (category?.position === "end" && record.category.length > 0) {
|
|
93
|
+
const joinedCategory = record.category.join(category.separator);
|
|
94
|
+
message += category.decorator === "[]" ? ` [${joinedCategory}]` : category.decorator === "()" ? ` (${joinedCategory})` : category.decorator === "<>" ? ` <${joinedCategory}>` : category.decorator === "{}" ? ` {${joinedCategory}}` : category.decorator === ":" ? `: ${joinedCategory}` : category.decorator === "-" ? ` - ${joinedCategory}` : category.decorator === "|" ? ` | ${joinedCategory}` : category.decorator === "/" ? ` / ${joinedCategory}` : ` ${joinedCategory}`;
|
|
95
|
+
}
|
|
96
|
+
logger[level](message, record.properties);
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function install(loggerOrOptions, options = {}) {
|
|
100
|
+
let logger;
|
|
101
|
+
let sinkOptions;
|
|
102
|
+
if (loggerOrOptions && ("error" in loggerOrOptions || "info" in loggerOrOptions)) {
|
|
103
|
+
logger = loggerOrOptions;
|
|
104
|
+
sinkOptions = options;
|
|
105
|
+
} else {
|
|
106
|
+
logger = winston.default;
|
|
107
|
+
sinkOptions = loggerOrOptions || {};
|
|
108
|
+
}
|
|
109
|
+
(0, __logtape_logtape.configureSync)({
|
|
110
|
+
sinks: { winston: getWinstonSink(logger, sinkOptions) },
|
|
111
|
+
loggers: [{
|
|
112
|
+
category: [],
|
|
113
|
+
sinks: ["winston"]
|
|
114
|
+
}]
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
exports.getWinstonSink = getWinstonSink;
|
|
120
|
+
exports.install = install;
|