@mihari/logger-pino 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.
@@ -0,0 +1,34 @@
1
+ import { Writable } from 'stream';
2
+ import { MihariConfig } from '@mihari/logger-types';
3
+
4
+ /**
5
+ * Creates a pino transport writable stream that forwards logs to mihari.
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * import pino from "pino";
10
+ * import { createMihariTransport } from "@mihari/logger-pino";
11
+ *
12
+ * const transport = createMihariTransport({
13
+ * token: "your-token",
14
+ * endpoint: "https://logs.example.com",
15
+ * });
16
+ *
17
+ * const logger = pino(transport);
18
+ * ```
19
+ *
20
+ * Or with pino's transport option:
21
+ * ```typescript
22
+ * const logger = pino({
23
+ * transport: { target: "@mihari/logger-pino" }
24
+ * });
25
+ * ```
26
+ */
27
+ declare function createMihariTransport(config: MihariConfig): Writable;
28
+ /**
29
+ * Default export for use as a pino transport target.
30
+ * The module default export must be a function that returns a writable stream.
31
+ */
32
+ declare function export_default(config: MihariConfig): Writable;
33
+
34
+ export { createMihariTransport, export_default as default };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { Writable } from "stream";
2
- import { MihariConfig } from "@mihari/logger-types";
1
+ import { Writable } from 'stream';
2
+ import { MihariConfig } from '@mihari/logger-types';
3
+
3
4
  /**
4
5
  * Creates a pino transport writable stream that forwards logs to mihari.
5
6
  *
@@ -23,10 +24,11 @@ import { MihariConfig } from "@mihari/logger-types";
23
24
  * });
24
25
  * ```
25
26
  */
26
- export declare function createMihariTransport(config: MihariConfig): Writable;
27
+ declare function createMihariTransport(config: MihariConfig): Writable;
27
28
  /**
28
29
  * Default export for use as a pino transport target.
29
30
  * The module default export must be a function that returns a writable stream.
30
31
  */
31
- export default function (config: MihariConfig): Writable;
32
- //# sourceMappingURL=index.d.ts.map
32
+ declare function export_default(config: MihariConfig): Writable;
33
+
34
+ export { createMihariTransport, export_default as default };
package/dist/index.js CHANGED
@@ -1,84 +1,73 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMihariTransport = createMihariTransport;
4
- exports.default = default_1;
5
- const stream_1 = require("stream");
6
- const logger_core_1 = require("@mihari/logger-core");
7
- const logger_types_1 = require("@mihari/logger-types");
8
- /**
9
- * Maps pino numeric levels to mihari LogLevel values.
10
- * Pino levels: 10=trace, 20=debug, 30=info, 40=warn, 50=error, 60=fatal
11
- */
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ createMihariTransport: () => createMihariTransport,
24
+ default: () => index_default
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_stream = require("stream");
28
+ var import_logger_core = require("@mihari/logger-core");
29
+ var import_logger_types = require("@mihari/logger-types");
12
30
  function mapPinoLevel(pinoLevel) {
13
- if (pinoLevel <= 20)
14
- return logger_types_1.LogLevel.Debug;
15
- if (pinoLevel <= 30)
16
- return logger_types_1.LogLevel.Info;
17
- if (pinoLevel <= 40)
18
- return logger_types_1.LogLevel.Warn;
19
- if (pinoLevel <= 50)
20
- return logger_types_1.LogLevel.Error;
21
- return logger_types_1.LogLevel.Fatal;
31
+ if (pinoLevel <= 20) return import_logger_types.LogLevel.Debug;
32
+ if (pinoLevel <= 30) return import_logger_types.LogLevel.Info;
33
+ if (pinoLevel <= 40) return import_logger_types.LogLevel.Warn;
34
+ if (pinoLevel <= 50) return import_logger_types.LogLevel.Error;
35
+ return import_logger_types.LogLevel.Fatal;
22
36
  }
