@visulima/pail 4.0.0-alpha.1 → 4.0.0-alpha.11
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/CHANGELOG.md +204 -0
- package/LICENSE.md +434 -52
- package/README.md +323 -0
- package/dist/error.d.ts +104 -0
- package/dist/error.js +76 -0
- package/dist/index.browser.d.ts +3 -1
- package/dist/index.browser.js +1490 -3
- package/dist/index.server.d.ts +3 -5
- package/dist/index.server.js +2380 -110
- package/dist/middleware/elysia.d.ts +71 -0
- package/dist/middleware/elysia.js +70 -0
- package/dist/middleware/express.d.ts +86 -0
- package/dist/middleware/express.js +29 -0
- package/dist/middleware/fastify.d.ts +81 -0
- package/dist/middleware/fastify.js +46 -0
- package/dist/middleware/hono.d.ts +85 -0
- package/dist/middleware/hono.js +33 -0
- package/dist/middleware/next/handler.d.ts +36 -0
- package/dist/middleware/next/handler.js +53 -0
- package/dist/middleware/next/middleware.d.ts +59 -0
- package/dist/middleware/next/storage.d.ts +14 -0
- package/dist/middleware/shared/create-middleware-logger.d.ts +82 -0
- package/dist/middleware/shared/headers.d.ts +14 -0
- package/dist/middleware/shared/routes.d.ts +30 -0
- package/dist/middleware/shared/storage.d.ts +29 -0
- package/dist/middleware/sveltekit.d.ts +123 -0
- package/dist/middleware/sveltekit.js +43 -0
- package/dist/object-tree.d.ts +2 -2
- package/dist/object-tree.js +7 -7
- package/dist/packem_shared/{AbstractJsonReporter-BaZ33PlE.js → AbstractJsonReporter-BO8Calb4.js} +112 -32
- package/dist/packem_shared/AbstractJsonReporter-nOj0Ft1F.js +284 -0
- package/dist/packem_shared/{JsonReporter-BRw4skd5.js → JsonReporter-CCmj7oYL.js} +2 -2
- package/dist/packem_shared/{JsonReporter-VzgyLEYz.js → JsonReporter-Ck2PIAEw.js} +2 -2
- package/dist/packem_shared/PrettyReporter-BCvyNzXO.js +2720 -0
- package/dist/packem_shared/{PrettyReporter-DySIXBjQ.js → PrettyReporter-BtTr13Ha.js} +55 -11
- package/dist/packem_shared/abstract-pretty-reporter-CXAKYCb8.js +2635 -0
- package/dist/packem_shared/constants-B1RjD_ps.js +99 -0
- package/dist/packem_shared/createPailError-B_sgL0nF.js +76 -0
- package/dist/packem_shared/headers-BxHWM6KI.js +127 -0
- package/dist/packem_shared/{index-BomQ3E6J.js → index-Bx3-C0j9.js} +29 -21
- package/dist/packem_shared/pailMiddleware-Ci88geIF.js +24 -0
- package/dist/packem_shared/storage-D0vqz8OX.js +36 -0
- package/dist/packem_shared/{InteractiveStreamHook-DiSubbJ1.js → useLogger-D0rU3lcX.js} +13 -1
- package/dist/packem_shared/{write-console-log-based-on-level-DBmRYXpj.js → write-console-log-based-on-level-ree2lDPw.js} +5 -4
- package/dist/packem_shared/{write-stream-BG8fhcs3.js → write-stream-MDqyXmc_.js} +1 -1
- package/dist/pail.browser.d.ts +1 -1
- package/dist/pail.server.d.ts +1 -76
- package/dist/processor/caller/caller-processor.js +1 -1
- package/dist/processor/environment-processor.d.ts +124 -0
- package/dist/processor/environment-processor.js +89 -0
- package/dist/processor/message-formatter-processor.d.ts +2 -3
- package/dist/processor/message-formatter-processor.js +654 -5
- package/dist/processor/opentelemetry-processor.js +4 -4
- package/dist/processor/redact-processor.d.ts +1 -1
- package/dist/processor/redact-processor.js +2 -1
- package/dist/processor/sampling-processor.d.ts +111 -0
- package/dist/processor/sampling-processor.js +59 -0
- package/dist/reporter/file/json-file-reporter.js +1 -1
- package/dist/reporter/http/abstract-http-reporter.js +23 -26
- package/dist/reporter/http/http-reporter.edge-light.js +134 -57
- package/dist/reporter/json/abstract-json-reporter.d.ts +1 -1
- package/dist/reporter/json/index.browser.js +2 -2
- package/dist/reporter/json/index.js +2 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/pretty/pretty-reporter.server.d.ts +1 -1
- package/dist/reporter/raw/raw-reporter.server.d.ts +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +1 -1
- package/dist/reporter/simple/simple-reporter.server.js +8 -12
- package/dist/types.d.ts +4 -4
- package/dist/utils/write-console-log-based-on-level.d.ts +1 -1
- package/dist/wide-event.d.ts +300 -0
- package/dist/wide-event.js +284 -0
- package/package.json +73 -20
- package/dist/interactive/index.d.ts +0 -2
- package/dist/interactive/index.js +0 -2
- package/dist/interactive/interactive-manager.d.ts +0 -108
- package/dist/interactive/interactive-stream-hook.d.ts +0 -68
- package/dist/packem_shared/InteractiveManager-CZ85hGNW.js +0 -172
- package/dist/packem_shared/PrettyReporter-DgZB2eBG.js +0 -222
- package/dist/packem_shared/abstract-pretty-reporter-Di_sdm2r.js +0 -50
- package/dist/packem_shared/format-label-De49vNPd.js +0 -1193
- package/dist/packem_shared/get-longest-label-C9PWeyKq.js +0 -9
- package/dist/packem_shared/index-DqKWykfa.js +0 -1146
- package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +0 -141
- package/dist/packem_shared/pail.browser-u2CSR_af.js +0 -1427
- package/dist/progress-bar.d.ts +0 -136
- package/dist/progress-bar.js +0 -404
- package/dist/spinner.d.ts +0 -220
- package/dist/spinner.js +0 -2150
- package/dist/utils/ansi-escapes.d.ts +0 -4
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { Meta, Processor } from "../types.d.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Detected environment information.
|
|
4
|
+
*
|
|
5
|
+
* Contains runtime environment details that are automatically detected
|
|
6
|
+
* from environment variables and process information.
|
|
7
|
+
*/
|
|
8
|
+
interface EnvironmentInfo {
|
|
9
|
+
/** Git commit hash or short SHA */
|
|
10
|
+
commit?: string;
|
|
11
|
+
/** Runtime environment (e.g., "production", "development", "test") */
|
|
12
|
+
environment?: string;
|
|
13
|
+
/** Hostname of the machine */
|
|
14
|
+
hostname?: string;
|
|
15
|
+
/** Process ID */
|
|
16
|
+
pid?: number;
|
|
17
|
+
/** Cloud region (e.g., "us-east-1") */
|
|
18
|
+
region?: string;
|
|
19
|
+
/** Application/service name */
|
|
20
|
+
service?: string;
|
|
21
|
+
/** Application version */
|
|
22
|
+
version?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Environment processor configuration options.
|
|
26
|
+
*/
|
|
27
|
+
interface EnvironmentProcessorOptions {
|
|
28
|
+
/**
|
|
29
|
+
* Whether to include the hostname. Defaults to false.
|
|
30
|
+
*/
|
|
31
|
+
includeHostname?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Whether to include the process ID. Defaults to false.
|
|
34
|
+
*/
|
|
35
|
+
includePid?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Static environment info to use instead of or in addition to auto-detection.
|
|
38
|
+
* Values provided here take precedence over auto-detected values.
|
|
39
|
+
*/
|
|
40
|
+
overrides?: Partial<EnvironmentInfo>;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Detects the runtime environment from environment variables.
|
|
44
|
+
*
|
|
45
|
+
* Checks common environment variable patterns used by various hosting
|
|
46
|
+
* platforms (Vercel, AWS, GCP, Heroku, Railway, Fly.io, Render, etc.)
|
|
47
|
+
* to automatically determine service name, version, environment, region,
|
|
48
|
+
* and commit hash.
|
|
49
|
+
* @returns Detected environment information
|
|
50
|
+
*/
|
|
51
|
+
declare const detectEnvironment: () => EnvironmentInfo;
|
|
52
|
+
/**
|
|
53
|
+
* Environment Enrichment Processor.
|
|
54
|
+
*
|
|
55
|
+
* Inspired by evlog's automatic environment detection, this processor
|
|
56
|
+
* enriches log metadata with runtime environment information. It auto-detects
|
|
57
|
+
* details like service name, version, environment, region, and commit hash
|
|
58
|
+
* from common environment variables used by popular hosting platforms.
|
|
59
|
+
*
|
|
60
|
+
* The detected info is added to the log's context, making it easier to
|
|
61
|
+
* correlate logs across services and deployments in production.
|
|
62
|
+
* @template L - The log level type
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* import { createPail } from "@visulima/pail";
|
|
66
|
+
* import EnvironmentProcessor from "@visulima/pail/processor/environment";
|
|
67
|
+
*
|
|
68
|
+
* const logger = createPail({
|
|
69
|
+
* processors: [
|
|
70
|
+
* new EnvironmentProcessor({
|
|
71
|
+
* overrides: { service: "my-api" },
|
|
72
|
+
* includePid: true,
|
|
73
|
+
* }),
|
|
74
|
+
* ],
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* logger.info("Server started");
|
|
78
|
+
* // Log metadata will include: { __env: { service: "my-api", environment: "production", ... } }
|
|
79
|
+
* ```
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* // With static configuration only (no auto-detection)
|
|
83
|
+
* new EnvironmentProcessor({
|
|
84
|
+
* overrides: {
|
|
85
|
+
* service: "payment-service",
|
|
86
|
+
* version: "2.1.0",
|
|
87
|
+
* environment: "staging",
|
|
88
|
+
* },
|
|
89
|
+
* });
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
declare class EnvironmentProcessor<L extends string = string> implements Processor<L> {
|
|
93
|
+
#private;
|
|
94
|
+
/**
|
|
95
|
+
* Creates a new EnvironmentProcessor instance.
|
|
96
|
+
*
|
|
97
|
+
* Auto-detects environment information on construction and merges
|
|
98
|
+
* with any provided overrides. Undefined values in overrides are
|
|
99
|
+
* filtered out so they don't overwrite detected values.
|
|
100
|
+
* @param options Processor configuration options
|
|
101
|
+
*/
|
|
102
|
+
constructor(options?: EnvironmentProcessorOptions);
|
|
103
|
+
/**
|
|
104
|
+
* Processes log metadata to add environment information.
|
|
105
|
+
*
|
|
106
|
+
* Adds a `__env` property to the meta containing detected and
|
|
107
|
+
* configured environment details. Each call receives a shallow
|
|
108
|
+
* clone of the environment info to prevent cross-record mutation.
|
|
109
|
+
* @param meta The log metadata to process
|
|
110
|
+
* @returns The processed metadata with environment info added
|
|
111
|
+
*/
|
|
112
|
+
process(meta: Meta<L>): Meta<L>;
|
|
113
|
+
/**
|
|
114
|
+
* Returns the detected environment information.
|
|
115
|
+
*
|
|
116
|
+
* Useful for inspecting what environment details were auto-detected.
|
|
117
|
+
* Returns a shallow clone to prevent external mutation.
|
|
118
|
+
* @returns The environment information object
|
|
119
|
+
*/
|
|
120
|
+
getEnvironmentInfo(): Readonly<EnvironmentInfo>;
|
|
121
|
+
}
|
|
122
|
+
export { detectEnvironment };
|
|
123
|
+
export default EnvironmentProcessor;
|
|
124
|
+
export type { EnvironmentInfo, EnvironmentProcessorOptions };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const detectEnvironment = () => {
|
|
2
|
+
if (!process.env) {
|
|
3
|
+
return {};
|
|
4
|
+
}
|
|
5
|
+
const { env } = process;
|
|
6
|
+
const info = {
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing -- env vars may be undefined or empty at runtime */
|
|
8
|
+
// Commit hash
|
|
9
|
+
commit: env.COMMIT_SHA || env.GIT_COMMIT || env.VERCEL_GIT_COMMIT_SHA?.slice(0, 7) || env.RAILWAY_GIT_COMMIT_SHA?.slice(0, 7) || env.RENDER_GIT_COMMIT?.slice(0, 7) || env.HEROKU_SLUG_COMMIT?.slice(0, 7) || env.CF_PAGES_COMMIT_SHA?.slice(0, 7) || void 0,
|
|
10
|
+
// Environment / Node env
|
|
11
|
+
environment: env.NODE_ENV || env.ENVIRONMENT || env.APP_ENV || void 0,
|
|
12
|
+
// Hostname
|
|
13
|
+
hostname: env.HOSTNAME || env.HOST || void 0,
|
|
14
|
+
// PID
|
|
15
|
+
pid: process.pid,
|
|
16
|
+
// Region (including GCP Cloud Functions FUNCTION_REGION and GOOGLE_CLOUD_REGION)
|
|
17
|
+
region: env.AWS_REGION || env.VERCEL_REGION || env.FLY_REGION || env.RENDER_REGION || env.CF_REGION || env.GOOGLE_CLOUD_REGION || // GCP general
|
|
18
|
+
env.FUNCTION_REGION || // GCP Cloud Functions
|
|
19
|
+
void 0,
|
|
20
|
+
// Service name - check common platform variables (including GCP Cloud Run / App Engine)
|
|
21
|
+
service: env.SERVICE_NAME || env.APP_NAME || env.K_SERVICE || // GCP Cloud Run
|
|
22
|
+
env.GAE_SERVICE || // GCP App Engine
|
|
23
|
+
env.FUNCTION_TARGET || // GCP Cloud Functions
|
|
24
|
+
env.VERCEL_PROJECT_PRODUCTION_URL || env.FLY_APP_NAME || env.RAILWAY_SERVICE_NAME || env.RENDER_SERVICE_NAME || env.HEROKU_APP_NAME || void 0,
|
|
25
|
+
// Version (including GCP Cloud Run K_REVISION and App Engine GAE_VERSION)
|
|
26
|
+
version: env.APP_VERSION || env.npm_package_version || env.K_REVISION || // GCP Cloud Run revision
|
|
27
|
+
env.GAE_VERSION || // GCP App Engine version
|
|
28
|
+
env.RAILWAY_GIT_COMMIT_SHA?.slice(0, 7) || env.RENDER_GIT_COMMIT?.slice(0, 7) || void 0
|
|
29
|
+
/* eslint-enable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/prefer-nullish-coalescing */
|
|
30
|
+
};
|
|
31
|
+
return Object.fromEntries(Object.entries(info).filter(([, v]) => v !== void 0));
|
|
32
|
+
};
|
|
33
|
+
class EnvironmentProcessor {
|
|
34
|
+
#envInfo;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new EnvironmentProcessor instance.
|
|
37
|
+
*
|
|
38
|
+
* Auto-detects environment information on construction and merges
|
|
39
|
+
* with any provided overrides. Undefined values in overrides are
|
|
40
|
+
* filtered out so they don't overwrite detected values.
|
|
41
|
+
* @param options Processor configuration options
|
|
42
|
+
*/
|
|
43
|
+
constructor(options = {}) {
|
|
44
|
+
const detected = detectEnvironment();
|
|
45
|
+
const cleanOverrides = {};
|
|
46
|
+
if (options.overrides) {
|
|
47
|
+
const overrideEntries = Object.entries(options.overrides);
|
|
48
|
+
for (let i = 0; i < overrideEntries.length; i += 1) {
|
|
49
|
+
const [key, value] = overrideEntries[i];
|
|
50
|
+
if (value !== void 0) {
|
|
51
|
+
cleanOverrides[key] = value;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const merged = { ...detected, ...cleanOverrides };
|
|
56
|
+
if (!options.includePid && cleanOverrides.pid === void 0) {
|
|
57
|
+
delete merged.pid;
|
|
58
|
+
}
|
|
59
|
+
if (!options.includeHostname && cleanOverrides.hostname === void 0) {
|
|
60
|
+
delete merged.hostname;
|
|
61
|
+
}
|
|
62
|
+
this.#envInfo = merged;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Processes log metadata to add environment information.
|
|
66
|
+
*
|
|
67
|
+
* Adds a `__env` property to the meta containing detected and
|
|
68
|
+
* configured environment details. Each call receives a shallow
|
|
69
|
+
* clone of the environment info to prevent cross-record mutation.
|
|
70
|
+
* @param meta The log metadata to process
|
|
71
|
+
* @returns The processed metadata with environment info added
|
|
72
|
+
*/
|
|
73
|
+
process(meta) {
|
|
74
|
+
const enriched = { ...meta, envStorage: { ...this.#envInfo } };
|
|
75
|
+
return enriched;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns the detected environment information.
|
|
79
|
+
*
|
|
80
|
+
* Useful for inspecting what environment details were auto-detected.
|
|
81
|
+
* Returns a shallow clone to prevent external mutation.
|
|
82
|
+
* @returns The environment information object
|
|
83
|
+
*/
|
|
84
|
+
getEnvironmentInfo() {
|
|
85
|
+
return { ...this.#envInfo };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { EnvironmentProcessor as default, detectEnvironment };
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { FormatterFunction } from "@visulima/fmt";
|
|
2
|
-
import type { stringify } from "safe-stable-stringify";
|
|
3
2
|
import type { Meta, StringifyAwareProcessor } from "../types.d.ts";
|
|
4
3
|
/**
|
|
5
4
|
* Message Formatter Processor.
|
|
6
5
|
*
|
|
7
|
-
* A processor that formats log messages using the {@link https://
|
|
6
|
+
* A processor that formats log messages using the {@link https://visulima.com/packages/fmt/|@visulima/fmt} library.
|
|
8
7
|
* Supports custom formatters, string interpolation, and complex object formatting.
|
|
9
8
|
* Processes both the main message and contextual data.
|
|
10
9
|
* @template L - The log level type
|
|
@@ -39,7 +38,7 @@ declare class MessageFormatterProcessor<L extends string = string> implements St
|
|
|
39
38
|
* Sets the stringify function for object serialization.
|
|
40
39
|
* @param function_ The stringify function to use for serializing objects
|
|
41
40
|
*/
|
|
42
|
-
setStringify(function_: typeof stringify): void;
|
|
41
|
+
setStringify(function_: typeof JSON.stringify): void;
|
|
43
42
|
/**
|
|
44
43
|
* Processes log metadata to format messages.
|
|
45
44
|
*
|