@peerbit/logger 1.0.4-fd84d12 → 2.0.0-369b236

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.
@@ -1,15 +1,2 @@
1
- type LogLevel = "fatal" | "error" | "warn" | "info" | "debug" | "trace" | "silent";
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,KAAK,QAAQ,GACV,OAAO,GACP,OAAO,GACP,MAAM,GACN,MAAM,GACN,OAAO,GACP,OAAO,GACP,QAAQ,CAAC;AAEZ;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SAyB7C,CAAC;AAEF,eAAO,MAAM,WAAW,QAAO,QAAQ,GAAG,SAmBzC,CAAC;AAEF,QAAA,MAAM,MAAM,GAAI,UAAU;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,QAAQ,CAAA;CAAE,iCAc9D,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
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
- import pino from "pino";
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
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,+CAA+C;AAC/C,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,WAAW,IAAI,CAAC,CAAC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MAAM,CAAC,QAAQ,CAAC,KAAiB,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,KAAK,CACd,yBAAyB,KAAK,uBAAuB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAC7E,CAAC;IACH,CAAC;IACD,OAAO,KAAiB,CAAC;AAC1B,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,OAA+C,EAAE,EAAE;IAClE,wEAAwE;IACxE,IAAI,IAAI,GAAG,IAAI,EAAE,CAAC;IAElB,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;QACrB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC/C,CAAC;IAED,MAAM,KAAK,GAAG,OAAO,EAAE,KAAK,IAAI,WAAW,EAAE,CAAC;IAC9C,IAAI,KAAK,EAAE,CAAC;QACX,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACpB,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
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": "1.0.4-fd84d12",
3
+ "version": "2.0.0-369b236",
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
- "pino": "^8.14.1"
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
- "author": "dao.xyz",
61
- "license": "MIT"
62
- }
61
+ }
62
+ }
package/src/index.ts CHANGED
@@ -1,85 +1 @@
1
- import pino from "pino";
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";