23
- /**
24
- * Creates a pino transport writable stream that forwards logs to mihari.
25
- *
26
- * Usage:
27
- * ```typescript
28
- * import pino from "pino";
29
- * import { createMihariTransport } from "@mihari/logger-pino";
30
- *
31
- * const transport = createMihariTransport({
32
- * token: "your-token",
33
- * endpoint: "https://logs.example.com",
34
- * });
35
- *
36
- * const logger = pino(transport);
37
- * ```
38
- *
39
- * Or with pino's transport option:
40
- * ```typescript
41
- * const logger = pino({
42
- * transport: { target: "@mihari/logger-pino" }
43
- * });
44
- * ```
45
- */
46
37
  function createMihariTransport(config) {
47
- const client = new logger_core_1.MihariClient(config);
48
- const stream = new stream_1.Writable({
49
- objectMode: true,
50
- write(chunk, _encoding, callback) {
51
- try {
52
- const obj = typeof chunk === "string" ? JSON.parse(chunk) : chunk;
53
- const { level, time, msg, message, ...rest } = obj;
54
- const mihariLevel = mapPinoLevel(level);
55
- const logMessage = msg ?? message ?? "";
56
- const { pid, hostname, ...metadata } = rest;
57
- client.log(mihariLevel, String(logMessage), {
58
- ...(pid !== undefined ? { pid } : {}),
59
- ...(hostname !== undefined ? { hostname } : {}),
60
- ...metadata,
61
- });
62
- callback();
63
- }
64
- catch (err) {
65
- callback(err instanceof Error ? err : new Error(String(err)));
66
- }
67
- },
68
- final(callback) {
69
- client
70
- .shutdown()
71
- .then(() => callback())
72
- .catch((err) => callback(err instanceof Error ? err : new Error(String(err))));
73
- },
74
- });
75
- return stream;
38
+ const client = new import_logger_core.MihariClient(config);
39
+ const stream = new import_stream.Writable({
40
+ objectMode: true,
41
+ write(chunk, _encoding, callback) {
42
+ try {
43
+ const obj = typeof chunk === "string" ? JSON.parse(chunk) : chunk;
44
+ const { level, time, msg, message, ...rest } = obj;
45
+ const mihariLevel = mapPinoLevel(level);
46
+ const logMessage = msg ?? message ?? "";
47
+ const { pid, hostname, ...metadata } = rest;
48
+ client.log(mihariLevel, String(logMessage), {
49
+ ...pid !== void 0 ? { pid } : {},
50
+ ...hostname !== void 0 ? { hostname } : {},
51
+ ...metadata
52
+ });
53
+ callback();
54
+ } catch (err) {
55
+ callback(err instanceof Error ? err : new Error(String(err)));
56
+ }
57
+ },
58
+ final(callback) {
59
+ client.shutdown().then(() => callback()).catch(
60
+ (err) => callback(err instanceof Error ? err : new Error(String(err)))
61
+ );
62
+ }
63
+ });
64
+ return stream;
76
65
  }
