@encore.dev/sdk 0.0.0 → 2.0.0-beta.4
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 +362 -0
- package/README.md +122 -2
- package/app_meta.test.ts +134 -0
- package/app_meta.ts +186 -0
- package/config/config.test.ts +381 -0
- package/config/config.ts +178 -0
- package/config/mod.ts +14 -0
- package/config/secrets.ts +147 -0
- package/config/value.ts +243 -0
- package/cron/mod.ts +23 -0
- package/dist/app_meta.d.ts +93 -0
- package/dist/app_meta.js +65 -0
- package/dist/app_meta.js.map +1 -0
- package/dist/config/config.d.ts +105 -0
- package/dist/config/config.js +87 -0
- package/dist/config/config.js.map +1 -0
- package/dist/config/mod.d.ts +4 -0
- package/dist/config/mod.js +3 -0
- package/dist/config/mod.js.map +1 -0
- package/dist/config/secrets.d.ts +92 -0
- package/dist/config/secrets.js +80 -0
- package/dist/config/secrets.js.map +1 -0
- package/dist/config/value.d.ts +51 -0
- package/dist/config/value.js +178 -0
- package/dist/config/value.js.map +1 -0
- package/dist/cron/mod.d.ts +22 -0
- package/dist/cron/mod.js +9 -0
- package/dist/cron/mod.js.map +1 -0
- package/dist/internal/otel/backend.d.ts +50 -0
- package/dist/internal/otel/backend.js +2 -0
- package/dist/internal/otel/backend.js.map +1 -0
- package/dist/internal/otel/context.d.ts +10 -0
- package/dist/internal/otel/context.js +34 -0
- package/dist/internal/otel/context.js.map +1 -0
- package/dist/internal/otel/context_manager.d.ts +22 -0
- package/dist/internal/otel/context_manager.js +120 -0
- package/dist/internal/otel/context_manager.js.map +1 -0
- package/dist/internal/otel/encode.d.ts +112 -0
- package/dist/internal/otel/encode.js +290 -0
- package/dist/internal/otel/encode.js.map +1 -0
- package/dist/internal/otel/index.d.ts +9 -0
- package/dist/internal/otel/index.js +9 -0
- package/dist/internal/otel/index.js.map +1 -0
- package/dist/internal/otel/meter.d.ts +73 -0
- package/dist/internal/otel/meter.js +265 -0
- package/dist/internal/otel/meter.js.map +1 -0
- package/dist/internal/otel/propagator.d.ts +14 -0
- package/dist/internal/otel/propagator.js +61 -0
- package/dist/internal/otel/propagator.js.map +1 -0
- package/dist/internal/otel/provider.d.ts +9 -0
- package/dist/internal/otel/provider.js +19 -0
- package/dist/internal/otel/provider.js.map +1 -0
- package/dist/internal/otel/request_context.d.ts +11 -0
- package/dist/internal/otel/request_context.js +20 -0
- package/dist/internal/otel/request_context.js.map +1 -0
- package/dist/internal/otel/span.d.ts +61 -0
- package/dist/internal/otel/span.js +206 -0
- package/dist/internal/otel/span.js.map +1 -0
- package/dist/internal/otel/tracer.d.ts +15 -0
- package/dist/internal/otel/tracer.js +65 -0
- package/dist/internal/otel/tracer.js.map +1 -0
- package/dist/internal/reqtrack/mod.d.ts +6 -0
- package/dist/internal/reqtrack/mod.js +28 -0
- package/dist/internal/reqtrack/mod.js.map +1 -0
- package/dist/internal/runtime/meter.d.ts +11 -0
- package/dist/internal/runtime/meter.js +22 -0
- package/dist/internal/runtime/meter.js.map +1 -0
- package/dist/internal/runtime/mod.d.ts +12 -0
- package/dist/internal/runtime/mod.js +28 -0
- package/dist/internal/runtime/mod.js.map +1 -0
- package/dist/internal/runtime/napi/napi.cjs +122 -0
- package/dist/internal/runtime/napi/napi.d.cts +601 -0
- package/dist/internal/runtime/shutdown.d.ts +13 -0
- package/dist/internal/runtime/shutdown.js +56 -0
- package/dist/internal/runtime/shutdown.js.map +1 -0
- package/dist/internal/utils/constraints.d.ts +9 -0
- package/dist/internal/utils/constraints.js +2 -0
- package/dist/internal/utils/constraints.js.map +1 -0
- package/dist/log/index.d.ts +39 -0
- package/dist/log/index.js +44 -0
- package/dist/log/index.js.map +1 -0
- package/dist/log/logger.d.ts +123 -0
- package/dist/log/logger.js +203 -0
- package/dist/log/logger.js.map +1 -0
- package/dist/log/runtime.d.ts +19 -0
- package/dist/log/runtime.js +22 -0
- package/dist/log/runtime.js.map +1 -0
- package/dist/log/stderr.d.ts +9 -0
- package/dist/log/stderr.js +25 -0
- package/dist/log/stderr.js.map +1 -0
- package/dist/metrics/mod.d.ts +315 -0
- package/dist/metrics/mod.js +488 -0
- package/dist/metrics/mod.js.map +1 -0
- package/dist/mod.d.ts +6 -0
- package/dist/mod.js +4 -0
- package/dist/mod.js.map +1 -0
- package/dist/otel.d.ts +9 -0
- package/dist/otel.js +13 -0
- package/dist/otel.js.map +1 -0
- package/dist/pubsub/encoding.d.ts +3 -0
- package/dist/pubsub/encoding.js +10 -0
- package/dist/pubsub/encoding.js.map +1 -0
- package/dist/pubsub/mod.d.ts +6 -0
- package/dist/pubsub/mod.js +3 -0
- package/dist/pubsub/mod.js.map +1 -0
- package/dist/pubsub/refs.d.ts +12 -0
- package/dist/pubsub/refs.js +11 -0
- package/dist/pubsub/refs.js.map +1 -0
- package/dist/pubsub/subscription.d.ts +128 -0
- package/dist/pubsub/subscription.js +39 -0
- package/dist/pubsub/subscription.js.map +1 -0
- package/dist/pubsub/topic.d.ts +148 -0
- package/dist/pubsub/topic.js +164 -0
- package/dist/pubsub/topic.js.map +1 -0
- package/dist/req_meta.d.ts +47 -0
- package/dist/req_meta.js +26 -0
- package/dist/req_meta.js.map +1 -0
- package/dist/services/index.d.ts +7 -0
- package/dist/services/index.js +17 -0
- package/dist/services/index.js.map +1 -0
- package/dist/shutdown/mod.d.ts +23 -0
- package/dist/shutdown/mod.js +24 -0
- package/dist/shutdown/mod.js.map +1 -0
- package/dist/storage/objects/bucket.d.ts +216 -0
- package/dist/storage/objects/bucket.js +123 -0
- package/dist/storage/objects/bucket.js.map +1 -0
- package/dist/storage/objects/error.d.ts +14 -0
- package/dist/storage/objects/error.js +81 -0
- package/dist/storage/objects/error.js.map +1 -0
- package/dist/storage/objects/mod.d.ts +4 -0
- package/dist/storage/objects/mod.js +3 -0
- package/dist/storage/objects/mod.js.map +1 -0
- package/dist/storage/objects/refs.d.ts +31 -0
- package/dist/storage/objects/refs.js +20 -0
- package/dist/storage/objects/refs.js.map +1 -0
- package/dist/storage/postgres/database.d.ts +295 -0
- package/dist/storage/postgres/database.js +378 -0
- package/dist/storage/postgres/database.js.map +1 -0
- package/dist/storage/postgres/mod.d.ts +2 -0
- package/dist/storage/postgres/mod.js +2 -0
- package/dist/storage/postgres/mod.js.map +1 -0
- package/dist/storage/redis/commands.d.ts +573 -0
- package/dist/storage/redis/commands.js +637 -0
- package/dist/storage/redis/commands.js.map +1 -0
- package/dist/storage/redis/database.d.ts +302 -0
- package/dist/storage/redis/database.js +336 -0
- package/dist/storage/redis/database.js.map +1 -0
- package/dist/storage/redis/mod.d.ts +88 -0
- package/dist/storage/redis/mod.js +84 -0
- package/dist/storage/redis/mod.js.map +1 -0
- package/dist/storage/redis/native.d.ts +8 -0
- package/dist/storage/redis/native.js +11 -0
- package/dist/storage/redis/native.js.map +1 -0
- package/dist/storage/redis/options.d.ts +89 -0
- package/dist/storage/redis/options.js +53 -0
- package/dist/storage/redis/options.js.map +1 -0
- package/dist/storage/redis/pubsub.d.ts +53 -0
- package/dist/storage/redis/pubsub.js +88 -0
- package/dist/storage/redis/pubsub.js.map +1 -0
- package/dist/storage/redis/reply.d.ts +256 -0
- package/dist/storage/redis/reply.js +572 -0
- package/dist/storage/redis/reply.js.map +1 -0
- package/dist/storage/redis/scan.d.ts +11 -0
- package/dist/storage/redis/scan.js +76 -0
- package/dist/storage/redis/scan.js.map +1 -0
- package/dist/storage/redis/script.d.ts +91 -0
- package/dist/storage/redis/script.js +143 -0
- package/dist/storage/redis/script.js.map +1 -0
- package/dist/storage/redis/target.d.ts +47 -0
- package/dist/storage/redis/target.js +82 -0
- package/dist/storage/redis/target.js.map +1 -0
- package/dist/storage/redis/wire.d.ts +105 -0
- package/dist/storage/redis/wire.js +333 -0
- package/dist/storage/redis/wire.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/mod.d.ts +42 -0
- package/dist/types/mod.js +65 -0
- package/dist/types/mod.js.map +1 -0
- package/internal/otel/backend.ts +60 -0
- package/internal/otel/context.test.ts +70 -0
- package/internal/otel/context.ts +48 -0
- package/internal/otel/context_manager.test.ts +154 -0
- package/internal/otel/context_manager.ts +141 -0
- package/internal/otel/encode.test.ts +266 -0
- package/internal/otel/encode.ts +408 -0
- package/internal/otel/index.ts +20 -0
- package/internal/otel/meter.test.ts +231 -0
- package/internal/otel/meter.ts +332 -0
- package/internal/otel/propagator.test.ts +105 -0
- package/internal/otel/propagator.ts +68 -0
- package/internal/otel/provider.ts +23 -0
- package/internal/otel/request_context.ts +32 -0
- package/internal/otel/span.ts +252 -0
- package/internal/otel/tracer.test.ts +352 -0
- package/internal/otel/tracer.ts +104 -0
- package/internal/reqtrack/mod.ts +39 -0
- package/internal/runtime/meter.ts +26 -0
- package/internal/runtime/mod.ts +41 -0
- package/internal/runtime/napi/napi.cjs +122 -0
- package/internal/runtime/napi/napi.d.cts +601 -0
- package/internal/runtime/shutdown.test.ts +248 -0
- package/internal/runtime/shutdown.ts +64 -0
- package/internal/utils/constraints.ts +12 -0
- package/log/index.ts +107 -0
- package/log/logger.test.ts +194 -0
- package/log/logger.ts +308 -0
- package/log/runtime.test.ts +65 -0
- package/log/runtime.ts +40 -0
- package/log/stderr.test.ts +23 -0
- package/log/stderr.ts +24 -0
- package/metrics/export.test.ts +337 -0
- package/metrics/mod.test.ts +180 -0
- package/metrics/mod.ts +619 -0
- package/mod.ts +22 -0
- package/otel.test.ts +84 -0
- package/otel.ts +17 -0
- package/package.json +121 -5
- package/pubsub/encoding.ts +8 -0
- package/pubsub/mod.ts +14 -0
- package/pubsub/pubsub.test.ts +186 -0
- package/pubsub/refs.ts +22 -0
- package/pubsub/subscription.ts +180 -0
- package/pubsub/topic.test.ts +121 -0
- package/pubsub/topic.ts +212 -0
- package/req_meta.ts +75 -0
- package/services/index.test.ts +30 -0
- package/services/index.ts +16 -0
- package/shutdown/mod.ts +24 -0
- package/storage/objects/bucket.ts +338 -0
- package/storage/objects/error.ts +94 -0
- package/storage/objects/mod.ts +35 -0
- package/storage/objects/refs.ts +69 -0
- package/storage/postgres/database.integration.test.ts +175 -0
- package/storage/postgres/database.test.ts +241 -0
- package/storage/postgres/database.ts +497 -0
- package/storage/postgres/mod.ts +15 -0
- package/storage/redis/commands.ts +1221 -0
- package/storage/redis/database.ts +466 -0
- package/storage/redis/mod.ts +135 -0
- package/storage/redis/native.ts +11 -0
- package/storage/redis/options.ts +119 -0
- package/storage/redis/pubsub.ts +92 -0
- package/storage/redis/redis.test.ts +706 -0
- package/storage/redis/reply.ts +705 -0
- package/storage/redis/runtime.test.ts +233 -0
- package/storage/redis/scan.ts +125 -0
- package/storage/redis/script.ts +162 -0
- package/storage/redis/target.ts +131 -0
- package/storage/redis/wire.ts +369 -0
- package/types/mod.ts +92 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Logger, type FieldsObject } from './logger.js';
|
|
2
|
+
export type { FieldValue, FieldsObject, Logger } from './logger.js';
|
|
3
|
+
export { LogLevel } from './logger.js';
|
|
4
|
+
/** `ENCORE_LOG`: the lowest level logged, `off` for none; trace by default. */
|
|
5
|
+
declare const log: Logger;
|
|
6
|
+
/**
|
|
7
|
+
* The default logger for the app
|
|
8
|
+
*/
|
|
9
|
+
export default log;
|
|
10
|
+
/**
|
|
11
|
+
* Trace logs a message at the trace level
|
|
12
|
+
*/
|
|
13
|
+
export declare function trace(msg: string, fields?: FieldsObject): void;
|
|
14
|
+
/**
|
|
15
|
+
* Debug logs a message at the debug level
|
|
16
|
+
*/
|
|
17
|
+
export declare function debug(msg: string, fields?: FieldsObject): void;
|
|
18
|
+
/**
|
|
19
|
+
* Info logs a message at the info level
|
|
20
|
+
*/
|
|
21
|
+
export declare function info(msg: string, fields?: FieldsObject): void;
|
|
22
|
+
/**
|
|
23
|
+
* Warn logs a message at the warn level
|
|
24
|
+
*/
|
|
25
|
+
export declare function warn(err: Error | unknown, fields?: FieldsObject): void;
|
|
26
|
+
export declare function warn(err: Error | unknown, msg: string, fields?: FieldsObject): void;
|
|
27
|
+
export declare function warn(msg: string, fields?: FieldsObject): void;
|
|
28
|
+
/**
|
|
29
|
+
* Error logs a message at the error level
|
|
30
|
+
*/
|
|
31
|
+
export declare function error(err: Error | unknown, fields?: FieldsObject): void;
|
|
32
|
+
export declare function error(err: Error | unknown, msg: string, fields?: FieldsObject): void;
|
|
33
|
+
export declare function error(msg: string, fields?: FieldsObject): void;
|
|
34
|
+
/**
|
|
35
|
+
* Fatal logs a message at the fatal level
|
|
36
|
+
*/
|
|
37
|
+
export declare function fatal(err: Error | unknown, fields?: FieldsObject): void;
|
|
38
|
+
export declare function fatal(err: Error | unknown, msg: string, fields?: FieldsObject): void;
|
|
39
|
+
export declare function fatal(msg: string, fields?: FieldsObject): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Structured logging. Each call prints a log record on stderr, one line in
|
|
2
|
+
// the Encore log format, with the active span's ids. Needs no runtime: lines
|
|
3
|
+
// logged before it loads are printed too.
|
|
4
|
+
//
|
|
5
|
+
// import log from "@encore.dev/sdk/log";
|
|
6
|
+
// log.info("adding user", { user: "grace" });
|
|
7
|
+
// const users = log.withName("users"); // `logger` of its records
|
|
8
|
+
import { Logger, parseLevel } from './logger.js';
|
|
9
|
+
export { LogLevel } from './logger.js';
|
|
10
|
+
/** `ENCORE_LOG`: the lowest level logged, `off` for none; trace by default. */
|
|
11
|
+
const log = new Logger({ level: parseLevel(process.env.ENCORE_LOG) });
|
|
12
|
+
/**
|
|
13
|
+
* The default logger for the app
|
|
14
|
+
*/
|
|
15
|
+
export default log;
|
|
16
|
+
/**
|
|
17
|
+
* Trace logs a message at the trace level
|
|
18
|
+
*/
|
|
19
|
+
export function trace(msg, fields) {
|
|
20
|
+
log.trace(msg, fields);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Debug logs a message at the debug level
|
|
24
|
+
*/
|
|
25
|
+
export function debug(msg, fields) {
|
|
26
|
+
log.debug(msg, fields);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Info logs a message at the info level
|
|
30
|
+
*/
|
|
31
|
+
export function info(msg, fields) {
|
|
32
|
+
log.info(msg, fields);
|
|
33
|
+
}
|
|
34
|
+
export function warn(errOrMsg, msgOrFields, fields) {
|
|
35
|
+
// The casts satisfy tsc; the method has the same overloads.
|
|
36
|
+
log.warn(errOrMsg, msgOrFields, fields);
|
|
37
|
+
}
|
|
38
|
+
export function error(errOrMsg, msgOrFields, fields) {
|
|
39
|
+
log.error(errOrMsg, msgOrFields, fields);
|
|
40
|
+
}
|
|
41
|
+
export function fatal(errOrMsg, msgOrFields, fields) {
|
|
42
|
+
log.fatal(errOrMsg, msgOrFields, fields);
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../log/index.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,6EAA6E;AAC7E,0CAA0C;AAC1C,EAAE;AACF,2CAA2C;AAC3C,gDAAgD;AAChD,oEAAoE;AACpE,OAAO,EAAC,MAAM,EAAE,UAAU,EAAoB,MAAM,UAAU,CAAC;AAG/D,OAAO,EAAC,QAAQ,EAAC,MAAM,UAAU,CAAC;AAElC,+EAA+E;AAC/E,MAAM,GAAG,GAAG,IAAI,MAAM,CAAC,EAAC,KAAK,EAAE,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAC,CAAC,CAAC;AAEpE;;GAEG;AACH,eAAe,GAAG,CAAC;AAEnB;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,GAAW,EAAE,MAAqB;IACtD,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,KAAK,CAAC,GAAW,EAAE,MAAqB;IACtD,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AACzB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,IAAI,CAAC,GAAW,EAAE,MAAqB;IACrD,GAAG,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AACxB,CAAC;AAYD,MAAM,UAAU,IAAI,CAClB,QAAiB,EACjB,WAAqB,EACrB,MAAgB;IAEhB,4DAA4D;IAC5D,GAAG,CAAC,IAAI,CACN,QAAiB,EACjB,WAAqB,EACrB,MAAkC,CACnC,CAAC;AACJ,CAAC;AAYD,MAAM,UAAU,KAAK,CACnB,QAAiB,EACjB,WAAqB,EACrB,MAAgB;IAEhB,GAAG,CAAC,KAAK,CACP,QAAiB,EACjB,WAAqB,EACrB,MAAkC,CACnC,CAAC;AACJ,CAAC;AAYD,MAAM,UAAU,KAAK,CACnB,QAAiB,EACjB,WAAqB,EACrB,MAAgB;IAEhB,GAAG,CAAC,KAAK,CACP,QAAiB,EACjB,WAAqB,EACrB,MAAkC,CACnC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* A field value we support logging
|
|
4
|
+
*/
|
|
5
|
+
export type FieldValue = string | number | boolean | null | undefined | FieldsObject | FieldValue[];
|
|
6
|
+
/**
|
|
7
|
+
* A map of fields that can be logged
|
|
8
|
+
*/
|
|
9
|
+
export type FieldsObject = Record<string, FieldValue>;
|
|
10
|
+
export declare enum LogLevel {
|
|
11
|
+
Trace = 1,
|
|
12
|
+
Debug = 2,
|
|
13
|
+
Info = 3,
|
|
14
|
+
Warn = 4,
|
|
15
|
+
Error = 5,
|
|
16
|
+
Fatal = 6
|
|
17
|
+
}
|
|
18
|
+
/** A level above every other: nothing is logged. */
|
|
19
|
+
export declare const OFF: number;
|
|
20
|
+
/** The level a name (any case) or `off` stands for; trace otherwise. */
|
|
21
|
+
export declare function parseLevel(name: string | undefined): LogLevel;
|
|
22
|
+
/** @internal */
|
|
23
|
+
export interface LoggerOptions {
|
|
24
|
+
/** The lowest level logged. */
|
|
25
|
+
level: LogLevel;
|
|
26
|
+
/** The `logger` of every record. */
|
|
27
|
+
name?: string;
|
|
28
|
+
/** Attributes of every record. */
|
|
29
|
+
fields?: FieldsObject;
|
|
30
|
+
/** Where lines go; stderr by default. */
|
|
31
|
+
write?: (line: Buffer) => void;
|
|
32
|
+
}
|
|
33
|
+
/** A record's parts besides its level and the logger's name. */
|
|
34
|
+
export interface RecordParts {
|
|
35
|
+
/** When the record was made; absent: now. */
|
|
36
|
+
timeUnixMillis?: number;
|
|
37
|
+
message: string;
|
|
38
|
+
/** The span's 25-byte context: trace id, span id, flags. */
|
|
39
|
+
spanCtx?: Buffer;
|
|
40
|
+
exceptionType?: string;
|
|
41
|
+
exceptionMessage?: string;
|
|
42
|
+
/** The stack trace in JavaScript's format. */
|
|
43
|
+
exceptionStacktrace?: string;
|
|
44
|
+
/** The calling function's name. */
|
|
45
|
+
codeFunction?: string;
|
|
46
|
+
/** The caller's source file, line, and column. */
|
|
47
|
+
codeFile?: string;
|
|
48
|
+
codeLine?: number;
|
|
49
|
+
codeColumn?: number;
|
|
50
|
+
/** The runtime module a line of the runtime's own comes from; such a
|
|
51
|
+
* line logs under the runtime's logger, in place of the logger's name. */
|
|
52
|
+
runtimeTarget?: string;
|
|
53
|
+
/** A JSON object of the user's attributes. */
|
|
54
|
+
attrsJson?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A structured logger. Each call prints a log record on stderr, one line in
|
|
58
|
+
* the Encore log format, with the logger's name, the logger's and the call's
|
|
59
|
+
* fields as attributes, and the active span's ids. The SDK core encodes the
|
|
60
|
+
* line; it needs the native library, not the runtime. An attribute named
|
|
61
|
+
* like a reserved key is that field when valid, `raw.<key>` otherwise; one
|
|
62
|
+
* named like a key of the record's exception is `raw.<key>`.
|
|
63
|
+
* Lines are written synchronously; none is lost on `process.exit`.
|
|
64
|
+
*/
|
|
65
|
+
export declare class Logger {
|
|
66
|
+
private readonly level;
|
|
67
|
+
private readonly name;
|
|
68
|
+
private readonly fields;
|
|
69
|
+
private readonly write;
|
|
70
|
+
/** @internal */
|
|
71
|
+
constructor(options: LoggerOptions);
|
|
72
|
+
/**
|
|
73
|
+
* Returns a new logger with the specified level.
|
|
74
|
+
*/
|
|
75
|
+
withLevel(level: LogLevel): Logger;
|
|
76
|
+
/**
|
|
77
|
+
* Returns a new logger named `name`, the `logger` of its records, with
|
|
78
|
+
* this logger's level and fields.
|
|
79
|
+
*/
|
|
80
|
+
withName(name: string): Logger;
|
|
81
|
+
/**
|
|
82
|
+
* Returns a new logger with the given fields added to the context.
|
|
83
|
+
*/
|
|
84
|
+
with(fields: FieldsObject): Logger;
|
|
85
|
+
/**
|
|
86
|
+
* Trace logs a message at the trace level.
|
|
87
|
+
*/
|
|
88
|
+
trace(msg: string, fields?: FieldsObject): void;
|
|
89
|
+
/**
|
|
90
|
+
* Debug logs a message at the debug level.
|
|
91
|
+
*/
|
|
92
|
+
debug(msg: string, fields?: FieldsObject): void;
|
|
93
|
+
/**
|
|
94
|
+
* Info logs a message at the info level.
|
|
95
|
+
*/
|
|
96
|
+
info(msg: string, fields?: FieldsObject): void;
|
|
97
|
+
/**
|
|
98
|
+
* Warn logs a message at the warn level.
|
|
99
|
+
*/
|
|
100
|
+
warn(err: Error | unknown, fields?: FieldsObject): void;
|
|
101
|
+
warn(err: Error | unknown, msg: string, fields?: FieldsObject): void;
|
|
102
|
+
warn(msg: string, fields?: FieldsObject): void;
|
|
103
|
+
/**
|
|
104
|
+
* Error logs a message at the error level.
|
|
105
|
+
*/
|
|
106
|
+
error(err: Error | unknown, fields?: FieldsObject): void;
|
|
107
|
+
error(err: Error | unknown, msg: string, fields?: FieldsObject): void;
|
|
108
|
+
error(msg: string, fields?: FieldsObject): void;
|
|
109
|
+
/**
|
|
110
|
+
* Fatal logs a message at the fatal level.
|
|
111
|
+
*/
|
|
112
|
+
fatal(err: Error | unknown, fields?: FieldsObject): void;
|
|
113
|
+
fatal(err: Error | unknown, msg: string, fields?: FieldsObject): void;
|
|
114
|
+
fatal(msg: string, fields?: FieldsObject): void;
|
|
115
|
+
private options;
|
|
116
|
+
private log;
|
|
117
|
+
/**
|
|
118
|
+
* Prints a record of `parts` under the logger's name, at or above the
|
|
119
|
+
* logger's level.
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
emit(level: LogLevel, parts: RecordParts): void;
|
|
123
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { isSpanContextValid, trace } from '@opentelemetry/api';
|
|
2
|
+
import { activeContext } from '../internal/otel/context.js';
|
|
3
|
+
import { encodeLog } from '../internal/runtime/napi/napi.cjs';
|
|
4
|
+
import { writeStderr } from './stderr.js';
|
|
5
|
+
export var LogLevel;
|
|
6
|
+
(function (LogLevel) {
|
|
7
|
+
LogLevel[LogLevel["Trace"] = 1] = "Trace";
|
|
8
|
+
LogLevel[LogLevel["Debug"] = 2] = "Debug";
|
|
9
|
+
LogLevel[LogLevel["Info"] = 3] = "Info";
|
|
10
|
+
LogLevel[LogLevel["Warn"] = 4] = "Warn";
|
|
11
|
+
LogLevel[LogLevel["Error"] = 5] = "Error";
|
|
12
|
+
LogLevel[LogLevel["Fatal"] = 6] = "Fatal";
|
|
13
|
+
})(LogLevel || (LogLevel = {}));
|
|
14
|
+
/** A level above every other: nothing is logged. */
|
|
15
|
+
export const OFF = LogLevel.Fatal + 1;
|
|
16
|
+
/** Each level's name, as `ENCORE_LOG` gives it. */
|
|
17
|
+
const LEVELS = {
|
|
18
|
+
[LogLevel.Trace]: 'trace',
|
|
19
|
+
[LogLevel.Debug]: 'debug',
|
|
20
|
+
[LogLevel.Info]: 'info',
|
|
21
|
+
[LogLevel.Warn]: 'warn',
|
|
22
|
+
[LogLevel.Error]: 'error',
|
|
23
|
+
[LogLevel.Fatal]: 'fatal',
|
|
24
|
+
};
|
|
25
|
+
/** The level a name (any case) or `off` stands for; trace otherwise. */
|
|
26
|
+
export function parseLevel(name) {
|
|
27
|
+
const v = name?.toLowerCase();
|
|
28
|
+
if (v === 'off')
|
|
29
|
+
return OFF;
|
|
30
|
+
const found = Object.entries(LEVELS).find(([, l]) => l === v);
|
|
31
|
+
return found ? Number(found[0]) : LogLevel.Trace;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A structured logger. Each call prints a log record on stderr, one line in
|
|
35
|
+
* the Encore log format, with the logger's name, the logger's and the call's
|
|
36
|
+
* fields as attributes, and the active span's ids. The SDK core encodes the
|
|
37
|
+
* line; it needs the native library, not the runtime. An attribute named
|
|
38
|
+
* like a reserved key is that field when valid, `raw.<key>` otherwise; one
|
|
39
|
+
* named like a key of the record's exception is `raw.<key>`.
|
|
40
|
+
* Lines are written synchronously; none is lost on `process.exit`.
|
|
41
|
+
*/
|
|
42
|
+
export class Logger {
|
|
43
|
+
level;
|
|
44
|
+
name;
|
|
45
|
+
fields;
|
|
46
|
+
write;
|
|
47
|
+
/** @internal */
|
|
48
|
+
constructor(options) {
|
|
49
|
+
this.level = options.level;
|
|
50
|
+
this.name = options.name;
|
|
51
|
+
this.fields = options.fields ?? {};
|
|
52
|
+
this.write = options.write ?? writeStderr;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns a new logger with the specified level.
|
|
56
|
+
*/
|
|
57
|
+
withLevel(level) {
|
|
58
|
+
return new Logger({ ...this.options(), level });
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Returns a new logger named `name`, the `logger` of its records, with
|
|
62
|
+
* this logger's level and fields.
|
|
63
|
+
*/
|
|
64
|
+
withName(name) {
|
|
65
|
+
return new Logger({ ...this.options(), name });
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns a new logger with the given fields added to the context.
|
|
69
|
+
*/
|
|
70
|
+
with(fields) {
|
|
71
|
+
return new Logger({
|
|
72
|
+
...this.options(),
|
|
73
|
+
fields: { ...this.fields, ...fields },
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Trace logs a message at the trace level.
|
|
78
|
+
*/
|
|
79
|
+
trace(msg, fields) {
|
|
80
|
+
this.log(LogLevel.Trace, msg, fields);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Debug logs a message at the debug level.
|
|
84
|
+
*/
|
|
85
|
+
debug(msg, fields) {
|
|
86
|
+
this.log(LogLevel.Debug, msg, fields);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Info logs a message at the info level.
|
|
90
|
+
*/
|
|
91
|
+
info(msg, fields) {
|
|
92
|
+
this.log(LogLevel.Info, msg, fields);
|
|
93
|
+
}
|
|
94
|
+
warn(errOrMsg, msgOrFields, fields) {
|
|
95
|
+
this.log(LogLevel.Warn, errOrMsg, msgOrFields, fields);
|
|
96
|
+
}
|
|
97
|
+
error(errOrMsg, msgOrFields, fields) {
|
|
98
|
+
this.log(LogLevel.Error, errOrMsg, msgOrFields, fields);
|
|
99
|
+
}
|
|
100
|
+
fatal(errOrMsg, msgOrFields, fields) {
|
|
101
|
+
this.log(LogLevel.Fatal, errOrMsg, msgOrFields, fields);
|
|
102
|
+
}
|
|
103
|
+
options() {
|
|
104
|
+
return {
|
|
105
|
+
level: this.level,
|
|
106
|
+
name: this.name,
|
|
107
|
+
fields: this.fields,
|
|
108
|
+
write: this.write,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
log(level, errOrMsg, msgOrFields, possibleFields) {
|
|
112
|
+
if (level < this.level)
|
|
113
|
+
return;
|
|
114
|
+
let err;
|
|
115
|
+
let msg;
|
|
116
|
+
let fields;
|
|
117
|
+
if (typeof errOrMsg === 'string') {
|
|
118
|
+
// log(msg, fields?)
|
|
119
|
+
msg = errOrMsg;
|
|
120
|
+
fields = msgOrFields;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// log(err, msg, fields?) or log(err, fields?)
|
|
124
|
+
if (errOrMsg) {
|
|
125
|
+
err =
|
|
126
|
+
errOrMsg instanceof Error ? errOrMsg : new Error(String(errOrMsg));
|
|
127
|
+
}
|
|
128
|
+
if (typeof msgOrFields === 'string') {
|
|
129
|
+
msg = msgOrFields;
|
|
130
|
+
fields = possibleFields;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
msg = '';
|
|
134
|
+
fields = msgOrFields;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const span = trace.getSpan(activeContext())?.spanContext();
|
|
138
|
+
this.emit(level, {
|
|
139
|
+
message: msg,
|
|
140
|
+
spanCtx: span && isSpanContextValid(span) ? spanBytes(span) : undefined,
|
|
141
|
+
exceptionType: err?.name,
|
|
142
|
+
exceptionMessage: err?.message,
|
|
143
|
+
exceptionStacktrace: err?.stack,
|
|
144
|
+
attrsJson: attrsJson({ ...this.fields, ...fields }),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Prints a record of `parts` under the logger's name, at or above the
|
|
149
|
+
* logger's level.
|
|
150
|
+
* @internal
|
|
151
|
+
*/
|
|
152
|
+
emit(level, parts) {
|
|
153
|
+
if (level < this.level)
|
|
154
|
+
return;
|
|
155
|
+
try {
|
|
156
|
+
this.write(encode((level - 1) * 4 + 1, this.name || undefined, parts));
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// Logging never throws.
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** A record as a line in the Encore log format; `severity` is the
|
|
164
|
+
* OpenTelemetry severity number. */
|
|
165
|
+
function encode(severity, logger, p) {
|
|
166
|
+
return encodeLog(severity, p.timeUnixMillis, p.message, logger, p.spanCtx, p.exceptionType, p.exceptionMessage, p.exceptionStacktrace, p.codeFunction, p.codeFile, p.codeLine, p.codeColumn, p.runtimeTarget, p.attrsJson);
|
|
167
|
+
}
|
|
168
|
+
/** `span` in its 25-byte wire form: trace id, span id, flags. */
|
|
169
|
+
function spanBytes(span) {
|
|
170
|
+
const b = Buffer.allocUnsafe(25);
|
|
171
|
+
b.write(span.traceId, 0, 16, 'hex');
|
|
172
|
+
b.write(span.spanId, 16, 8, 'hex');
|
|
173
|
+
b[24] = span.traceFlags & 0xff;
|
|
174
|
+
return b;
|
|
175
|
+
}
|
|
176
|
+
/** `attrs` as a JSON object: bigints as strings, errors as their string,
|
|
177
|
+
* `undefined` left out; a value JSON cannot hold (a cycle) as its string. */
|
|
178
|
+
function attrsJson(attrs) {
|
|
179
|
+
try {
|
|
180
|
+
return JSON.stringify(attrs, replacer);
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
const out = {};
|
|
184
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
185
|
+
try {
|
|
186
|
+
JSON.stringify(v, replacer);
|
|
187
|
+
out[k] = v;
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
out[k] = String(v);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return JSON.stringify(out, replacer);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function replacer(_key, v) {
|
|
197
|
+
if (typeof v === 'bigint')
|
|
198
|
+
return v.toString();
|
|
199
|
+
if (v instanceof Error)
|
|
200
|
+
return String(v);
|
|
201
|
+
return v;
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../log/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAE,KAAK,EAAmB,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAC,WAAW,EAAC,MAAM,UAAU,CAAC;AAiBrC,MAAM,CAAN,IAAY,QAOX;AAPD,WAAY,QAAQ;IAClB,yCAAS,CAAA;IACT,yCAAK,CAAA;IACL,uCAAI,CAAA;IACJ,uCAAI,CAAA;IACJ,yCAAK,CAAA;I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CAAC,CAAC,QAAQ,EAAE,CAAC;IAC/C,IAAI,CAAC,YAAY,KAAK;QAAE,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;IACzC,OAAO,CAAC,CAAC;AACX,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { type Logger } from './logger.js';
|
|
3
|
+
/** One runtime log line (the napi `RuntimeLogLine`). */
|
|
4
|
+
export interface RuntimeLine {
|
|
5
|
+
/** 1 ERROR, 2 WARN, 3 INFO, 4 DEBUG, 5 TRACE. */
|
|
6
|
+
level: number;
|
|
7
|
+
/** The module path, or `file:line`, the line comes from. */
|
|
8
|
+
target: string;
|
|
9
|
+
message: string;
|
|
10
|
+
/** A JSON object. */
|
|
11
|
+
fields: string;
|
|
12
|
+
/** 25 bytes: trace id, span id, flags. */
|
|
13
|
+
spanCtx?: Buffer;
|
|
14
|
+
}
|
|
15
|
+
/** Prints a runtime line through `logger`'s level and writer, under the
|
|
16
|
+
* runtime's logger: its target and fields as attributes, its span's ids. */
|
|
17
|
+
export declare function runtimeLinePrinter(logger: Logger): (line: RuntimeLine) => void;
|
|
18
|
+
/** Prints runtime lines through the default logger. */
|
|
19
|
+
export declare const printRuntimeLine: (line: RuntimeLine) => void;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import log from './index.js';
|
|
2
|
+
import { LogLevel } from './logger.js';
|
|
3
|
+
const LEVELS = {
|
|
4
|
+
1: LogLevel.Error,
|
|
5
|
+
2: LogLevel.Warn,
|
|
6
|
+
3: LogLevel.Info,
|
|
7
|
+
4: LogLevel.Debug,
|
|
8
|
+
5: LogLevel.Trace,
|
|
9
|
+
};
|
|
10
|
+
/** Prints a runtime line through `logger`'s level and writer, under the
|
|
11
|
+
* runtime's logger: its target and fields as attributes, its span's ids. */
|
|
12
|
+
export function runtimeLinePrinter(logger) {
|
|
13
|
+
return line => logger.emit(LEVELS[line.level] ?? LogLevel.Info, {
|
|
14
|
+
message: line.message,
|
|
15
|
+
spanCtx: line.spanCtx,
|
|
16
|
+
runtimeTarget: line.target,
|
|
17
|
+
attrsJson: line.fields,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/** Prints runtime lines through the default logger. */
|
|
21
|
+
export const printRuntimeLine = runtimeLinePrinter(log);
|
|
22
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../log/runtime.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,SAAS,CAAC;AAC1B,OAAO,EAAC,QAAQ,EAAc,MAAM,UAAU,CAAC;AAe/C,MAAM,MAAM,GAA6B;IACvC,CAAC,EAAE,QAAQ,CAAC,KAAK;IACjB,CAAC,EAAE,QAAQ,CAAC,IAAI;IAChB,CAAC,EAAE,QAAQ,CAAC,IAAI;IAChB,CAAC,EAAE,QAAQ,CAAC,KAAK;IACjB,CAAC,EAAE,QAAQ,CAAC,KAAK;CAClB,CAAC;AAEF;4EAC4E;AAC5E,MAAM,UAAU,kBAAkB,CAChC,MAAc;IAEd,OAAO,IAAI,CAAC,EAAE,CACZ,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE;QAC/C,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,aAAa,EAAE,IAAI,CAAC,MAAM;QAC1B,SAAS,EAAE,IAAI,CAAC,MAAM;KACvB,CAAC,CAAC;AACP,CAAC;AAED,uDAAuD;AACvD,MAAM,CAAC,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes `buf` to stderr synchronously, so no line is lost on
|
|
3
|
+
* `process.exit` or a crash. `process.stderr.write` is asynchronous for pipes
|
|
4
|
+
* on POSIX under Node, and the process manager reads stderr through one.
|
|
5
|
+
* When the pipe is full (EAGAIN on a non-blocking descriptor) the write is
|
|
6
|
+
* retried, blocking the caller like a blocking write would; other errors
|
|
7
|
+
* drop the line.
|
|
8
|
+
*/
|
|
9
|
+
export declare function writeStderr(buf: Uint8Array): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { writeSync } from 'node:fs';
|
|
2
|
+
const STDERR = 2;
|
|
3
|
+
const sleep = new Int32Array(new SharedArrayBuffer(4));
|
|
4
|
+
/**
|
|
5
|
+
* Writes `buf` to stderr synchronously, so no line is lost on
|
|
6
|
+
* `process.exit` or a crash. `process.stderr.write` is asynchronous for pipes
|
|
7
|
+
* on POSIX under Node, and the process manager reads stderr through one.
|
|
8
|
+
* When the pipe is full (EAGAIN on a non-blocking descriptor) the write is
|
|
9
|
+
* retried, blocking the caller like a blocking write would; other errors
|
|
10
|
+
* drop the line.
|
|
11
|
+
*/
|
|
12
|
+
export function writeStderr(buf) {
|
|
13
|
+
let off = 0;
|
|
14
|
+
while (off < buf.length) {
|
|
15
|
+
try {
|
|
16
|
+
off += writeSync(STDERR, buf, off);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
if (err.code !== 'EAGAIN')
|
|
20
|
+
return;
|
|
21
|
+
Atomics.wait(sleep, 0, 0, 1);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=stderr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stderr.js","sourceRoot":"","sources":["../../log/stderr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AAElC,MAAM,MAAM,GAAG,CAAC,CAAC;AACjB,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,IAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvD;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CAAC,GAAe;IACzC,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,OAAO,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QACxB,IAAI,CAAC;YACH,GAAG,IAAI,SAAS,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;QACrC,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAK,GAA6B,CAAC,IAAI,KAAK,QAAQ;gBAAE,OAAO;YAC7D,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;AACH,CAAC"}
|