@intutic/logger 1.6.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Intutic
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, 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
+ IMPORTED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @intutic/logger — Structured logging with trace context
3
+ *
4
+ * Provides a pino-based logger factory that outputs structured JSON to stdout.
5
+ * 12-factor app compliant — no file transports, stdout only.
6
+ *
7
+ * **MCP proxy exception:** When `PINO_DEST=stderr` is set in the environment,
8
+ * all log output is redirected to stderr (fd 2). This is required by processes
9
+ * that reserve stdout exclusively for JSON-RPC frames (e.g., MCP stdio servers).
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import { createLogger } from '@intutic/logger'
14
+ * const log = createLogger('circuit-breaker')
15
+ * log.info({ workspaceId: 'wk_abc123' }, 'Tool call evaluated')
16
+ * ```
17
+ *
18
+ * @module
19
+ */
20
+ import type { Logger as PinoLogger } from 'pino';
21
+ /** Structured logger interface — re-exported pino Logger */
22
+ export type Logger = PinoLogger;
23
+ /**
24
+ * Creates a named, structured logger instance.
25
+ *
26
+ * @param name - Component name (e.g., 'control-plane', 'circuit-breaker')
27
+ * @param bindings - Optional default key-value pairs attached to every log line
28
+ * @returns Configured pino logger
29
+ */
30
+ export declare function createLogger(name: string, bindings?: Record<string, unknown>): Logger;
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,MAAM,CAAA;AAGhD,4DAA4D;AAC5D,MAAM,MAAM,MAAM,GAAG,UAAU,CAAA;AA0C/B;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,MAAM,CAKR"}
package/dist/index.js ADDED
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ /**
3
+ * @intutic/logger — Structured logging with trace context
4
+ *
5
+ * Provides a pino-based logger factory that outputs structured JSON to stdout.
6
+ * 12-factor app compliant — no file transports, stdout only.
7
+ *
8
+ * **MCP proxy exception:** When `PINO_DEST=stderr` is set in the environment,
9
+ * all log output is redirected to stderr (fd 2). This is required by processes
10
+ * that reserve stdout exclusively for JSON-RPC frames (e.g., MCP stdio servers).
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { createLogger } from '@intutic/logger'
15
+ * const log = createLogger('circuit-breaker')
16
+ * log.info({ workspaceId: 'wk_abc123' }, 'Tool call evaluated')
17
+ * ```
18
+ *
19
+ * @module
20
+ */
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.createLogger = createLogger;
26
+ const pino_1 = __importDefault(require("pino"));
27
+ const api_1 = require("@opentelemetry/api");
28
+ /**
29
+ * Resolve the pino destination stream.
30
+ * - Default: process.stdout (fd 1) — normal 12-factor behaviour.
31
+ * - PINO_DEST=stderr: process.stderr (fd 2) — used by MCP proxy to avoid
32
+ * polluting the JSON-RPC channel on stdout.
33
+ */
34
+ function resolveDestination() {
35
+ if (process.env['PINO_DEST'] === 'stderr') {
36
+ return pino_1.default.destination({ fd: 2, sync: true });
37
+ }
38
+ return undefined; // pino default → stdout
39
+ }
40
+ /** Base configuration for all loggers */
41
+ const BASE_CONFIG = {
42
+ level: process.env.LOG_LEVEL ?? 'info',
43
+ formatters: {
44
+ level: (label) => ({ level: label }),
45
+ },
46
+ timestamp: pino_1.default.stdTimeFunctions.isoTime,
47
+ mixin() {
48
+ try {
49
+ const activeSpan = api_1.trace.getActiveSpan();
50
+ if (activeSpan) {
51
+ const spanContext = activeSpan.spanContext();
52
+ return {
53
+ trace_id: spanContext.traceId,
54
+ span_id: spanContext.spanId,
55
+ };
56
+ }
57
+ }
58
+ catch {
59
+ // Safe fallback if OpenTelemetry is not initialized
60
+ }
61
+ return {};
62
+ },
63
+ };
64
+ /** Resolved destination (evaluated once at module load, before any logger is created) */
65
+ const DEST = resolveDestination();
66
+ /**
67
+ * Creates a named, structured logger instance.
68
+ *
69
+ * @param name - Component name (e.g., 'control-plane', 'circuit-breaker')
70
+ * @param bindings - Optional default key-value pairs attached to every log line
71
+ * @returns Configured pino logger
72
+ */
73
+ function createLogger(name, bindings) {
74
+ const logger = DEST
75
+ ? (0, pino_1.default)({ ...BASE_CONFIG, name }, DEST)
76
+ : (0, pino_1.default)({ ...BASE_CONFIG, name });
77
+ return bindings ? logger.child(bindings) : logger;
78
+ }
79
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3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AI,EAAC,EAAE,GAAG,WAAW,EAAE,IAAI,EAAE,EAAE,IAAI,CAAC;QACtC,CAAC,CAAC,IAAA,cAAI,EAAC,EAAE,GAAG,WAAW,EAAE,IAAI,EAAE,CAAC,CAAA;IAClC,OAAO,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;AACnD,CAAC"}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@intutic/logger",
3
+ "version": "1.6.0",
4
+ "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/intutic/intutic",
8
+ "directory": "packages/logger"
9
+ },
10
+ "main": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "files": [
13
+ "./dist"
14
+ ],
15
+ "dependencies": {
16
+ "pino": "^9.0.0",
17
+ "@opentelemetry/api": "^1.9.0"
18
+ },
19
+ "devDependencies": {
20
+ "typescript": "^5.5",
21
+ "vitest": "^3"
22
+ },
23
+ "engines": {
24
+ "node": ">=18"
25
+ },
26
+ "scripts": {
27
+ "build": "tsc",
28
+ "test": "vitest run --passWithNoTests",
29
+ "typecheck": "tsc --noEmit"
30
+ }
31
+ }