77
- /**
78
- * Default export for use as a pino transport target.
79
- * The module default export must be a function that returns a writable stream.
80
- */
81
- function default_1(config) {
82
- return createMihariTransport(config);
66
+ function index_default(config) {
67
+ return createMihariTransport(config);
83
68
  }
69
+ // Annotate the CommonJS export names for ESM import in node:
70
+ 0 && (module.exports = {
71
+ createMihariTransport
72
+ });
84
73
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AA+CA,sDAsCC;AAMD,4BAEC;AA7FD,mCAAkC;AAClC,qDAAmD;AACnD,uDAA8D;AAE9D;;;GAGG;AACH,SAAS,YAAY,CAAC,SAAiB;IACrC,IAAI,SAAS,IAAI,EAAE;QAAE,OAAO,uBAAQ,CAAC,KAAK,CAAC;IAC3C,IAAI,SAAS,IAAI,EAAE;QAAE,OAAO,uBAAQ,CAAC,IAAI,CAAC;IAC1C,IAAI,SAAS,IAAI,EAAE;QAAE,OAAO,uBAAQ,CAAC,IAAI,CAAC;IAC1C,IAAI,SAAS,IAAI,EAAE;QAAE,OAAO,uBAAQ,CAAC,KAAK,CAAC;IAC3C,OAAO,uBAAQ,CAAC,KAAK,CAAC;AACxB,CAAC;AAUD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,SAAgB,qBAAqB,CAAC,MAAoB;IACxD,MAAM,MAAM,GAAG,IAAI,0BAAY,CAAC,MAAM,CAAC,CAAC;IAExC,MAAM,MAAM,GAAG,IAAI,iBAAQ,CAAC;QAC1B,UAAU,EAAE,IAAI;QAChB,KAAK,CAAC,KAA6B,EAAE,SAAS,EAAE,QAAQ;YACtD,IAAI,CAAC;gBACH,MAAM,GAAG,GACP,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;gBAExD,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,GAAG,GAAG,CAAC;gBACnD,MAAM,WAAW,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;gBACxC,MAAM,UAAU,GAAG,GAAG,IAAI,OAAO,IAAI,EAAE,CAAC;gBAExC,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI,CAAC;gBAE5C,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,UAAU,CAAC,EAAE;oBAC1C,GAAG,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBACrC,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC/C,GAAG,QAAQ;iBACZ,CAAC,CAAC;gBAEH,QAAQ,EAAE,CAAC;YACb,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,QAAQ,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QACD,KAAK,CAAC,QAAQ;YACZ,MAAM;iBACH,QAAQ,EAAE;iBACV,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;iBACtB,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CACb,QAAQ,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAC9D,CAAC;QACN,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,mBAAyB,MAAoB;IAC3C,OAAO,qBAAqB,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Writable } from \"stream\";\nimport { MihariClient } from \"@mihari/logger-core\";\nimport { LogLevel, MihariConfig } from \"@mihari/logger-types\";\n\n/**\n * Maps pino numeric levels to mihari LogLevel values.\n * Pino levels: 10=trace, 20=debug, 30=info, 40=warn, 50=error, 60=fatal\n */\nfunction mapPinoLevel(pinoLevel: number): LogLevel {\n if (pinoLevel <= 20) return LogLevel.Debug;\n if (pinoLevel <= 30) return LogLevel.Info;\n if (pinoLevel <= 40) return LogLevel.Warn;\n if (pinoLevel <= 50) return LogLevel.Error;\n return LogLevel.Fatal;\n}\n\ninterface PinoLogObject {\n level: number;\n time: number;\n msg?: string;\n message?: string;\n [key: string]: unknown;\n}\n\n/**\n * Creates a pino transport writable stream that forwards logs to mihari.\n *\n * Usage:\n * ```typescript\n * import pino from \"pino\";\n * import { createMihariTransport } from \"@mihari/logger-pino\";\n *\n * const transport = createMihariTransport({\n * token: \"your-token\",\n * endpoint: \"https://logs.example.com\",\n * });\n *\n * const logger = pino(transport);\n * ```\n *\n * Or with pino's transport option:\n * ```typescript\n * const logger = pino({\n * transport: { target: \"@mihari/logger-pino\" }\n * });\n * ```\n */\nexport function createMihariTransport(config: MihariConfig): Writable {\n const client = new MihariClient(config);\n\n const stream = new Writable({\n objectMode: true,\n write(chunk: PinoLogObject | string, _encoding, callback) {\n try {\n const obj: PinoLogObject =\n typeof chunk === \"string\" ? JSON.parse(chunk) : chunk;\n\n const { level, time, msg, message, ...rest } = obj;\n const mihariLevel = mapPinoLevel(level);\n const logMessage = msg ?? message ?? \"\";\n\n const { pid, hostname, ...metadata } = rest;\n\n client.log(mihariLevel, String(logMessage), {\n ...(pid !== undefined ? { pid } : {}),\n ...(hostname !== undefined ? { hostname } : {}),\n ...metadata,\n });\n\n callback();\n } catch (err) {\n callback(err instanceof Error ? err : new Error(String(err)));\n }\n },\n final(callback) {\n client\n .shutdown()\n .then(() => callback())\n .catch((err) =>\n callback(err instanceof Error ? err : new Error(String(err)))\n );\n },\n });\n\n return stream;\n}\n\n/**\n * Default export for use as a pino transport target.\n * The module default export must be a function that returns a writable stream.\n */\nexport default function (config: MihariConfig): Writable {\n return createMihariTransport(config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyB;AACzB,yBAA6B;AAC7B,0BAAuC;AAMvC,SAAS,aAAa,WAA6B;AACjD,MAAI,aAAa,GAAI,QAAO,6BAAS;AACrC,MAAI,aAAa,GAAI,QAAO,6BAAS;AACrC,MAAI,aAAa,GAAI,QAAO,6BAAS;AACrC,MAAI,aAAa,GAAI,QAAO,6BAAS;AACrC,SAAO,6BAAS;AAClB;AAiCO,SAAS,sBAAsB,QAAgC;AACpE,QAAM,SAAS,IAAI,gCAAa,MAAM;AAEtC,QAAM,SAAS,IAAI,uBAAS;AAAA,IAC1B,YAAY;AAAA,IACZ,MAAM,OAA+B,WAAW,UAAU;AACxD,UAAI;AACF,cAAM,MACJ,OAAO,UAAU,WAAW,KAAK,MAAM,KAAK,IAAI;AAElD,cAAM,EAAE,OAAO,MAAM,KAAK,SAAS,GAAG,KAAK,IAAI;AAC/C,cAAM,cAAc,aAAa,KAAK;AACtC,cAAM,aAAa,OAAO,WAAW;AAErC,cAAM,EAAE,KAAK,UAAU,GAAG,SAAS,IAAI;AAEvC,eAAO,IAAI,aAAa,OAAO,UAAU,GAAG;AAAA,UAC1C,GAAI,QAAQ,SAAY,EAAE,IAAI,IAAI,CAAC;AAAA,UACnC,GAAI,aAAa,SAAY,EAAE,SAAS,IAAI,CAAC;AAAA,UAC7C,GAAG;AAAA,QACL,CAAC;AAED,iBAAS;AAAA,MACX,SAAS,KAAK;AACZ,iBAAS,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,MAC9D;AAAA,IACF;AAAA,IACA,MAAM,UAAU;AACd,aACG,SAAS,EACT,KAAK,MAAM,SAAS,CAAC,EACrB;AAAA,QAAM,CAAC,QACN,SAAS,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,MAC9D;AAAA,IACJ;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAMe,SAAR,cAAkB,QAAgC;AACvD,SAAO,sBAAsB,MAAM;AACrC;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,48 @@
1
+ // src/index.ts
2
+ import { Writable } from "stream";
3
+ import { MihariClient } from "@mihari/logger-core";
4
+ import { LogLevel } from "@mihari/logger-types";
5
+ function mapPinoLevel(pinoLevel) {
6
+ if (pinoLevel <= 20) return LogLevel.Debug;
7
+ if (pinoLevel <= 30) return LogLevel.Info;
8
+ if (pinoLevel <= 40) return LogLevel.Warn;
9
+ if (pinoLevel <= 50) return LogLevel.Error;
10
+ return LogLevel.Fatal;
11
+ }
12
+ function createMihariTransport(config) {
13
+ const client = new MihariClient(config);
14
+ const stream = new Writable({
15
+ objectMode: true,
16
+ write(chunk, _encoding, callback) {
17
+ try {
18
+ const obj = typeof chunk === "string" ? JSON.parse(chunk) : chunk;
19
+ const { level, time, msg, message, ...rest } = obj;
20
+ const mihariLevel = mapPinoLevel(level);
21
+ const logMessage = msg ?? message ?? "";
22
+ const { pid, hostname, ...metadata } = rest;
23
+ client.log(mihariLevel, String(logMessage), {
24
+ ...pid !== void 0 ? { pid } : {},
25
+ ...hostname !== void 0 ? { hostname } : {},
26
+ ...metadata
27
+ });
28
+ callback();
29
+ } catch (err) {
30
+ callback(err instanceof Error ? err : new Error(String(err)));
31
+ }
32
+ },
33
+ final(callback) {
34
+ client.shutdown().then(() => callback()).catch(
35
+ (err) => callback(err instanceof Error ? err : new Error(String(err)))
36
+ );
37
+ }
38
+ });
39
+ return stream;
40
+ }
41
+ function index_default(config) {
42
+ return createMihariTransport(config);
43
+ }
44
+ export {
45
+ createMihariTransport,
46
+ index_default as default
47
+ };
48
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Writable } from \"stream\";\nimport { MihariClient } from \"@mihari/logger-core\";\nimport { LogLevel, MihariConfig } from \"@mihari/logger-types\";\n\n/**\n * Maps pino numeric levels to mihari LogLevel values.\n * Pino levels: 10=trace, 20=debug, 30=info, 40=warn, 50=error, 60=fatal\n */\nfunction mapPinoLevel(pinoLevel: number): LogLevel {\n if (pinoLevel <= 20) return LogLevel.Debug;\n if (pinoLevel <= 30) return LogLevel.Info;\n if (pinoLevel <= 40) return LogLevel.Warn;\n if (pinoLevel <= 50) return LogLevel.Error;\n return LogLevel.Fatal;\n}\n\ninterface PinoLogObject {\n level: number;\n time: number;\n msg?: string;\n message?: string;\n [key: string]: unknown;\n}\n\n/**\n * Creates a pino transport writable stream that forwards logs to mihari.\n *\n * Usage:\n * ```typescript\n * import pino from \"pino\";\n * import { createMihariTransport } from \"@mihari/logger-pino\";\n *\n * const transport = createMihariTransport({\n * token: \"your-token\",\n * endpoint: \"https://logs.example.com\",\n * });\n *\n * const logger = pino(transport);\n * ```\n *\n * Or with pino's transport option:\n * ```typescript\n * const logger = pino({\n * transport: { target: \"@mihari/logger-pino\" }\n * });\n * ```\n */\nexport function createMihariTransport(config: MihariConfig): Writable {\n const client = new MihariClient(config);\n\n const stream = new Writable({\n objectMode: true,\n write(chunk: PinoLogObject | string, _encoding, callback) {\n try {\n const obj: PinoLogObject =\n typeof chunk === \"string\" ? JSON.parse(chunk) : chunk;\n\n const { level, time, msg, message, ...rest } = obj;\n const mihariLevel = mapPinoLevel(level);\n const logMessage = msg ?? message ?? \"\";\n\n const { pid, hostname, ...metadata } = rest;\n\n client.log(mihariLevel, String(logMessage), {\n ...(pid !== undefined ? { pid } : {}),\n ...(hostname !== undefined ? { hostname } : {}),\n ...metadata,\n });\n\n callback();\n } catch (err) {\n callback(err instanceof Error ? err : new Error(String(err)));\n }\n },\n final(callback) {\n client\n .shutdown()\n .then(() => callback())\n .catch((err) =>\n callback(err instanceof Error ? err : new Error(String(err)))\n );\n },\n });\n\n return stream;\n}\n\n/**\n * Default export for use as a pino transport target.\n * The module default export must be a function that returns a writable stream.\n */\nexport default function (config: MihariConfig): Writable {\n return createMihariTransport(config);\n}\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,gBAA8B;AAMvC,SAAS,aAAa,WAA6B;AACjD,MAAI,aAAa,GAAI,QAAO,SAAS;AACrC,MAAI,aAAa,GAAI,QAAO,SAAS;AACrC,MAAI,aAAa,GAAI,QAAO,SAAS;AACrC,MAAI,aAAa,GAAI,QAAO,SAAS;AACrC,SAAO,SAAS;AAClB;AAiCO,SAAS,sBAAsB,QAAgC;AACpE,QAAM,SAAS,IAAI,aAAa,MAAM;AAEtC,QAAM,SAAS,IAAI,SAAS;AAAA,IAC1B,YAAY;AAAA,IACZ,MAAM,OAA+B,WAAW,UAAU;AACxD,UAAI;AACF,cAAM,MACJ,OAAO,UAAU,WAAW,KAAK,MAAM,KAAK,IAAI;AAElD,cAAM,EAAE,OAAO,MAAM,KAAK,SAAS,GAAG,KAAK,IAAI;AAC/C,cAAM,cAAc,aAAa,KAAK;AACtC,cAAM,aAAa,OAAO,WAAW;AAErC,cAAM,EAAE,KAAK,UAAU,GAAG,SAAS,IAAI;AAEvC,eAAO,IAAI,aAAa,OAAO,UAAU,GAAG;AAAA,UAC1C,GAAI,QAAQ,SAAY,EAAE,IAAI,IAAI,CAAC;AAAA,UACnC,GAAI,aAAa,SAAY,EAAE,SAAS,IAAI,CAAC;AAAA,UAC7C,GAAG;AAAA,QACL,CAAC;AAED,iBAAS;AAAA,MACX,SAAS,KAAK;AACZ,iBAAS,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,MAC9D;AAAA,IACF;AAAA,IACA,MAAM,UAAU;AACd,aACG,SAAS,EACT,KAAK,MAAM,SAAS,CAAC,EACrB;AAAA,QAAM,CAAC,QACN,SAAS,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,MAC9D;AAAA,IACJ;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAMe,SAAR,cAAkB,QAAgC;AACvD,SAAO,sBAAsB,MAAM;AACrC;","names":[]}
package/package.json CHANGED
@@ -1,23 +1,46 @@
1
1
  {
2
2
  "name": "@mihari/logger-pino",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Pino transport for mihari log collection",
5
- "main": "src/index.ts",
6
- "types": "src/index.ts",
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": "tsc",
19
+ "build": "tsup",
12
20
  "clean": "rm -rf dist",
13
21
  "test": "cd ../.. && npx vitest run --config vitest.config.ts packages/pino"
14
22
  },
