@peerbit/logger 1.0.4-fd84d12 → 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/dist/src/index.d.ts +1 -14
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -64
- package/dist/src/index.js.map +1 -1
- package/package.json +6 -6
- package/src/index.ts +1 -85
package/dist/src/index.d.ts
CHANGED
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Safely read an env var from:
|
|
4
|
-
* - Node: process.env
|
|
5
|
-
* - Webpack/CRA (browser/worker): globalThis.process.env (if defined by bundler)
|
|
6
|
-
* - Vite (browser/worker): import.meta.env
|
|
7
|
-
*/
|
|
8
|
-
export declare const getEnv: (key: string) => string | undefined;
|
|
9
|
-
export declare const getLogLevel: () => LogLevel | undefined;
|
|
10
|
-
declare const logger: (options?: {
|
|
11
|
-
module?: string;
|
|
12
|
-
level?: LogLevel;
|
|
13
|
-
}) => import("pino").Logger<never>;
|
|
14
|
-
export { logger };
|
|
1
|
+
export * from "@libp2p/logger";
|
|
15
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,65 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
// Robust Node detection (true only in Node.js)
|
|
3
|
-
const isNode = typeof process !== "undefined" && !!process.versions?.node;
|
|
4
|
-
/**
|
|
5
|
-
* Safely read an env var from:
|
|
6
|
-
* - Node: process.env
|
|
7
|
-
* - Webpack/CRA (browser/worker): globalThis.process.env (if defined by bundler)
|
|
8
|
-
* - Vite (browser/worker): import.meta.env
|
|
9
|
-
*/
|
|
10
|
-
export const getEnv = (key) => {
|
|
11
|
-
if (isNode) {
|
|
12
|
-
return process.env?.[key];
|
|
13
|
-
}
|
|
14
|
-
// Some bundlers (Webpack/CRA) inject a process shim
|
|
15
|
-
const g = typeof globalThis !== "undefined" ? globalThis : {};
|
|
16
|
-
if (g.process?.env && typeof g.process.env[key] !== "undefined") {
|
|
17
|
-
return g.process.env[key];
|
|
18
|
-
}
|
|
19
|
-
// Vite exposes import.meta.env
|
|
20
|
-
let metaEnv;
|
|
21
|
-
try {
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
23
|
-
// @ts-ignore - import.meta may not exist in TS/node type context
|
|
24
|
-
metaEnv = import.meta?.env;
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
// ignore if not supported
|
|
28
|
-
}
|
|
29
|
-
if (metaEnv && typeof metaEnv[key] !== "undefined") {
|
|
30
|
-
return metaEnv[key];
|
|
31
|
-
}
|
|
32
|
-
return undefined;
|
|
33
|
-
};
|
|
34
|
-
export const getLogLevel = () => {
|
|
35
|
-
const level = getEnv("LOG_LEVEL") || getEnv("REACT_APP_LOG_LEVEL");
|
|
36
|
-
if (!level)
|
|
37
|
-
return undefined;
|
|
38
|
-
const levels = [
|
|
39
|
-
"fatal",
|
|
40
|
-
"error",
|
|
41
|
-
"warn",
|
|
42
|
-
"info",
|
|
43
|
-
"debug",
|
|
44
|
-
"trace",
|
|
45
|
-
"silent",
|
|
46
|
-
];
|
|
47
|
-
if (!levels.includes(level)) {
|
|
48
|
-
throw new Error(`Unexpected LOG_LEVEL: ${level}. Expecting one of: ${JSON.stringify(levels)}`);
|
|
49
|
-
}
|
|
50
|
-
return level;
|
|
51
|
-
};
|
|
52
|
-
const logger = (options) => {
|
|
53
|
-
// In browsers/workers, pino's browser build logs to console by default.
|
|
54
|
-
let base = pino();
|
|
55
|
-
if (options?.module) {
|
|
56
|
-
base = base.child({ module: options.module });
|
|
57
|
-
}
|
|
58
|
-
const level = options?.level ?? getLogLevel();
|
|
59
|
-
if (level) {
|
|
60
|
-
base.level = level;
|
|
61
|
-
}
|
|
62
|
-
return base;
|
|
63
|
-
};
|
|
64
|
-
export { logger };
|
|
1
|
+
export * from "@libp2p/logger";
|
|
65
2
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peerbit/logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Logging utils",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
@@ -49,14 +49,14 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"
|
|
52
|
+
"@libp2p/logger": "^6.2.1"
|
|
53
53
|
},
|
|
54
|
+
"author": "dao.xyz",
|
|
55
|
+
"license": "MIT",
|
|
54
56
|
"scripts": {
|
|
55
57
|
"clean": "aegir clean",
|
|
56
58
|
"build": "aegir build --no-bundle",
|
|
57
59
|
"test": "aegir test --target node",
|
|
58
60
|
"lint": "aegir lint"
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
"license": "MIT"
|
|
62
|
-
}
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,85 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// Robust Node detection (true only in Node.js)
|
|
4
|
-
const isNode = typeof process !== "undefined" && !!process.versions?.node;
|
|
5
|
-
|
|
6
|
-
type LogLevel =
|
|
7
|
-
| "fatal"
|
|
8
|
-
| "error"
|
|
9
|
-
| "warn"
|
|
10
|
-
| "info"
|
|
11
|
-
| "debug"
|
|
12
|
-
| "trace"
|
|
13
|
-
| "silent";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Safely read an env var from:
|
|
17
|
-
* - Node: process.env
|
|
18
|
-
* - Webpack/CRA (browser/worker): globalThis.process.env (if defined by bundler)
|
|
19
|
-
* - Vite (browser/worker): import.meta.env
|
|
20
|
-
*/
|
|
21
|
-
export const getEnv = (key: string): string | undefined => {
|
|
22
|
-
if (isNode) {
|
|
23
|
-
return process.env?.[key];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Some bundlers (Webpack/CRA) inject a process shim
|
|
27
|
-
const g: any = typeof globalThis !== "undefined" ? (globalThis as any) : {};
|
|
28
|
-
if (g.process?.env && typeof g.process.env[key] !== "undefined") {
|
|
29
|
-
return g.process.env[key];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Vite exposes import.meta.env
|
|
33
|
-
let metaEnv: any;
|
|
34
|
-
try {
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
36
|
-
// @ts-ignore - import.meta may not exist in TS/node type context
|
|
37
|
-
metaEnv = import.meta?.env;
|
|
38
|
-
} catch {
|
|
39
|
-
// ignore if not supported
|
|
40
|
-
}
|
|
41
|
-
if (metaEnv && typeof metaEnv[key] !== "undefined") {
|
|
42
|
-
return metaEnv[key];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return undefined;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export const getLogLevel = (): LogLevel | undefined => {
|
|
49
|
-
const level = getEnv("LOG_LEVEL") || getEnv("REACT_APP_LOG_LEVEL");
|
|
50
|
-
if (!level) return undefined;
|
|
51
|
-
|
|
52
|
-
const levels: LogLevel[] = [
|
|
53
|
-
"fatal",
|
|
54
|
-
"error",
|
|
55
|
-
"warn",
|
|
56
|
-
"info",
|
|
57
|
-
"debug",
|
|
58
|
-
"trace",
|
|
59
|
-
"silent",
|
|
60
|
-
];
|
|
61
|
-
if (!levels.includes(level as LogLevel)) {
|
|
62
|
-
throw new Error(
|
|
63
|
-
`Unexpected LOG_LEVEL: ${level}. Expecting one of: ${JSON.stringify(levels)}`,
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
return level as LogLevel;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const logger = (options?: { module?: string; level?: LogLevel }) => {
|
|
70
|
-
// In browsers/workers, pino's browser build logs to console by default.
|
|
71
|
-
let base = pino();
|
|
72
|
-
|
|
73
|
-
if (options?.module) {
|
|
74
|
-
base = base.child({ module: options.module });
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const level = options?.level ?? getLogLevel();
|
|
78
|
-
if (level) {
|
|
79
|
-
base.level = level;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return base;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
export { logger };
|
|
1
|
+
export * from "@libp2p/logger";
|