@mihari/logger-bunyan 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,44 @@
1
+ import { Writable } from 'stream';
2
+ import { MihariConfig } from '@mihari/logger-types';
3
+
4
+ interface BunyanLogRecord {
5
+ level: number;
6
+ msg: string;
7
+ time: string;
8
+ name: string;
9
+ hostname: string;
10
+ pid: number;
11
+ v: number;
12
+ [key: string]: unknown;
13
+ }
14
+ /**
15
+ * Bunyan writable stream that forwards logs to mihari.
16
+ *
17
+ * Usage:
18
+ * ```typescript
19
+ * import bunyan from "bunyan";
20
+ * import { MihariBunyanStream } from "@mihari/logger-bunyan";
21
+ *
22
+ * const mihariStream = new MihariBunyanStream({
23
+ * token: "your-token",
24
+ * endpoint: "https://logs.example.com",
25
+ * });
26
+ *
27
+ * const logger = bunyan.createLogger({
28
+ * name: "my-app",
29
+ * streams: [
30
+ * { type: "raw", stream: mihariStream },
31
+ * ],
32
+ * });
33
+ *
34
+ * logger.info("Hello from bunyan");
35
+ * ```
36
+ */
37
+ declare class MihariBunyanStream extends Writable {
38
+ private readonly client;
39
+ constructor(config: MihariConfig);
40
+ _write(chunk: BunyanLogRecord, _encoding: string, callback: (error?: Error | null) => void): void;
41
+ _final(callback: (error?: Error | null) => void): void;
42
+ }
43
+
44
+ export { MihariBunyanStream, MihariBunyanStream 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
  interface BunyanLogRecord {
4
5
  level: number;
5
6
  msg: string;
@@ -33,11 +34,11 @@ interface BunyanLogRecord {
33
34
  * logger.info("Hello from bunyan");
34
35
  * ```
35
36
  */
36
- export declare class MihariBunyanStream extends Writable {
37
+ declare class MihariBunyanStream extends Writable {
37
38
  private readonly client;
38
39
  constructor(config: MihariConfig);
39
40
  _write(chunk: BunyanLogRecord, _encoding: string, callback: (error?: Error | null) => void): void;
40
41
  _final(callback: (error?: Error | null) => void): void;
41
42
  }
42
- export default MihariBunyanStream;
43
- //# sourceMappingURL=index.d.ts.map
43
+
44
+ export { MihariBunyanStream, MihariBunyanStream as default };
package/dist/index.js CHANGED
@@ -1,75 +1,68 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MihariBunyanStream = void 0;
4
- const stream_1 = require("stream");
5
- const logger_core_1 = require("@mihari/logger-core");
6
- const logger_types_1 = require("@mihari/logger-types");
7
- /**
8
- * Maps bunyan numeric levels to mihari LogLevel values.
9
- * Bunyan levels: 10=trace, 20=debug, 30=info, 40=warn, 50=error, 60=fatal
10
- */
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
+ MihariBunyanStream: () => MihariBunyanStream,
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");
11
30
  function mapBunyanLevel(bunyanLevel) {
12
- if (bunyanLevel <= 20)
13
- return logger_types_1.LogLevel.Debug;
14
- if (bunyanLevel <= 30)
15
- return logger_types_1.LogLevel.Info;
16
- if (bunyanLevel <= 40)
17
- return logger_types_1.LogLevel.Warn;
18
- if (bunyanLevel <= 50)
19
- return logger_types_1.LogLevel.Error;
20
- return logger_types_1.LogLevel.Fatal;
31
+ if (bunyanLevel <= 20) return import_logger_types.LogLevel.Debug;
32
+ if (bunyanLevel <= 30) return import_logger_types.LogLevel.Info;
33
+ if (bunyanLevel <= 40) return import_logger_types.LogLevel.Warn;
34
+ if (bunyanLevel <= 50) return import_logger_types.LogLevel.Error;
35
+ return import_logger_types.LogLevel.Fatal;
21
36
  }
22
- /**
23
- * Bunyan writable stream that forwards logs to mihari.
24
- *
25
- * Usage:
26
- * ```typescript
27
- * import bunyan from "bunyan";
28
- * import { MihariBunyanStream } from "@mihari/logger-bunyan";
29
- *
30
- * const mihariStream = new MihariBunyanStream({
31
- * token: "your-token",
32
- * endpoint: "https://logs.example.com",
33
- * });
34
- *
35
- * const logger = bunyan.createLogger({
36
- * name: "my-app",
37
- * streams: [
38
- * { type: "raw", stream: mihariStream },
39
- * ],
40
- * });
41
- *
42
- * logger.info("Hello from bunyan");
43
- * ```
44
- */
45
- class MihariBunyanStream extends stream_1.Writable {
46
- constructor(config) {
47
- super({ objectMode: true });
48
- this.client = new logger_core_1.MihariClient(config);
37
+ var MihariBunyanStream = class extends import_stream.Writable {
38
+ constructor(config) {
39
+ super({ objectMode: true });
40
+ this.client = new import_logger_core.MihariClient(config);
41
+ }
42
+ _write(chunk, _encoding, callback) {
43
+ try {
44
+ const { level, msg, time, name, hostname, pid, v, ...rest } = chunk;
45
+ const mihariLevel = mapBunyanLevel(level);
46
+ this.client.log(mihariLevel, msg, {
47
+ bunyanName: name,
48
+ hostname,
49
+ pid,
50
+ ...rest
51
+ });
52
+ callback();
53
+ } catch (err) {
54
+ callback(err instanceof Error ? err : new Error(String(err)));
49
55
  }
50
- _write(chunk, _encoding, callback) {
51
- try {
52
- const { level, msg, time, name, hostname, pid, v, ...rest } = chunk;
53
- const mihariLevel = mapBunyanLevel(level);
54
- this.client.log(mihariLevel, msg, {
55
- bunyanName: name,
56
- hostname,
57
- pid,
58
- ...rest,
59
- });
60
- callback();
61
- }
62
- catch (err) {
63
- callback(err instanceof Error ? err : new Error(String(err)));
64
- }
65
- }
66
- _final(callback) {
67
- this.client
68
- .shutdown()
69
- .then(() => callback())
70
- .catch((err) => callback(err instanceof Error ? err : new Error(String(err))));
71
- }
72
- }
73
- exports.MihariBunyanStream = MihariBunyanStream;
74
- exports.default = MihariBunyanStream;
56
+ }
57
+ _final(callback) {
58
+ this.client.shutdown().then(() => callback()).catch(
59
+ (err) => callback(err instanceof Error ? err : new Error(String(err)))
60
+ );
61
+ }
62
+ };
63
+ var index_default = MihariBunyanStream;
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ MihariBunyanStream
67
+ });
75
68
  //# 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":";;;AAAA,mCAAkC;AAClC,qDAAmD;AACnD,uDAA8D;AAE9D;;;GAGG;AACH,SAAS,cAAc,CAAC,WAAmB;IACzC,IAAI,WAAW,IAAI,EAAE;QAAE,OAAO,uBAAQ,CAAC,KAAK,CAAC;IAC7C,IAAI,WAAW,IAAI,EAAE;QAAE,OAAO,uBAAQ,CAAC,IAAI,CAAC;IAC5C,IAAI,WAAW,IAAI,EAAE;QAAE,OAAO,uBAAQ,CAAC,IAAI,CAAC;IAC5C,IAAI,WAAW,IAAI,EAAE;QAAE,OAAO,uBAAQ,CAAC,KAAK,CAAC;IAC7C,OAAO,uBAAQ,CAAC,KAAK,CAAC;AACxB,CAAC;AAaD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,kBAAmB,SAAQ,iBAAQ;IAG9C,YAAY,MAAoB;QAC9B,KAAK,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5B,IAAI,CAAC,MAAM,GAAG,IAAI,0BAAY,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAEQ,MAAM,CACb,KAAsB,EACtB,SAAiB,EACjB,QAAwC;QAExC,IAAI,CAAC;YACH,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;YACpE,MAAM,WAAW,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC;YAE1C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,GAAG,EAAE;gBAChC,UAAU,EAAE,IAAI;gBAChB,QAAQ;gBACR,GAAG;gBACH,GAAG,IAAI;aACR,CAAC,CAAC;YAEH,QAAQ,EAAE,CAAC;QACb,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,QAAQ,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IAEQ,MAAM,CAAC,QAAwC;QACtD,IAAI,CAAC,MAAM;aACR,QAAQ,EAAE;aACV,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;aACtB,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;IACN,CAAC;CACF;AAtCD,gDAsCC;AAED,kBAAe,kBAAkB,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 bunyan numeric levels to mihari LogLevel values.\n * Bunyan levels: 10=trace, 20=debug, 30=info, 40=warn, 50=error, 60=fatal\n */\nfunction mapBunyanLevel(bunyanLevel: number): LogLevel {\n if (bunyanLevel <= 20) return LogLevel.Debug;\n if (bunyanLevel <= 30) return LogLevel.Info;\n if (bunyanLevel <= 40) return LogLevel.Warn;\n if (bunyanLevel <= 50) return LogLevel.Error;\n return LogLevel.Fatal;\n}\n\ninterface BunyanLogRecord {\n level: number;\n msg: string;\n time: string;\n name: string;\n hostname: string;\n pid: number;\n v: number;\n [key: string]: unknown;\n}\n\n/**\n * Bunyan writable stream that forwards logs to mihari.\n *\n * Usage:\n * ```typescript\n * import bunyan from \"bunyan\";\n * import { MihariBunyanStream } from \"@mihari/logger-bunyan\";\n *\n * const mihariStream = new MihariBunyanStream({\n * token: \"your-token\",\n * endpoint: \"https://logs.example.com\",\n * });\n *\n * const logger = bunyan.createLogger({\n * name: \"my-app\",\n * streams: [\n * { type: \"raw\", stream: mihariStream },\n * ],\n * });\n *\n * logger.info(\"Hello from bunyan\");\n * ```\n */\nexport class MihariBunyanStream extends Writable {\n private readonly client: MihariClient;\n\n constructor(config: MihariConfig) {\n super({ objectMode: true });\n this.client = new MihariClient(config);\n }\n\n override _write(\n chunk: BunyanLogRecord,\n _encoding: string,\n callback: (error?: Error | null) => void\n ): void {\n try {\n const { level, msg, time, name, hostname, pid, v, ...rest } = chunk;\n const mihariLevel = mapBunyanLevel(level);\n\n this.client.log(mihariLevel, msg, {\n bunyanName: name,\n hostname,\n pid,\n ...rest,\n });\n\n callback();\n } catch (err) {\n callback(err instanceof Error ? err : new Error(String(err)));\n }\n }\n\n override _final(callback: (error?: Error | null) => void): void {\n this.client\n .shutdown()\n .then(() => callback())\n .catch((err) =>\n callback(err instanceof Error ? err : new Error(String(err)))\n );\n }\n}\n\nexport default MihariBunyanStream;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAyB;AACzB,yBAA6B;AAC7B,0BAAuC;AAMvC,SAAS,eAAe,aAA+B;AACrD,MAAI,eAAe,GAAI,QAAO,6BAAS;AACvC,MAAI,eAAe,GAAI,QAAO,6BAAS;AACvC,MAAI,eAAe,GAAI,QAAO,6BAAS;AACvC,MAAI,eAAe,GAAI,QAAO,6BAAS;AACvC,SAAO,6BAAS;AAClB;AAoCO,IAAM,qBAAN,cAAiC,uBAAS;AAAA,EAG/C,YAAY,QAAsB;AAChC,UAAM,EAAE,YAAY,KAAK,CAAC;AAC1B,SAAK,SAAS,IAAI,gCAAa,MAAM;AAAA,EACvC;AAAA,EAES,OACP,OACA,WACA,UACM;AACN,QAAI;AACF,YAAM,EAAE,OAAO,KAAK,MAAM,MAAM,UAAU,KAAK,GAAG,GAAG,KAAK,IAAI;AAC9D,YAAM,cAAc,eAAe,KAAK;AAExC,WAAK,OAAO,IAAI,aAAa,KAAK;AAAA,QAChC,YAAY;AAAA,QACZ;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL,CAAC;AAED,eAAS;AAAA,IACX,SAAS,KAAK;AACZ,eAAS,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,IAC9D;AAAA,EACF;AAAA,EAES,OAAO,UAAgD;AAC9D,SAAK,OACF,SAAS,EACT,KAAK,MAAM,SAAS,CAAC,EACrB;AAAA,MAAM,CAAC,QACN,SAAS,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,IAC9D;AAAA,EACJ;AACF;AAEA,IAAO,gBAAQ;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,43 @@
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 mapBunyanLevel(bunyanLevel) {
6
+ if (bunyanLevel <= 20) return LogLevel.Debug;
7
+ if (bunyanLevel <= 30) return LogLevel.Info;
8
+ if (bunyanLevel <= 40) return LogLevel.Warn;
9
+ if (bunyanLevel <= 50) return LogLevel.Error;
10
+ return LogLevel.Fatal;
11
+ }
12
+ var MihariBunyanStream = class extends Writable {
13
+ constructor(config) {
14
+ super({ objectMode: true });
15
+ this.client = new MihariClient(config);
16
+ }
17
+ _write(chunk, _encoding, callback) {
18
+ try {
19
+ const { level, msg, time, name, hostname, pid, v, ...rest } = chunk;
20
+ const mihariLevel = mapBunyanLevel(level);
21
+ this.client.log(mihariLevel, msg, {
22
+ bunyanName: name,
23
+ hostname,
24
+ pid,
25
+ ...rest
26
+ });
27
+ callback();
28
+ } catch (err) {
29
+ callback(err instanceof Error ? err : new Error(String(err)));
30
+ }
31
+ }
32
+ _final(callback) {
33
+ this.client.shutdown().then(() => callback()).catch(
34
+ (err) => callback(err instanceof Error ? err : new Error(String(err)))
35
+ );
36
+ }
37
+ };
38
+ var index_default = MihariBunyanStream;
39
+ export {
40
+ MihariBunyanStream,
41
+ index_default as default
42
+ };
43
+ //# 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 bunyan numeric levels to mihari LogLevel values.\n * Bunyan levels: 10=trace, 20=debug, 30=info, 40=warn, 50=error, 60=fatal\n */\nfunction mapBunyanLevel(bunyanLevel: number): LogLevel {\n if (bunyanLevel <= 20) return LogLevel.Debug;\n if (bunyanLevel <= 30) return LogLevel.Info;\n if (bunyanLevel <= 40) return LogLevel.Warn;\n if (bunyanLevel <= 50) return LogLevel.Error;\n return LogLevel.Fatal;\n}\n\ninterface BunyanLogRecord {\n level: number;\n msg: string;\n time: string;\n name: string;\n hostname: string;\n pid: number;\n v: number;\n [key: string]: unknown;\n}\n\n/**\n * Bunyan writable stream that forwards logs to mihari.\n *\n * Usage:\n * ```typescript\n * import bunyan from \"bunyan\";\n * import { MihariBunyanStream } from \"@mihari/logger-bunyan\";\n *\n * const mihariStream = new MihariBunyanStream({\n * token: \"your-token\",\n * endpoint: \"https://logs.example.com\",\n * });\n *\n * const logger = bunyan.createLogger({\n * name: \"my-app\",\n * streams: [\n * { type: \"raw\", stream: mihariStream },\n * ],\n * });\n *\n * logger.info(\"Hello from bunyan\");\n * ```\n */\nexport class MihariBunyanStream extends Writable {\n private readonly client: MihariClient;\n\n constructor(config: MihariConfig) {\n super({ objectMode: true });\n this.client = new MihariClient(config);\n }\n\n override _write(\n chunk: BunyanLogRecord,\n _encoding: string,\n callback: (error?: Error | null) => void\n ): void {\n try {\n const { level, msg, time, name, hostname, pid, v, ...rest } = chunk;\n const mihariLevel = mapBunyanLevel(level);\n\n this.client.log(mihariLevel, msg, {\n bunyanName: name,\n hostname,\n pid,\n ...rest,\n });\n\n callback();\n } catch (err) {\n callback(err instanceof Error ? err : new Error(String(err)));\n }\n }\n\n override _final(callback: (error?: Error | null) => void): void {\n this.client\n .shutdown()\n .then(() => callback())\n .catch((err) =>\n callback(err instanceof Error ? err : new Error(String(err)))\n );\n }\n}\n\nexport default MihariBunyanStream;\n"],"mappings":";AAAA,SAAS,gBAAgB;AACzB,SAAS,oBAAoB;AAC7B,SAAS,gBAA8B;AAMvC,SAAS,eAAe,aAA+B;AACrD,MAAI,eAAe,GAAI,QAAO,SAAS;AACvC,MAAI,eAAe,GAAI,QAAO,SAAS;AACvC,MAAI,eAAe,GAAI,QAAO,SAAS;AACvC,MAAI,eAAe,GAAI,QAAO,SAAS;AACvC,SAAO,SAAS;AAClB;AAoCO,IAAM,qBAAN,cAAiC,SAAS;AAAA,EAG/C,YAAY,QAAsB;AAChC,UAAM,EAAE,YAAY,KAAK,CAAC;AAC1B,SAAK,SAAS,IAAI,aAAa,MAAM;AAAA,EACvC;AAAA,EAES,OACP,OACA,WACA,UACM;AACN,QAAI;AACF,YAAM,EAAE,OAAO,KAAK,MAAM,MAAM,UAAU,KAAK,GAAG,GAAG,KAAK,IAAI;AAC9D,YAAM,cAAc,eAAe,KAAK;AAExC,WAAK,OAAO,IAAI,aAAa,KAAK;AAAA,QAChC,YAAY;AAAA,QACZ;AAAA,QACA;AAAA,QACA,GAAG;AAAA,MACL,CAAC;AAED,eAAS;AAAA,IACX,SAAS,KAAK;AACZ,eAAS,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,IAC9D;AAAA,EACF;AAAA,EAES,OAAO,UAAgD;AAC9D,SAAK,OACF,SAAS,EACT,KAAK,MAAM,SAAS,CAAC,EACrB;AAAA,MAAM,CAAC,QACN,SAAS,eAAe,QAAQ,MAAM,IAAI,MAAM,OAAO,GAAG,CAAC,CAAC;AAAA,IAC9D;AAAA,EACJ;AACF;AAEA,IAAO,gBAAQ;","names":[]}
package/package.json CHANGED
@@ -1,23 +1,46 @@
1
1
  {
2
2
  "name": "@mihari/logger-bunyan",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Bunyan stream 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/bunyan"
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
+ "bunyan",
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
  "bunyan": ">=1.0.0"
@@ -31,5 +54,5 @@
31
54
  "url": "https://github.com/mihari/mihari-js",
32
55
  "directory": "packages/bunyan"
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;AAc9D,UAAU,eAAe;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,kBAAmB,SAAQ,QAAQ;IAC9C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;gBAE1B,MAAM,EAAE,YAAY;IAKvB,MAAM,CACb,KAAK,EAAE,eAAe,EACtB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GACvC,IAAI;IAkBE,MAAM,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI;CAQhE;AAED,eAAe,kBAAkB,CAAC"}
package/src/index.ts DELETED
@@ -1,91 +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 bunyan numeric levels to mihari LogLevel values.
7
- * Bunyan levels: 10=trace, 20=debug, 30=info, 40=warn, 50=error, 60=fatal
8
- */
9
- function mapBunyanLevel(bunyanLevel: number): LogLevel {
10
- if (bunyanLevel <= 20) return LogLevel.Debug;
11
- if (bunyanLevel <= 30) return LogLevel.Info;
12
- if (bunyanLevel <= 40) return LogLevel.Warn;
13
- if (bunyanLevel <= 50) return LogLevel.Error;
14
- return LogLevel.Fatal;
15
- }
16
-
17
- interface BunyanLogRecord {
18
- level: number;
19
- msg: string;
20
- time: string;
21
- name: string;
22
- hostname: string;
23
- pid: number;
24
- v: number;
25
- [key: string]: unknown;
26
- }
27
-
28
- /**
29
- * Bunyan writable stream that forwards logs to mihari.
30
- *
31
- * Usage:
32
- * ```typescript
33
- * import bunyan from "bunyan";
34
- * import { MihariBunyanStream } from "@mihari/logger-bunyan";
35
- *
36
- * const mihariStream = new MihariBunyanStream({
37
- * token: "your-token",
38
- * endpoint: "https://logs.example.com",
39
- * });
40
- *
41
- * const logger = bunyan.createLogger({
42
- * name: "my-app",
43
- * streams: [
44
- * { type: "raw", stream: mihariStream },
45
- * ],
46
- * });
47
- *
48
- * logger.info("Hello from bunyan");
49
- * ```
50
- */
51
- export class MihariBunyanStream extends Writable {
52
- private readonly client: MihariClient;
53
-
54
- constructor(config: MihariConfig) {
55
- super({ objectMode: true });
56
- this.client = new MihariClient(config);
57
- }
58
-
59
- override _write(
60
- chunk: BunyanLogRecord,
61
- _encoding: string,
62
- callback: (error?: Error | null) => void
63
- ): void {
64
- try {
65
- const { level, msg, time, name, hostname, pid, v, ...rest } = chunk;
66
- const mihariLevel = mapBunyanLevel(level);
67
-
68
- this.client.log(mihariLevel, msg, {
69
- bunyanName: name,
70
- hostname,
71
- pid,
72
- ...rest,
73
- });
74
-
75
- callback();
76
- } catch (err) {
77
- callback(err instanceof Error ? err : new Error(String(err)));
78
- }
79
- }
80
-
81
- override _final(callback: (error?: Error | null) => void): void {
82
- this.client
83
- .shutdown()
84
- .then(() => callback())
85
- .catch((err) =>
86
- callback(err instanceof Error ? err : new Error(String(err)))
87
- );
88
- }
89
- }
90
-
91
- export default MihariBunyanStream;