15
- "devDependencies": {
16
- "vitest": "^3.0.0"
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
+ "pino",
37
+ "@mihari/logger-core",
38
+ "@mihari/logger-types"
39
+ ]
17
40
  },
18
41
  "dependencies": {
19
- "@mihari/logger-core": "^0.1.0",
20
- "@mihari/logger-types": "^0.1.0"
42
+ "@mihari/logger-core": "^0.2.0",
43
+ "@mihari/logger-types": "^0.2.0"
21
44
  },
22
45
  "peerDependencies": {
23
46
  "pino": ">=8.0.0"
@@ -31,5 +54,5 @@
31
54
  "url": "https://github.com/mihari/mihari-js",
32
55
  "directory": "packages/pino"
33
56
  },
34
- "gitHead": "dc10a3217caa819965eb3a1e2ff3901a16e510aa"
57
+ "gitHead": "a0a2dd591dafbf0923bb81bd5d8180fa6d6eecea"
35
58
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAY,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAsB9D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,YAAY,GAAG,QAAQ,CAsCpE;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,WAAW,MAAM,EAAE,YAAY,GAAG,QAAQ,CAEvD"}
package/src/index.ts DELETED
@@ -1,94 +0,0 @@
1
- import { Writable } from "stream";
2
- import { MihariClient } from "@mihari/logger-core";
3
- import { LogLevel, MihariConfig } from "@mihari/logger-types";
4
-
5
- /**
6
- * Maps pino numeric levels to mihari LogLevel values.
7
- * Pino levels: 10=trace, 20=debug, 30=info, 40=warn, 50=error, 60=fatal
8
- */
9
- function mapPinoLevel(pinoLevel: number): LogLevel {
10
- if (pinoLevel <= 20) return LogLevel.Debug;
11
- if (pinoLevel <= 30) return LogLevel.Info;
12
- if (pinoLevel <= 40) return LogLevel.Warn;
13
- if (pinoLevel <= 50) return LogLevel.Error;
14
- return LogLevel.Fatal;
15
- }
16
-
17
- interface PinoLogObject {
18
- level: number;
19
- time: number;
20
- msg?: string;
21
- message?: string;
22
- [key: string]: unknown;
23
- }
24
-
25
- /**
26
- * Creates a pino transport writable stream that forwards logs to mihari.
27
- *
28
- * Usage:
29
- * ```typescript
30
- * import pino from "pino";
31
- * import { createMihariTransport } from "@mihari/logger-pino";
32
- *
33
- * const transport = createMihariTransport({
34
- * token: "your-token",
35
- * endpoint: "https://logs.example.com",
36
- * });
37
- *
38
- * const logger = pino(transport);
39
- * ```
40
- *
41
- * Or with pino's transport option:
42
- * ```typescript
43
- * const logger = pino({
44
- * transport: { target: "@mihari/logger-pino" }
45
- * });
46
- * ```
47
- */
48
- export function createMihariTransport(config: MihariConfig): Writable {
49
- const client = new MihariClient(config);
50
-
51
- const stream = new Writable({
52
- objectMode: true,
53
- write(chunk: PinoLogObject | string, _encoding, callback) {
54
- try {
55
- const obj: PinoLogObject =
56
- typeof chunk === "string" ? JSON.parse(chunk) : chunk;
57
-
58
- const { level, time, msg, message, ...rest } = obj;
59
- const mihariLevel = mapPinoLevel(level);
60
- const logMessage = msg ?? message ?? "";
61
-
62
- const { pid, hostname, ...metadata } = rest;
63
-
64
- client.log(mihariLevel, String(logMessage), {
65
- ...(pid !== undefined ? { pid } : {}),
66
- ...(hostname !== undefined ? { hostname } : {}),
67
- ...metadata,
68
- });
69
-
70
- callback();
71
- } catch (err) {
72
- callback(err instanceof Error ? err : new Error(String(err)));
73
- }
74
- },
75
- final(callback) {
76
- client
77
- .shutdown()
78
- .then(() => callback())
79
- .catch((err) =>
80
- callback(err instanceof Error ? err : new Error(String(err)))
81
- );
82
- },
83
- });
84
-
85
- return stream;
86
- }
87
-
88
- /**
89
- * Default export for use as a pino transport target.
90
- * The module default export must be a function that returns a writable stream.
91
- */
92
- export default function (config: MihariConfig): Writable {
93
- return createMihariTransport(config);
94
- }