@outfitter/logging 0.2.0 → 0.3.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/README.md +29 -0
- package/dist/index.d.ts +29 -9
- package/dist/index.js +40 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -304,6 +304,34 @@ await flush();
|
|
|
304
304
|
process.exit(0);
|
|
305
305
|
```
|
|
306
306
|
|
|
307
|
+
## Environment-Aware Log Level
|
|
308
|
+
|
|
309
|
+
### `resolveLogLevel(level?)`
|
|
310
|
+
|
|
311
|
+
Resolve the log level from environment configuration. Use this instead of hardcoding levels so your app responds to `OUTFITTER_ENV` and `OUTFITTER_LOG_LEVEL` automatically.
|
|
312
|
+
|
|
313
|
+
**Precedence** (highest wins):
|
|
314
|
+
1. `OUTFITTER_LOG_LEVEL` environment variable
|
|
315
|
+
2. Explicit `level` parameter
|
|
316
|
+
3. `OUTFITTER_ENV` profile defaults (`"debug"` in development)
|
|
317
|
+
4. `"info"` (default)
|
|
318
|
+
|
|
319
|
+
```typescript
|
|
320
|
+
import { createLogger, resolveLogLevel } from "@outfitter/logging";
|
|
321
|
+
|
|
322
|
+
const logger = createLogger({
|
|
323
|
+
name: "my-app",
|
|
324
|
+
level: resolveLogLevel(),
|
|
325
|
+
sinks: [createConsoleSink()],
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// With OUTFITTER_ENV=development → "debug"
|
|
329
|
+
// With OUTFITTER_LOG_LEVEL=error → "error" (overrides everything)
|
|
330
|
+
// With nothing set → "info"
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
MCP-style level names are mapped automatically: `warning` to `warn`, `emergency`/`critical`/`alert` to `fatal`, `notice` to `info`.
|
|
334
|
+
|
|
307
335
|
## API Reference
|
|
308
336
|
|
|
309
337
|
### Functions
|
|
@@ -312,6 +340,7 @@ process.exit(0);
|
|
|
312
340
|
| ----------------------- | --------------------------------------------------- |
|
|
313
341
|
| `createLogger` | Create a configured logger instance |
|
|
314
342
|
| `createChildLogger` | Create a child logger with merged context |
|
|
343
|
+
| `resolveLogLevel` | Resolve log level from env vars and profile |
|
|
315
344
|
| `configureRedaction` | Configure global redaction patterns and keys |
|
|
316
345
|
| `flush` | Flush all pending log writes across all sinks |
|
|
317
346
|
| `createJsonFormatter` | Create a JSON formatter for structured output |
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @outfitter/logging
|
|
3
|
-
*
|
|
4
|
-
* Structured logging via logtape with automatic sensitive data redaction.
|
|
5
|
-
* Provides consistent log formatting across CLI, MCP, and server contexts.
|
|
6
|
-
*
|
|
7
|
-
* @packageDocumentation
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
2
|
* Log levels supported by the logger, ordered from lowest to highest severity.
|
|
11
3
|
*
|
|
12
4
|
* Level priority (lowest to highest): trace (0) < debug (1) < info (2) < warn (3) < error (4) < fatal (5)
|
|
@@ -549,4 +541,32 @@ declare function configureRedaction(config: GlobalRedactionConfig): void;
|
|
|
549
541
|
* ```
|
|
550
542
|
*/
|
|
551
543
|
declare function flush(): Promise<void>;
|
|
552
|
-
|
|
544
|
+
/**
|
|
545
|
+
* Resolve the log level from environment configuration.
|
|
546
|
+
*
|
|
547
|
+
* Precedence (highest wins):
|
|
548
|
+
* 1. `OUTFITTER_LOG_LEVEL` environment variable
|
|
549
|
+
* 2. Explicit `level` parameter
|
|
550
|
+
* 3. `OUTFITTER_ENV` environment profile defaults
|
|
551
|
+
* 4. `"info"` (default)
|
|
552
|
+
*
|
|
553
|
+
* @param level - Optional explicit log level (overridden by env var)
|
|
554
|
+
* @returns Resolved LogLevel
|
|
555
|
+
*
|
|
556
|
+
* @example
|
|
557
|
+
* ```typescript
|
|
558
|
+
* import { createLogger, resolveLogLevel } from "@outfitter/logging";
|
|
559
|
+
*
|
|
560
|
+
* // Auto-resolve from environment
|
|
561
|
+
* const logger = createLogger({
|
|
562
|
+
* name: "my-app",
|
|
563
|
+
* level: resolveLogLevel(),
|
|
564
|
+
* });
|
|
565
|
+
*
|
|
566
|
+
* // With OUTFITTER_ENV=development → "debug"
|
|
567
|
+
* // With OUTFITTER_LOG_LEVEL=error → "error" (overrides everything)
|
|
568
|
+
* // With nothing set → "info"
|
|
569
|
+
* ```
|
|
570
|
+
*/
|
|
571
|
+
declare function resolveLogLevel(level?: LogLevel): LogLevel;
|
|
572
|
+
export { resolveLogLevel, flush, createPrettyFormatter, createLogger, createJsonFormatter, createFileSink, createConsoleSink, createChildLogger, configureRedaction, Sink, RedactionConfig, PrettyFormatterOptions, LoggerInstance, LoggerConfig, LogRecord, LogLevel, GlobalRedactionConfig, Formatter, FileSinkOptions, DEFAULT_PATTERNS, ConsoleSinkOptions };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
getEnvironment as _getEnvironment,
|
|
4
|
+
getEnvironmentDefaults as _getEnvironmentDefaults
|
|
5
|
+
} from "@outfitter/config";
|
|
2
6
|
var LEVEL_PRIORITY = {
|
|
3
7
|
trace: 0,
|
|
4
8
|
debug: 1,
|
|
@@ -387,7 +391,43 @@ async function flush() {
|
|
|
387
391
|
}
|
|
388
392
|
await Promise.all(flushPromises);
|
|
389
393
|
}
|
|
394
|
+
var ENV_LEVEL_MAP = {
|
|
395
|
+
trace: "trace",
|
|
396
|
+
debug: "debug",
|
|
397
|
+
info: "info",
|
|
398
|
+
notice: "info",
|
|
399
|
+
warn: "warn",
|
|
400
|
+
warning: "warn",
|
|
401
|
+
error: "error",
|
|
402
|
+
critical: "fatal",
|
|
403
|
+
alert: "fatal",
|
|
404
|
+
emergency: "fatal",
|
|
405
|
+
fatal: "fatal",
|
|
406
|
+
silent: "silent"
|
|
407
|
+
};
|
|
408
|
+
function resolveLogLevel(level) {
|
|
409
|
+
const envLogLevel = process.env["OUTFITTER_LOG_LEVEL"];
|
|
410
|
+
if (envLogLevel !== undefined) {
|
|
411
|
+
const mapped = ENV_LEVEL_MAP[envLogLevel];
|
|
412
|
+
if (mapped !== undefined) {
|
|
413
|
+
return mapped;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
if (level !== undefined) {
|
|
417
|
+
return level;
|
|
418
|
+
}
|
|
419
|
+
const env = _getEnvironment();
|
|
420
|
+
const defaults = _getEnvironmentDefaults(env);
|
|
421
|
+
if (defaults.logLevel !== null) {
|
|
422
|
+
const mapped = ENV_LEVEL_MAP[defaults.logLevel];
|
|
423
|
+
if (mapped !== undefined) {
|
|
424
|
+
return mapped;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return "info";
|
|
428
|
+
}
|
|
390
429
|
export {
|
|
430
|
+
resolveLogLevel,
|
|
391
431
|
flush,
|
|
392
432
|
createPrettyFormatter,
|
|
393
433
|
createLogger,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outfitter/logging",
|
|
3
3
|
"description": "Structured logging via logtape with redaction support for Outfitter",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.3.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist"
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"clean": "rm -rf dist"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
+
"@outfitter/config": "0.3.0",
|
|
30
31
|
"@outfitter/contracts": "0.2.0",
|
|
31
32
|
"@logtape/logtape": "^2.0.0"
|
|
32
33
|
},
|