@mihari/logger-winston 0.1.0 → 0.2.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/dist/index.d.mts +41 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.js +85 -79
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +33 -9
- package/dist/index.d.ts.map +0 -1
- package/src/index.ts +0 -97
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import Transport from 'winston-transport';
|
|
2
|
+
import { MihariConfig } from '@mihari/logger-types';
|
|
3
|
+
|
|
4
|
+
interface WinstonLogInfo {
|
|
5
|
+
level: string;
|
|
6
|
+
message: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
interface MihariWinstonOptions extends Transport.TransportStreamOptions {
|
|
10
|
+
readonly mihariConfig: MihariConfig;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Winston transport that forwards logs to mihari.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import winston from "winston";
|
|
18
|
+
* import { MihariWinstonTransport } from "@mihari/logger-winston";
|
|
19
|
+
*
|
|
20
|
+
* const logger = winston.createLogger({
|
|
21
|
+
* transports: [
|
|
22
|
+
* new MihariWinstonTransport({
|
|
23
|
+
* mihariConfig: {
|
|
24
|
+
* token: "your-token",
|
|
25
|
+
* endpoint: "https://logs.example.com",
|
|
26
|
+
* },
|
|
27
|
+
* }),
|
|
28
|
+
* ],
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* logger.info("Hello from winston");
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare class MihariWinstonTransport extends Transport {
|
|
35
|
+
private readonly client;
|
|
36
|
+
constructor(options: MihariWinstonOptions);
|
|
37
|
+
log(info: WinstonLogInfo, callback: () => void): void;
|
|
38
|
+
close(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { type MihariWinstonOptions, MihariWinstonTransport, MihariWinstonTransport as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import Transport from
|
|
2
|
-
import { MihariConfig } from
|
|
1
|
+
import Transport from 'winston-transport';
|
|
2
|
+
import { MihariConfig } from '@mihari/logger-types';
|
|
3
|
+
|
|
3
4
|
interface WinstonLogInfo {
|
|
4
5
|
level: string;
|
|
5
6
|
message: string;
|
|
6
7
|
[key: string]: unknown;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
interface MihariWinstonOptions extends Transport.TransportStreamOptions {
|
|
9
10
|
readonly mihariConfig: MihariConfig;
|
|
10
11
|
}
|
|
11
12
|
/**
|
|
@@ -30,11 +31,11 @@ export interface MihariWinstonOptions extends Transport.TransportStreamOptions {
|
|
|
30
31
|
* logger.info("Hello from winston");
|
|
31
32
|
* ```
|
|
32
33
|
*/
|
|
33
|
-
|
|
34
|
+
declare class MihariWinstonTransport extends Transport {
|
|
34
35
|
private readonly client;
|
|
35
36
|
constructor(options: MihariWinstonOptions);
|
|
36
37
|
log(info: WinstonLogInfo, callback: () => void): void;
|
|
37
38
|
close(): Promise<void>;
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
|
|
41
|
+
export { type MihariWinstonOptions, MihariWinstonTransport, MihariWinstonTransport as default };
|
package/dist/index.js
CHANGED
|
@@ -1,85 +1,91 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
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 __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
11
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
MihariWinstonTransport: () => MihariWinstonTransport,
|
|
34
|
+
default: () => index_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
var import_winston_transport = __toESM(require("winston-transport"));
|
|
38
|
+
var import_logger_core = require("@mihari/logger-core");
|
|
39
|
+
var import_logger_types = require("@mihari/logger-types");
|
|
13
40
|
function mapWinstonLevel(level) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
switch (level) {
|
|
42
|
+
case "silly":
|
|
43
|
+
case "debug":
|
|
44
|
+
return import_logger_types.LogLevel.Debug;
|
|
45
|
+
case "verbose":
|
|
46
|
+
case "info":
|
|
47
|
+
return import_logger_types.LogLevel.Info;
|
|
48
|
+
case "warn":
|
|
49
|
+
case "warning":
|
|
50
|
+
return import_logger_types.LogLevel.Warn;
|
|
51
|
+
case "error":
|
|
52
|
+
return import_logger_types.LogLevel.Error;
|
|
53
|
+
case "crit":
|
|
54
|
+
case "critical":
|
|
55
|
+
case "emerg":
|
|
56
|
+
case "alert":
|
|
57
|
+
return import_logger_types.LogLevel.Fatal;
|
|
58
|
+
default:
|
|
59
|
+
return import_logger_types.LogLevel.Info;
|
|
60
|
+
}
|
|
34
61
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
* ],
|
|
52
|
-
* });
|
|
53
|
-
*
|
|
54
|
-
* logger.info("Hello from winston");
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
class MihariWinstonTransport extends winston_transport_1.default {
|
|
58
|
-
constructor(options) {
|
|
59
|
-
super(options);
|
|
60
|
-
this.client = new logger_core_1.MihariClient(options.mihariConfig);
|
|
61
|
-
}
|
|
62
|
-
log(info, callback) {
|
|
63
|
-
setImmediate(() => {
|
|
64
|
-
this.emit("logged", info);
|
|
65
|
-
});
|
|
66
|
-
const { level, message, ...metadata } = info;
|
|
67
|
-
const mihariLevel = mapWinstonLevel(level);
|
|
68
|
-
// Remove winston internal Symbol properties by extracting
|
|
69
|
-
// only string-keyed properties
|
|
70
|
-
const cleanMeta = {};
|
|
71
|
-
for (const key of Object.keys(metadata)) {
|
|
72
|
-
if (key !== "splat") {
|
|
73
|
-
cleanMeta[key] = metadata[key];
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
this.client.log(mihariLevel, message, cleanMeta);
|
|
77
|
-
callback();
|
|
62
|
+
var MihariWinstonTransport = class extends import_winston_transport.default {
|
|
63
|
+
constructor(options) {
|
|
64
|
+
super(options);
|
|
65
|
+
this.client = new import_logger_core.MihariClient(options.mihariConfig);
|
|
66
|
+
}
|
|
67
|
+
log(info, callback) {
|
|
68
|
+
setImmediate(() => {
|
|
69
|
+
this.emit("logged", info);
|
|
70
|
+
});
|
|
71
|
+
const { level, message, ...metadata } = info;
|
|
72
|
+
const mihariLevel = mapWinstonLevel(level);
|
|
73
|
+
const cleanMeta = {};
|
|
74
|
+
for (const key of Object.keys(metadata)) {
|
|
75
|
+
if (key !== "splat") {
|
|
76
|
+
cleanMeta[key] = metadata[key];
|
|
77
|
+
}
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
79
|
+
this.client.log(mihariLevel, message, cleanMeta);
|
|
80
|
+
callback();
|
|
81
|
+
}
|
|
82
|
+
async close() {
|
|
83
|
+
await this.client.shutdown();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var index_default = MihariWinstonTransport;
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
MihariWinstonTransport
|
|
90
|
+
});
|
|
85
91
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import Transport from \"winston-transport\";\nimport { MihariClient } from \"@mihari/logger-core\";\nimport { LogLevel, MihariConfig } from \"@mihari/logger-types\";\n\n/**\n * Maps winston level strings to mihari LogLevel values.\n */\nfunction mapWinstonLevel(level: string): LogLevel {\n switch (level) {\n case \"silly\":\n case \"debug\":\n return LogLevel.Debug;\n case \"verbose\":\n case \"info\":\n return LogLevel.Info;\n case \"warn\":\n case \"warning\":\n return LogLevel.Warn;\n case \"error\":\n return LogLevel.Error;\n case \"crit\":\n case \"critical\":\n case \"emerg\":\n case \"alert\":\n return LogLevel.Fatal;\n default:\n return LogLevel.Info;\n }\n}\n\ninterface WinstonLogInfo {\n level: string;\n message: string;\n [key: string]: unknown;\n}\n\nexport interface MihariWinstonOptions extends Transport.TransportStreamOptions {\n readonly mihariConfig: MihariConfig;\n}\n\n/**\n * Winston transport that forwards logs to mihari.\n *\n * Usage:\n * ```typescript\n * import winston from \"winston\";\n * import { MihariWinstonTransport } from \"@mihari/logger-winston\";\n *\n * const logger = winston.createLogger({\n * transports: [\n * new MihariWinstonTransport({\n * mihariConfig: {\n * token: \"your-token\",\n * endpoint: \"https://logs.example.com\",\n * },\n * }),\n * ],\n * });\n *\n * logger.info(\"Hello from winston\");\n * ```\n */\nexport class MihariWinstonTransport extends Transport {\n private readonly client: MihariClient;\n\n constructor(options: MihariWinstonOptions) {\n super(options);\n this.client = new MihariClient(options.mihariConfig);\n }\n\n log(info: WinstonLogInfo, callback: () => void): void {\n setImmediate(() => {\n this.emit(\"logged\", info);\n });\n\n const { level, message, ...metadata } = info;\n const mihariLevel = mapWinstonLevel(level);\n\n // Remove winston internal Symbol properties by extracting\n // only string-keyed properties\n const cleanMeta: Record<string, unknown> = {};\n for (const key of Object.keys(metadata)) {\n if (key !== \"splat\") {\n cleanMeta[key] = metadata[key];\n }\n }\n\n this.client.log(mihariLevel, message, cleanMeta);\n callback();\n }\n\n async close(): Promise<void> {\n await this.client.shutdown();\n }\n}\n\nexport default MihariWinstonTransport;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAAsB;AACtB,yBAA6B;AAC7B,0BAAuC;AAKvC,SAAS,gBAAgB,OAAyB;AAChD,UAAQ,OAAO;AAAA,IACb,KAAK;AAAA,IACL,KAAK;AACH,aAAO,6BAAS;AAAA,IAClB,KAAK;AAAA,IACL,KAAK;AACH,aAAO,6BAAS;AAAA,IAClB,KAAK;AAAA,IACL,KAAK;AACH,aAAO,6BAAS;AAAA,IAClB,KAAK;AACH,aAAO,6BAAS;AAAA,IAClB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO,6BAAS;AAAA,IAClB;AACE,aAAO,6BAAS;AAAA,EACpB;AACF;AAkCO,IAAM,yBAAN,cAAqC,yBAAAA,QAAU;AAAA,EAGpD,YAAY,SAA+B;AACzC,UAAM,OAAO;AACb,SAAK,SAAS,IAAI,gCAAa,QAAQ,YAAY;AAAA,EACrD;AAAA,EAEA,IAAI,MAAsB,UAA4B;AACpD,iBAAa,MAAM;AACjB,WAAK,KAAK,UAAU,IAAI;AAAA,IAC1B,CAAC;AAED,UAAM,EAAE,OAAO,SAAS,GAAG,SAAS,IAAI;AACxC,UAAM,cAAc,gBAAgB,KAAK;AAIzC,UAAM,YAAqC,CAAC;AAC5C,eAAW,OAAO,OAAO,KAAK,QAAQ,GAAG;AACvC,UAAI,QAAQ,SAAS;AACnB,kBAAU,GAAG,IAAI,SAAS,GAAG;AAAA,MAC/B;AAAA,IACF;AAEA,SAAK,OAAO,IAAI,aAAa,SAAS,SAAS;AAC/C,aAAS;AAAA,EACX;AAAA,EAEA,MAAM,QAAuB;AAC3B,UAAM,KAAK,OAAO,SAAS;AAAA,EAC7B;AACF;AAEA,IAAO,gBAAQ;","names":["Transport"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import Transport from "winston-transport";
|
|
3
|
+
import { MihariClient } from "@mihari/logger-core";
|
|
4
|
+
import { LogLevel } from "@mihari/logger-types";
|
|
5
|
+
function mapWinstonLevel(level) {
|
|
6
|
+
switch (level) {
|
|
7
|
+
case "silly":
|
|
8
|
+
case "debug":
|
|
9
|
+
return LogLevel.Debug;
|
|
10
|
+
case "verbose":
|
|
11
|
+
case "info":
|
|
12
|
+
return LogLevel.Info;
|
|
13
|
+
case "warn":
|
|
14
|
+
case "warning":
|
|
15
|
+
return LogLevel.Warn;
|
|
16
|
+
case "error":
|
|
17
|
+
return LogLevel.Error;
|
|
18
|
+
case "crit":
|
|
19
|
+
case "critical":
|
|
20
|
+
case "emerg":
|
|
21
|
+
case "alert":
|
|
22
|
+
return LogLevel.Fatal;
|
|
23
|
+
default:
|
|
24
|
+
return LogLevel.Info;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
var MihariWinstonTransport = class extends Transport {
|
|
28
|
+
constructor(options) {
|
|
29
|
+
super(options);
|
|
30
|
+
this.client = new MihariClient(options.mihariConfig);
|
|
31
|
+
}
|
|
32
|
+
log(info, callback) {
|
|
33
|
+
setImmediate(() => {
|
|
34
|
+
this.emit("logged", info);
|
|
35
|
+
});
|
|
36
|
+
const { level, message, ...metadata } = info;
|
|
37
|
+
const mihariLevel = mapWinstonLevel(level);
|
|
38
|
+
const cleanMeta = {};
|
|
39
|
+
for (const key of Object.keys(metadata)) {
|
|
40
|
+
if (key !== "splat") {
|
|
41
|
+
cleanMeta[key] = metadata[key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
this.client.log(mihariLevel, message, cleanMeta);
|
|
45
|
+
callback();
|
|
46
|
+
}
|
|
47
|
+
async close() {
|
|
48
|
+
await this.client.shutdown();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var index_default = MihariWinstonTransport;
|
|
52
|
+
export {
|
|
53
|
+
MihariWinstonTransport,
|
|
54
|
+
index_default as default
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import Transport from \"winston-transport\";\nimport { MihariClient } from \"@mihari/logger-core\";\nimport { LogLevel, MihariConfig } from \"@mihari/logger-types\";\n\n/**\n * Maps winston level strings to mihari LogLevel values.\n */\nfunction mapWinstonLevel(level: string): LogLevel {\n switch (level) {\n case \"silly\":\n case \"debug\":\n return LogLevel.Debug;\n case \"verbose\":\n case \"info\":\n return LogLevel.Info;\n case \"warn\":\n case \"warning\":\n return LogLevel.Warn;\n case \"error\":\n return LogLevel.Error;\n case \"crit\":\n case \"critical\":\n case \"emerg\":\n case \"alert\":\n return LogLevel.Fatal;\n default:\n return LogLevel.Info;\n }\n}\n\ninterface WinstonLogInfo {\n level: string;\n message: string;\n [key: string]: unknown;\n}\n\nexport interface MihariWinstonOptions extends Transport.TransportStreamOptions {\n readonly mihariConfig: MihariConfig;\n}\n\n/**\n * Winston transport that forwards logs to mihari.\n *\n * Usage:\n * ```typescript\n * import winston from \"winston\";\n * import { MihariWinstonTransport } from \"@mihari/logger-winston\";\n *\n * const logger = winston.createLogger({\n * transports: [\n * new MihariWinstonTransport({\n * mihariConfig: {\n * token: \"your-token\",\n * endpoint: \"https://logs.example.com\",\n * },\n * }),\n * ],\n * });\n *\n * logger.info(\"Hello from winston\");\n * ```\n */\nexport class MihariWinstonTransport extends Transport {\n private readonly client: MihariClient;\n\n constructor(options: MihariWinstonOptions) {\n super(options);\n this.client = new MihariClient(options.mihariConfig);\n }\n\n log(info: WinstonLogInfo, callback: () => void): void {\n setImmediate(() => {\n this.emit(\"logged\", info);\n });\n\n const { level, message, ...metadata } = info;\n const mihariLevel = mapWinstonLevel(level);\n\n // Remove winston internal Symbol properties by extracting\n // only string-keyed properties\n const cleanMeta: Record<string, unknown> = {};\n for (const key of Object.keys(metadata)) {\n if (key !== \"splat\") {\n cleanMeta[key] = metadata[key];\n }\n }\n\n this.client.log(mihariLevel, message, cleanMeta);\n callback();\n }\n\n async close(): Promise<void> {\n await this.client.shutdown();\n }\n}\n\nexport default MihariWinstonTransport;\n"],"mappings":";AAAA,OAAO,eAAe;AACtB,SAAS,oBAAoB;AAC7B,SAAS,gBAA8B;AAKvC,SAAS,gBAAgB,OAAyB;AAChD,UAAQ,OAAO;AAAA,IACb,KAAK;AAAA,IACL,KAAK;AACH,aAAO,SAAS;AAAA,IAClB,KAAK;AAAA,IACL,KAAK;AACH,aAAO,SAAS;AAAA,IAClB,KAAK;AAAA,IACL,KAAK;AACH,aAAO,SAAS;AAAA,IAClB,KAAK;AACH,aAAO,SAAS;AAAA,IAClB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO,SAAS;AAAA,IAClB;AACE,aAAO,SAAS;AAAA,EACpB;AACF;AAkCO,IAAM,yBAAN,cAAqC,UAAU;AAAA,EAGpD,YAAY,SAA+B;AACzC,UAAM,OAAO;AACb,SAAK,SAAS,IAAI,aAAa,QAAQ,YAAY;AAAA,EACrD;AAAA,EAEA,IAAI,MAAsB,UAA4B;AACpD,iBAAa,MAAM;AACjB,WAAK,KAAK,UAAU,IAAI;AAAA,IAC1B,CAAC;AAED,UAAM,EAAE,OAAO,SAAS,GAAG,SAAS,IAAI;AACxC,UAAM,cAAc,gBAAgB,KAAK;AAIzC,UAAM,YAAqC,CAAC;AAC5C,eAAW,OAAO,OAAO,KAAK,QAAQ,GAAG;AACvC,UAAI,QAAQ,SAAS;AACnB,kBAAU,GAAG,IAAI,SAAS,GAAG;AAAA,MAC/B;AAAA,IACF;AAEA,SAAK,OAAO,IAAI,aAAa,SAAS,SAAS;AAC/C,aAAS;AAAA,EACX;AAAA,EAEA,MAAM,QAAuB;AAC3B,UAAM,KAAK,OAAO,SAAS;AAAA,EAC7B;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,23 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mihari/logger-winston",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Winston transport for mihari log collection",
|
|
5
|
-
"main": "
|
|
6
|
-
"
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
7
15
|
"files": [
|
|
8
16
|
"dist"
|
|
9
17
|
],
|
|
10
18
|
"scripts": {
|
|
11
|
-
"build": "
|
|
19
|
+
"build": "tsup",
|
|
12
20
|
"clean": "rm -rf dist",
|
|
13
21
|
"test": "cd ../.. && npx vitest run --config vitest.config.ts packages/winston"
|
|
14
22
|
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
23
|
+
"tsup": {
|
|
24
|
+
"entry": [
|
|
25
|
+
"src/index.ts"
|
|
26
|
+
],
|
|
27
|
+
"format": [
|
|
28
|
+
"cjs",
|
|
29
|
+
"esm"
|
|
30
|
+
],
|
|
31
|
+
"dts": true,
|
|
32
|
+
"splitting": false,
|
|
33
|
+
"sourcemap": true,
|
|
34
|
+
"clean": true,
|
|
35
|
+
"external": [
|
|
36
|
+
"winston",
|
|
37
|
+
"winston-transport",
|
|
38
|
+
"@mihari/logger-core",
|
|
39
|
+
"@mihari/logger-types"
|
|
40
|
+
]
|
|
17
41
|
},
|
|
18
42
|
"dependencies": {
|
|
19
|
-
"@mihari/logger-core": "^0.
|
|
20
|
-
"@mihari/logger-types": "^0.
|
|
43
|
+
"@mihari/logger-core": "^0.2.0",
|
|
44
|
+
"@mihari/logger-types": "^0.2.0",
|
|
21
45
|
"winston-transport": "^4.7.0"
|
|
22
46
|
},
|
|
23
47
|
"peerDependencies": {
|
|
@@ -32,5 +56,5 @@
|
|
|
32
56
|
"url": "https://github.com/mihari/mihari-js",
|
|
33
57
|
"directory": "packages/winston"
|
|
34
58
|
},
|
|
35
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "a0a2dd591dafbf0923bb81bd5d8180fa6d6eecea"
|
|
36
60
|
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAY,YAAY,EAAE,MAAM,sBAAsB,CAAC;AA4B9D,UAAU,cAAc;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,oBAAqB,SAAQ,SAAS,CAAC,sBAAsB;IAC5E,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,sBAAuB,SAAQ,SAAS;IACnD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;gBAE1B,OAAO,EAAE,oBAAoB;IAKzC,GAAG,CAAC,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAqB/C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAG7B;AAED,eAAe,sBAAsB,CAAC"}
|
package/src/index.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import Transport from "winston-transport";
|
|
2
|
-
import { MihariClient } from "@mihari/logger-core";
|
|
3
|
-
import { LogLevel, MihariConfig } from "@mihari/logger-types";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Maps winston level strings to mihari LogLevel values.
|
|
7
|
-
*/
|
|
8
|
-
function mapWinstonLevel(level: string): LogLevel {
|
|
9
|
-
switch (level) {
|
|
10
|
-
case "silly":
|
|
11
|
-
case "debug":
|
|
12
|
-
return LogLevel.Debug;
|
|
13
|
-
case "verbose":
|
|
14
|
-
case "info":
|
|
15
|
-
return LogLevel.Info;
|
|
16
|
-
case "warn":
|
|
17
|
-
case "warning":
|
|
18
|
-
return LogLevel.Warn;
|
|
19
|
-
case "error":
|
|
20
|
-
return LogLevel.Error;
|
|
21
|
-
case "crit":
|
|
22
|
-
case "critical":
|
|
23
|
-
case "emerg":
|
|
24
|
-
case "alert":
|
|
25
|
-
return LogLevel.Fatal;
|
|
26
|
-
default:
|
|
27
|
-
return LogLevel.Info;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface WinstonLogInfo {
|
|
32
|
-
level: string;
|
|
33
|
-
message: string;
|
|
34
|
-
[key: string]: unknown;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface MihariWinstonOptions extends Transport.TransportStreamOptions {
|
|
38
|
-
readonly mihariConfig: MihariConfig;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Winston transport that forwards logs to mihari.
|
|
43
|
-
*
|
|
44
|
-
* Usage:
|
|
45
|
-
* ```typescript
|
|
46
|
-
* import winston from "winston";
|
|
47
|
-
* import { MihariWinstonTransport } from "@mihari/logger-winston";
|
|
48
|
-
*
|
|
49
|
-
* const logger = winston.createLogger({
|
|
50
|
-
* transports: [
|
|
51
|
-
* new MihariWinstonTransport({
|
|
52
|
-
* mihariConfig: {
|
|
53
|
-
* token: "your-token",
|
|
54
|
-
* endpoint: "https://logs.example.com",
|
|
55
|
-
* },
|
|
56
|
-
* }),
|
|
57
|
-
* ],
|
|
58
|
-
* });
|
|
59
|
-
*
|
|
60
|
-
* logger.info("Hello from winston");
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export class MihariWinstonTransport extends Transport {
|
|
64
|
-
private readonly client: MihariClient;
|
|
65
|
-
|
|
66
|
-
constructor(options: MihariWinstonOptions) {
|
|
67
|
-
super(options);
|
|
68
|
-
this.client = new MihariClient(options.mihariConfig);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
log(info: WinstonLogInfo, callback: () => void): void {
|
|
72
|
-
setImmediate(() => {
|
|
73
|
-
this.emit("logged", info);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
const { level, message, ...metadata } = info;
|
|
77
|
-
const mihariLevel = mapWinstonLevel(level);
|
|
78
|
-
|
|
79
|
-
// Remove winston internal Symbol properties by extracting
|
|
80
|
-
// only string-keyed properties
|
|
81
|
-
const cleanMeta: Record<string, unknown> = {};
|
|
82
|
-
for (const key of Object.keys(metadata)) {
|
|
83
|
-
if (key !== "splat") {
|
|
84
|
-
cleanMeta[key] = metadata[key];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
this.client.log(mihariLevel, message, cleanMeta);
|
|
89
|
-
callback();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async close(): Promise<void> {
|
|
93
|
-
await this.client.shutdown();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export default MihariWinstonTransport;
|