@trebired/logger 1.1.2 → 2.0.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/CHANGELOG.md +21 -0
- package/README.md +177 -14
- package/dist/browser/console_transport.d.ts +5 -0
- package/dist/browser/console_transport.d.ts.map +1 -0
- package/dist/browser/console_transport.js +51 -0
- package/dist/browser/console_transport.js.map +1 -0
- package/dist/browser/create_log.d.ts +4 -0
- package/dist/browser/create_log.d.ts.map +1 -0
- package/dist/browser/create_log.js +234 -0
- package/dist/browser/create_log.js.map +1 -0
- package/dist/browser/index.d.ts +4 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +3 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/react.d.ts +30 -0
- package/dist/browser/react.d.ts.map +1 -0
- package/dist/browser/react.js +44 -0
- package/dist/browser/react.js.map +1 -0
- package/dist/constants.d.ts +2 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -1
- package/dist/constants.js.map +1 -1
- package/dist/core/create_log.d.ts.map +1 -1
- package/dist/core/create_log.js +111 -137
- package/dist/core/create_log.js.map +1 -1
- package/dist/core/shared.d.ts +31 -0
- package/dist/core/shared.d.ts.map +1 -0
- package/dist/core/shared.js +144 -0
- package/dist/core/shared.js.map +1 -0
- package/dist/format/console.d.ts +2 -2
- package/dist/format/console.d.ts.map +1 -1
- package/dist/format/console.js +2 -17
- package/dist/format/console.js.map +1 -1
- package/dist/format/options.d.ts +4 -0
- package/dist/format/options.d.ts.map +1 -0
- package/dist/format/options.js +19 -0
- package/dist/format/options.js.map +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/storage/names.d.ts +10 -3
- package/dist/storage/names.d.ts.map +1 -1
- package/dist/storage/names.js +76 -33
- package/dist/storage/names.js.map +1 -1
- package/dist/storage/options.d.ts.map +1 -1
- package/dist/storage/options.js +3 -1
- package/dist/storage/options.js.map +1 -1
- package/dist/storage/partitions.d.ts +30 -0
- package/dist/storage/partitions.d.ts.map +1 -0
- package/dist/storage/partitions.js +564 -0
- package/dist/storage/partitions.js.map +1 -0
- package/dist/storage/query.d.ts +8 -4
- package/dist/storage/query.d.ts.map +1 -1
- package/dist/storage/query.js +135 -28
- package/dist/storage/query.js.map +1 -1
- package/dist/storage/retention.d.ts.map +1 -1
- package/dist/storage/retention.js +51 -2
- package/dist/storage/retention.js.map +1 -1
- package/dist/storage/walk.d.ts.map +1 -1
- package/dist/storage/walk.js +65 -9
- package/dist/storage/walk.js.map +1 -1
- package/dist/storage/write.d.ts +1 -0
- package/dist/storage/write.d.ts.map +1 -1
- package/dist/storage/write.js +12 -1
- package/dist/storage/write.js.map +1 -1
- package/dist/stream/index.d.ts +11 -3
- package/dist/stream/index.d.ts.map +1 -1
- package/dist/stream/index.js +40 -4
- package/dist/stream/index.js.map +1 -1
- package/dist/types.d.ts +189 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +24 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,YAAY,EACV,mBAAmB,EACnB,8BAA8B,EAC9B,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,uBAAuB,GACxB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { Component } from "react";
|
|
2
|
+
import type { BrowserLogInstance } from "../types.js";
|
|
3
|
+
type LogProviderProps = {
|
|
4
|
+
log: BrowserLogInstance;
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
};
|
|
7
|
+
type LogErrorBoundaryProps = {
|
|
8
|
+
log?: BrowserLogInstance;
|
|
9
|
+
group?: string;
|
|
10
|
+
metadata?: Record<string, unknown>;
|
|
11
|
+
fallback?: React.ReactNode | ((error: Error) => React.ReactNode);
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
};
|
|
14
|
+
type LogErrorBoundaryState = {
|
|
15
|
+
error: Error | null;
|
|
16
|
+
};
|
|
17
|
+
declare const LogContext: React.Context<BrowserLogInstance>;
|
|
18
|
+
declare function LogProvider({ log, children }: LogProviderProps): React.FunctionComponentElement<React.ProviderProps<BrowserLogInstance>>;
|
|
19
|
+
declare function useLog(groupName?: string): BrowserLogInstance | Record<string, any>;
|
|
20
|
+
declare class LogErrorBoundary extends Component<LogErrorBoundaryProps, LogErrorBoundaryState> {
|
|
21
|
+
static contextType: React.Context<BrowserLogInstance>;
|
|
22
|
+
context: React.ContextType<typeof LogContext>;
|
|
23
|
+
state: LogErrorBoundaryState;
|
|
24
|
+
static getDerivedStateFromError(error: Error): LogErrorBoundaryState;
|
|
25
|
+
componentDidCatch(error: Error, info: React.ErrorInfo): void;
|
|
26
|
+
render(): React.ReactNode;
|
|
27
|
+
}
|
|
28
|
+
export { LogErrorBoundary, LogProvider, useLog };
|
|
29
|
+
export type { LogErrorBoundaryProps, LogProviderProps };
|
|
30
|
+
//# sourceMappingURL=react.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/browser/react.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,SAAS,EAA6B,MAAM,OAAO,CAAC;AAEpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAA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AM,EAAE,CAAC;AACjD,YAAY,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React, { Component, createContext, useContext } from "react";
|
|
2
|
+
const LogContext = createContext(null);
|
|
3
|
+
function LogProvider({ log, children }) {
|
|
4
|
+
return React.createElement(LogContext.Provider, { value: log }, children);
|
|
5
|
+
}
|
|
6
|
+
function useLog(groupName) {
|
|
7
|
+
const log = useContext(LogContext);
|
|
8
|
+
if (!log)
|
|
9
|
+
throw new Error("missing-log-provider");
|
|
10
|
+
return groupName ? log.group(groupName) : log;
|
|
11
|
+
}
|
|
12
|
+
class LogErrorBoundary extends Component {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.state = {
|
|
16
|
+
error: null,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
static getDerivedStateFromError(error) {
|
|
20
|
+
return {
|
|
21
|
+
error,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
componentDidCatch(error, info) {
|
|
25
|
+
const logger = this.props.log || this.context;
|
|
26
|
+
if (!logger)
|
|
27
|
+
return;
|
|
28
|
+
logger.logError(error, {
|
|
29
|
+
...(this.props.metadata || {}),
|
|
30
|
+
group: this.props.group || "react.error_boundary",
|
|
31
|
+
componentStack: info.componentStack,
|
|
32
|
+
}, "react");
|
|
33
|
+
}
|
|
34
|
+
render() {
|
|
35
|
+
if (!this.state.error)
|
|
36
|
+
return this.props.children;
|
|
37
|
+
if (typeof this.props.fallback === "function")
|
|
38
|
+
return this.props.fallback(this.state.error);
|
|
39
|
+
return this.props.fallback ?? null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
LogErrorBoundary.contextType = LogContext;
|
|
43
|
+
export { LogErrorBoundary, LogProvider, useLog };
|
|
44
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"react.js","sourceRoot":"","sources":["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CAAC;IAED,MAAM;QACJ,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;QAClD,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,KAAK,UAAU;YAAE,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5F,OAAO,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,IAAI,CAAC;IACrC,CAAC;;AAhCM,4BAAW,GAAG,UAAU,AAAb,CAAc;AAmClC,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC"}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { LogLevelConfig } from "./types.js";
|
|
2
2
|
declare const TOP_LEVEL = "top-level";
|
|
3
|
+
declare const PARTITION_MARKER_FILE = ".trebired-partition.json";
|
|
3
4
|
declare const DEFAULT_LEVELS: Record<string, LogLevelConfig>;
|
|
4
5
|
declare const RESERVED_METADATA_KEYS: Set<string>;
|
|
5
6
|
declare const DEFAULT_SENSITIVE_KEYS: Set<string>;
|
|
6
|
-
export { DEFAULT_LEVELS, DEFAULT_SENSITIVE_KEYS, RESERVED_METADATA_KEYS, TOP_LEVEL };
|
|
7
|
+
export { DEFAULT_LEVELS, DEFAULT_SENSITIVE_KEYS, PARTITION_MARKER_FILE, RESERVED_METADATA_KEYS, TOP_LEVEL };
|
|
7
8
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,QAAA,MAAM,SAAS,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,QAAA,MAAM,SAAS,cAAc,CAAC;AAC9B,QAAA,MAAM,qBAAqB,6BAA6B,CAAC;AAEzD,QAAA,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAOjD,CAAC;AAEH,QAAA,MAAM,sBAAsB,aAuB1B,CAAC;AAEH,QAAA,MAAM,sBAAsB,aAY1B,CAAC;AAEH,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,SAAS,EAAE,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const TOP_LEVEL = "top-level";
|
|
2
|
+
const PARTITION_MARKER_FILE = ".trebired-partition.json";
|
|
2
3
|
const DEFAULT_LEVELS = Object.freeze({
|
|
3
4
|
debug: { weight: 10, label: "DEBUG", color: "#b7c063", stream: "stdout", showStack: false, bold: false },
|
|
4
5
|
info: { weight: 20, label: "INFO", color: "#2958ea", stream: "stdout", showStack: false, bold: false },
|
|
@@ -12,6 +13,8 @@ const RESERVED_METADATA_KEYS = new Set([
|
|
|
12
13
|
"configKey",
|
|
13
14
|
"config_key",
|
|
14
15
|
"deployment_type",
|
|
16
|
+
"deployment",
|
|
17
|
+
"partition",
|
|
15
18
|
"group",
|
|
16
19
|
"groupKey",
|
|
17
20
|
"group_label",
|
|
@@ -42,5 +45,5 @@ const DEFAULT_SENSITIVE_KEYS = new Set([
|
|
|
42
45
|
"token",
|
|
43
46
|
"access_token",
|
|
44
47
|
]);
|
|
45
|
-
export { DEFAULT_LEVELS, DEFAULT_SENSITIVE_KEYS, RESERVED_METADATA_KEYS, TOP_LEVEL };
|
|
48
|
+
export { DEFAULT_LEVELS, DEFAULT_SENSITIVE_KEYS, PARTITION_MARKER_FILE, RESERVED_METADATA_KEYS, TOP_LEVEL };
|
|
46
49
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,MAAM,SAAS,GAAG,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,MAAM,qBAAqB,GAAG,0BAA0B,CAAC;AAEzD,MAAM,cAAc,GAAmC,MAAM,CAAC,MAAM,CAAC;IACnE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE;IACxG,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE;IACtG,OAAO,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE;IAC5G,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE;IACrG,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE;IACtG,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE;CACvG,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC;IACrC,eAAe;IACf,WAAW;IACX,YAAY;IACZ,iBAAiB;IACjB,YAAY;IACZ,WAAW;IACX,OAAO;IACP,UAAU;IACV,aAAa;IACb,YAAY;IACZ,KAAK;IACL,eAAe;IACf,SAAS;IACT,UAAU;IACV,MAAM;IACN,aAAa;IACb,YAAY;IACZ,aAAa;IACb,QAAQ;IACR,WAAW;IACX,UAAU;IACV,WAAW;CACZ,CAAC,CAAC;AAEH,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC;IACrC,SAAS;IACT,QAAQ;IACR,eAAe;IACf,QAAQ;IACR,QAAQ;IACR,UAAU;IACV,KAAK;IACL,eAAe;IACf,QAAQ;IACR,OAAO;IACP,cAAc;CACf,CAAC,CAAC;AAEH,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create_log.d.ts","sourceRoot":"","sources":["../../src/core/create_log.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create_log.d.ts","sourceRoot":"","sources":["../../src/core/create_log.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAYjE,iBAAS,SAAS,CAAC,OAAO,GAAE,gBAAqB,GAAG,WAAW,CAkJ9D;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
package/dist/core/create_log.js
CHANGED
|
@@ -1,71 +1,31 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { createCommonLogger } from "./shared.js";
|
|
3
|
+
import { formatConsole, writeConsole } from "../format/console.js";
|
|
4
|
+
import { normalizeConsoleOptions } from "../format/options.js";
|
|
5
|
+
import { normalizeLevels } from "../levels/index.js";
|
|
6
6
|
import { buildRequestMiddleware } from "../middleware/request.js";
|
|
7
7
|
import { logStream } from "../stream/index.js";
|
|
8
|
-
import {
|
|
8
|
+
import { normalizePartitionKey, sanitizePartitionName } from "../storage/names.js";
|
|
9
|
+
import { getPartitionInfo as getStoredPartitionInfo, listPartitions as listStoredPartitions, mergePartition, renamePartition, touchPartitionMarkerSync, } from "../storage/partitions.js";
|
|
10
|
+
import { getLogsForDir } from "../storage/query.js";
|
|
9
11
|
import { normalizeRetentionOptions, normalizeWriteOptions } from "../storage/options.js";
|
|
10
12
|
import { FileWriter } from "../storage/write.js";
|
|
11
13
|
import { normalizeTimeZone } from "../utils/datetime.js";
|
|
12
14
|
import { maybeShowNodeRuntimeNotice } from "../utils/runtime.js";
|
|
13
|
-
import {
|
|
15
|
+
import { toString } from "../utils/values.js";
|
|
14
16
|
let packageGreetingShown = false;
|
|
15
17
|
function safeResolveDir(value) {
|
|
16
18
|
const raw = toString(value);
|
|
17
19
|
return raw ? path.resolve(raw) : "";
|
|
18
20
|
}
|
|
19
|
-
function buildOrigin(source, instance = null) {
|
|
20
|
-
const src = toString(source) || "app";
|
|
21
|
-
const inst = instance == null ? null : String(instance);
|
|
22
|
-
return {
|
|
23
|
-
source: src,
|
|
24
|
-
instance: inst || null,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
function parseCallArguments(argsLike, fallbackGroup) {
|
|
28
|
-
const args = Array.isArray(argsLike) ? argsLike : Array.from(argsLike || []);
|
|
29
|
-
const hasExplicitGroup = typeof args[0] === "string" && typeof args[1] === "string";
|
|
30
|
-
return {
|
|
31
|
-
group: hasExplicitGroup ? args[0] : fallbackGroup,
|
|
32
|
-
message: hasExplicitGroup ? args[1] : String(args[0] ?? ""),
|
|
33
|
-
metadata: hasExplicitGroup ? asObject(args[2]) : asObject(args[1]),
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function shouldKeepSample(entry, sample) {
|
|
37
|
-
if (sample == null)
|
|
38
|
-
return true;
|
|
39
|
-
if (typeof sample === "number") {
|
|
40
|
-
if (!Number.isFinite(sample))
|
|
41
|
-
return true;
|
|
42
|
-
if (sample <= 0)
|
|
43
|
-
return false;
|
|
44
|
-
if (sample >= 1)
|
|
45
|
-
return true;
|
|
46
|
-
return Math.random() < sample;
|
|
47
|
-
}
|
|
48
|
-
if (typeof sample === "function") {
|
|
49
|
-
try {
|
|
50
|
-
return sample(entry) === true;
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
21
|
function createLog(options = {}) {
|
|
59
22
|
const cfg = options && typeof options === "object" ? options : {};
|
|
60
23
|
maybeShowNodeRuntimeNotice(cfg.quiet);
|
|
61
24
|
const levels = normalizeLevels(cfg.levels);
|
|
62
|
-
const threshold = minLevelWeight(cfg.minLevel, levels);
|
|
63
25
|
const consoleOptions = normalizeConsoleOptions(cfg.console);
|
|
64
26
|
const timeZone = normalizeTimeZone(cfg.timeZone);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
let loggingEnabled = true;
|
|
68
|
-
let closed = false;
|
|
27
|
+
let activePartition = normalizePartitionKey(cfg.partition) || null;
|
|
28
|
+
let activeTemporary = cfg.temporaryPartition === true;
|
|
69
29
|
const writer = new FileWriter({
|
|
70
30
|
dir: safeResolveDir(cfg.dir),
|
|
71
31
|
save: typeof cfg.save === "boolean" ? cfg.save : Boolean(toString(cfg.dir)),
|
|
@@ -74,112 +34,126 @@ function createLog(options = {}) {
|
|
|
74
34
|
timeZone,
|
|
75
35
|
onError: (message) => writeConsole("stderr", message),
|
|
76
36
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return;
|
|
80
|
-
const level = normalizeLevel(levelInput, levels);
|
|
81
|
-
const levelConfig = levels[level] || levels.info;
|
|
82
|
-
if (levelConfig.weight < threshold)
|
|
83
|
-
return;
|
|
84
|
-
const rawMetadata = asObject(metadataInput);
|
|
85
|
-
const recordedAt = toString(rawMetadata.__recorded_at) || new Date().toISOString();
|
|
86
|
-
const metadata = prepareMetadata(rawMetadata, cfg.serializers, cfg.redact);
|
|
87
|
-
const group = normGroup(groupInput || defaultGroup).key;
|
|
88
|
-
const message = typeof messageInput === "string" ? messageInput : String(messageInput ?? "");
|
|
89
|
-
const originSource = originInput && originInput.source ? originInput.source : defaultSource;
|
|
90
|
-
const originInstance = originInput && Object.prototype.hasOwnProperty.call(originInput, "instance") ? originInput.instance : null;
|
|
91
|
-
const entry = {
|
|
92
|
-
recorded_at: recordedAt,
|
|
93
|
-
level,
|
|
94
|
-
group,
|
|
95
|
-
message,
|
|
96
|
-
origin: buildOrigin(originSource, originInstance),
|
|
97
|
-
};
|
|
98
|
-
if (Object.keys(metadata).length)
|
|
99
|
-
entry.metadata = metadata;
|
|
100
|
-
if (!shouldKeepSample(entry, cfg.sample))
|
|
101
|
-
return;
|
|
102
|
-
if (consoleOptions.enabled)
|
|
103
|
-
writeConsole(levelConfig.stream, formatConsole(entry, levelConfig, consoleOptions, timeZone));
|
|
104
|
-
writer.write(entry);
|
|
105
|
-
try {
|
|
106
|
-
logStream.emit("log", entry, { dir: writer.getDir() });
|
|
107
|
-
}
|
|
108
|
-
catch { }
|
|
37
|
+
if (activePartition && activeTemporary && writer.isSavingEnabled() && writer.getDir()) {
|
|
38
|
+
touchPartitionMarkerSync(writer.getDir(), activePartition, { temporary: true });
|
|
109
39
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const child = {};
|
|
125
|
-
for (const level of Object.keys(levels)) {
|
|
126
|
-
child[level] = (message, metadata) => emit(level, boundGroup, message, { ...asObject(metadata), ...extra }, originInput);
|
|
40
|
+
const { api: baseApi } = createCommonLogger({
|
|
41
|
+
levels,
|
|
42
|
+
minLevel: cfg.minLevel,
|
|
43
|
+
defaultSource: cfg.source,
|
|
44
|
+
serializers: cfg.serializers,
|
|
45
|
+
redact: cfg.redact,
|
|
46
|
+
sample: cfg.sample,
|
|
47
|
+
getPartition: () => activePartition,
|
|
48
|
+
writeEntry(entry, levelConfig) {
|
|
49
|
+
if (consoleOptions.enabled)
|
|
50
|
+
writeConsole(levelConfig.stream, formatConsole(entry, levelConfig, consoleOptions, timeZone));
|
|
51
|
+
writer.write(entry);
|
|
52
|
+
try {
|
|
53
|
+
logStream.emit("log", entry, { runtime: "server", dir: writer.getDir() });
|
|
127
54
|
}
|
|
128
|
-
|
|
129
|
-
};
|
|
130
|
-
return grouped;
|
|
131
|
-
}
|
|
132
|
-
const api = {
|
|
133
|
-
group(groupName) {
|
|
134
|
-
return bindGroup(groupName || defaultGroup);
|
|
55
|
+
catch { }
|
|
135
56
|
},
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
source: toString(source) || defaultSource,
|
|
139
|
-
instance: instance == null ? null : String(instance),
|
|
140
|
-
};
|
|
141
|
-
return bindGroup(groupName || defaultGroup, originInput);
|
|
57
|
+
flush() {
|
|
58
|
+
return writer.flush();
|
|
142
59
|
},
|
|
143
|
-
|
|
144
|
-
|
|
60
|
+
close() {
|
|
61
|
+
return writer.close();
|
|
145
62
|
},
|
|
63
|
+
getStats() {
|
|
64
|
+
return writer.getStats();
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
const api = baseApi;
|
|
68
|
+
Object.assign(api, {
|
|
146
69
|
getDir() {
|
|
147
70
|
return writer.getDir();
|
|
148
71
|
},
|
|
149
72
|
setDir(nextDir) {
|
|
150
73
|
writer.setDir(safeResolveDir(nextDir));
|
|
74
|
+
if (activePartition && activeTemporary && writer.isSavingEnabled() && writer.getDir()) {
|
|
75
|
+
touchPartitionMarkerSync(writer.getDir(), activePartition, { temporary: true });
|
|
76
|
+
}
|
|
151
77
|
},
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
78
|
+
getPartition() {
|
|
79
|
+
return activePartition;
|
|
80
|
+
},
|
|
81
|
+
async setPartition(partition, options) {
|
|
82
|
+
const hasTemporary = Object.prototype.hasOwnProperty.call(options || {}, "temporary");
|
|
83
|
+
const nextPartition = partition == null ? null : sanitizePartitionName(String(partition));
|
|
84
|
+
const samePartition = nextPartition === activePartition;
|
|
85
|
+
const nextTemporary = nextPartition
|
|
86
|
+
? (hasTemporary ? options?.temporary === true : (samePartition ? activeTemporary : false))
|
|
87
|
+
: false;
|
|
88
|
+
await writer.flush();
|
|
89
|
+
activePartition = nextPartition;
|
|
90
|
+
activeTemporary = nextTemporary;
|
|
91
|
+
if (activePartition && writer.isSavingEnabled() && writer.getDir()) {
|
|
92
|
+
touchPartitionMarkerSync(writer.getDir(), activePartition, {
|
|
93
|
+
temporary: activeTemporary,
|
|
94
|
+
});
|
|
160
95
|
}
|
|
161
|
-
emit("error", groupName, String(error), meta, { source: originSource });
|
|
162
96
|
},
|
|
163
|
-
async
|
|
97
|
+
async promotePartition(partition, options) {
|
|
98
|
+
if (!activePartition)
|
|
99
|
+
throw new Error("partition-not-set");
|
|
100
|
+
const nextPartition = sanitizePartitionName(partition);
|
|
164
101
|
await writer.flush();
|
|
165
|
-
|
|
102
|
+
if (!writer.isSavingEnabled() || !writer.getDir()) {
|
|
103
|
+
activePartition = nextPartition;
|
|
104
|
+
activeTemporary = false;
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (nextPartition === activePartition) {
|
|
108
|
+
touchPartitionMarkerSync(writer.getDir(), nextPartition, { temporary: false });
|
|
109
|
+
activeTemporary = false;
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const sourceInfo = await getStoredPartitionInfo(writer.getDir(), activePartition);
|
|
113
|
+
const targetInfo = await getStoredPartitionInfo(writer.getDir(), nextPartition);
|
|
114
|
+
if (!sourceInfo) {
|
|
115
|
+
if (targetInfo && options?.merge !== true)
|
|
116
|
+
throw new Error(`partition-already-exists: ${nextPartition}`);
|
|
117
|
+
}
|
|
118
|
+
else if (targetInfo) {
|
|
119
|
+
if (options?.merge !== true)
|
|
120
|
+
throw new Error(`partition-already-exists: ${nextPartition}`);
|
|
121
|
+
await mergePartition(writer.getDir(), { from: activePartition, to: nextPartition });
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
await renamePartition(writer.getDir(), { from: activePartition, to: nextPartition });
|
|
125
|
+
}
|
|
126
|
+
touchPartitionMarkerSync(writer.getDir(), nextPartition, { temporary: false });
|
|
127
|
+
activePartition = nextPartition;
|
|
128
|
+
activeTemporary = false;
|
|
166
129
|
},
|
|
167
|
-
|
|
168
|
-
return writer.
|
|
130
|
+
async listPartitions() {
|
|
131
|
+
return listStoredPartitions(writer.getDir());
|
|
169
132
|
},
|
|
170
|
-
async
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
133
|
+
async getPartitionInfo(partition) {
|
|
134
|
+
const target = partition == null ? activePartition : sanitizePartitionName(partition);
|
|
135
|
+
if (!target)
|
|
136
|
+
return null;
|
|
137
|
+
return getStoredPartitionInfo(writer.getDir(), target);
|
|
175
138
|
},
|
|
176
|
-
|
|
177
|
-
|
|
139
|
+
async getAllLogs(options) {
|
|
140
|
+
await writer.flush();
|
|
141
|
+
const query = {
|
|
142
|
+
...(options || {}),
|
|
143
|
+
levels,
|
|
144
|
+
};
|
|
145
|
+
if (Object.prototype.hasOwnProperty.call(options || {}, "partition"))
|
|
146
|
+
query.partition = options?.partition ?? null;
|
|
147
|
+
else if (activePartition)
|
|
148
|
+
query.partition = activePartition;
|
|
149
|
+
return getLogsForDir(writer.getDir(), query);
|
|
150
|
+
},
|
|
151
|
+
async getAllLogsAcrossPartitions(options) {
|
|
152
|
+
await writer.flush();
|
|
153
|
+
return getLogsForDir(writer.getDir(), { ...(options || {}), acrossPartitions: true, levels });
|
|
178
154
|
},
|
|
179
|
-
};
|
|
155
|
+
});
|
|
180
156
|
api.requestLogger = buildRequestMiddleware(api, cfg.request);
|
|
181
|
-
for (const level of Object.keys(levels))
|
|
182
|
-
api[level] = logWith(level);
|
|
183
157
|
if (cfg.quiet !== true && !packageGreetingShown) {
|
|
184
158
|
packageGreetingShown = true;
|
|
185
159
|
api.success("logger.loader", "@trebired/logger initialized");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create_log.js","sourceRoot":"","sources":["../../src/core/create_log.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"create_log.js","sourceRoot":"","sources":["../../src/core/create_log.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AACnF,OAAO,EACL,gBAAgB,IAAI,sBAAsB,EAC1C,cAAc,IAAI,oBAAoB,EACtC,cAAc,EACd,eAAe,EACf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P = "default";
|
|
3
|
+
type CommonLoggerOptions<TStats> = {
|
|
4
|
+
levels: Record<string, LogLevelConfig>;
|
|
5
|
+
minLevel?: string | number;
|
|
6
|
+
defaultSource?: string;
|
|
7
|
+
defaultGroup?: string;
|
|
8
|
+
defaultMetadata?: Record<string, unknown>;
|
|
9
|
+
serializers?: Record<string, (value: unknown) => unknown>;
|
|
10
|
+
redact?: RedactOptions;
|
|
11
|
+
sample?: number | ((entry: LogEntry) => boolean);
|
|
12
|
+
getPartition?: () => string | null;
|
|
13
|
+
writeEntry: (entry: LogEntry, levelConfig: LogLevelConfig) => void;
|
|
14
|
+
flush: () => Promise<void>;
|
|
15
|
+
close: () => Promise<void>;
|
|
16
|
+
getStats: () => TStats;
|
|
17
|
+
};
|
|
18
|
+
declare function buildOrigin(source: unknown, instance?: unknown): LogOrigin;
|
|
19
|
+
declare function parseCallArguments(argsLike: IArguments | unknown[], fallbackGroup: string): {
|
|
20
|
+
group: any;
|
|
21
|
+
message: any;
|
|
22
|
+
metadata: Record<string, unknown>;
|
|
23
|
+
};
|
|
24
|
+
declare function shouldKeepSample(entry: LogEntry, sample: CommonLoggerOptions<unknown>["sample"]): boolean;
|
|
25
|
+
declare function createCommonLogger<TStats>(options: CommonLoggerOptions<TStats>): {
|
|
26
|
+
api: Record<string, any>;
|
|
27
|
+
emit: (levelInput: string, groupInput: unknown, messageInput: unknown, metadataInput?: unknown, originInput?: Partial<LogOrigin>) => void;
|
|
28
|
+
};
|
|
29
|
+
export { DEFAULT_GROUP, buildOrigin, createCommonLogger, parseCallArguments, shouldKeepSample };
|
|
30
|
+
export type { CommonLoggerOptions };
|
|
31
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/core/shared.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,aA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