@dawntech/dwntbots-logger 0.0.2

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/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # logger
2
+
3
+ This library was generated with [Nx](https://nx.dev).
package/package.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@dawntech/dwntbots-logger",
3
+ "version": "0.0.2",
4
+ "type": "commonjs",
5
+ "main": "./src/index.js",
6
+ "types": "./src/index.d.ts",
7
+ "dependencies": {},
8
+ "peerDependencies": {
9
+ "pino": "8.7.0",
10
+ "micromatch": "4.0.5",
11
+ "tslib": "2.4.1"
12
+ }
13
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './lib/logger';
package/src/index.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/logger"), exports);
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/logger/src/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B"}
@@ -0,0 +1,45 @@
1
+ import pino from "pino";
2
+ export declare enum LoggingType {
3
+ LOCAL = "local"
4
+ }
5
+ export declare enum LoggingLevel {
6
+ silent = "silent",
7
+ fatal = "fatal",
8
+ error = "error",
9
+ warn = "warn",
10
+ api = "api",
11
+ info = "info",
12
+ debug = "debug",
13
+ trace = "trace"
14
+ }
15
+ export declare type LoggingGlobLevels = Record<keyof typeof LoggingLevel, Array<string>>;
16
+ export declare const _levels: {
17
+ [k: string]: LoggingLevel;
18
+ };
19
+ export declare const updateGlobLevels: (globLevels: Partial<LoggingGlobLevels>) => void;
20
+ export declare const logger: import("pino").Logger<{
21
+ level: string;
22
+ customLevels: {
23
+ api: number;
24
+ };
25
+ mixin: () => {
26
+ project: string;
27
+ };
28
+ }>;
29
+ export interface SetupOptions {
30
+ project: string;
31
+ type?: LoggingType;
32
+ level?: LoggingLevel;
33
+ globLevels?: Partial<LoggingGlobLevels>;
34
+ }
35
+ export declare const setup: (options: SetupOptions) => void;
36
+ export declare const getLogger: (path?: string) => pino.Logger<{
37
+ level: string;
38
+ customLevels: {
39
+ api: number;
40
+ };
41
+ mixin: () => {
42
+ project: string;
43
+ };
44
+ } & pino.ChildLoggerOptions>;
45
+ export default setup;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLogger = exports.setup = exports.logger = exports.updateGlobLevels = exports._levels = exports.LoggingLevel = exports.LoggingType = void 0;
4
+ const pino_1 = require("pino");
5
+ const micromatch = require("micromatch");
6
+ var LoggingType;
7
+ (function (LoggingType) {
8
+ LoggingType["LOCAL"] = "local";
9
+ })(LoggingType = exports.LoggingType || (exports.LoggingType = {}));
10
+ var LoggingLevel;
11
+ (function (LoggingLevel) {
12
+ LoggingLevel["silent"] = "silent";
13
+ LoggingLevel["fatal"] = "fatal";
14
+ LoggingLevel["error"] = "error";
15
+ LoggingLevel["warn"] = "warn";
16
+ LoggingLevel["api"] = "api";
17
+ LoggingLevel["info"] = "info";
18
+ LoggingLevel["debug"] = "debug";
19
+ LoggingLevel["trace"] = "trace";
20
+ })(LoggingLevel = exports.LoggingLevel || (exports.LoggingLevel = {}));
21
+ const levels = {
22
+ [LoggingLevel.silent]: Infinity,
23
+ [LoggingLevel.fatal]: 60,
24
+ [LoggingLevel.error]: 50,
25
+ [LoggingLevel.warn]: 40,
26
+ [LoggingLevel.api]: 35,
27
+ [LoggingLevel.info]: 30,
28
+ [LoggingLevel.debug]: 20,
29
+ [LoggingLevel.trace]: 10,
30
+ };
31
+ exports._levels = Object.fromEntries(Object.keys(LoggingLevel)
32
+ .filter((key) => isNaN(Number(key)))
33
+ .map((key) => [key, LoggingLevel[key]]));
34
+ let _project;
35
+ let _glob_levels;
36
+ const updateGlobLevels = (globLevels) => {
37
+ const _levels = Object.keys(levels)
38
+ .filter((key) => !isNaN(Number(key)))
39
+ .sort((a, b) => Number(a) - Number(b))
40
+ .map((key) => LoggingLevel[key]);
41
+ _glob_levels = Object.fromEntries(_levels.map((curr_level, index) => [
42
+ curr_level,
43
+ _levels
44
+ .slice(0, index)
45
+ .flatMap((level) => level in globLevels ? globLevels[level] : []),
46
+ ]));
47
+ };
48
+ exports.updateGlobLevels = updateGlobLevels;
49
+ (0, exports.updateGlobLevels)({ error: [] });
50
+ // const project = format((info, opts) => {
51
+ // info['project'] = _project;
52
+ // console.log(info);
53
+ // return info;
54
+ // });
55
+ // const globLevels = format((info, opts) => {
56
+ // const { level, path } = info;
57
+ // const patterns = _glob_levels[level as keyof typeof Level];
58
+ // return micromatch([path], patterns).length === 0 ? info : false;
59
+ // });
60
+ // const _transports = {
61
+ // [Transport.LOCAL]: [
62
+ // new transports.Console({
63
+ // format: printf(({ level, message, path, timestamp }) => {
64
+ // return `${timestamp} [${path}] ${level}: ${message}`;
65
+ // })
66
+ // })
67
+ // ]
68
+ // };
69
+ exports.logger = (0, pino_1.default)({
70
+ level: "silent",
71
+ customLevels: {
72
+ [LoggingLevel.api]: levels[LoggingLevel.api],
73
+ },
74
+ mixin: () => ({ project: _project }),
75
+ });
76
+ const setup = (options) => {
77
+ let { project, level, type } = options;
78
+ //const level = Level[_level || Level.info];
79
+ //const transports = _transports[_transport || Transport.LOCAL];
80
+ _project = project;
81
+ exports.logger.level = level || "info";
82
+ // logger.configure({
83
+ // level,
84
+ // transports
85
+ // });
86
+ (0, exports.updateGlobLevels)(options.globLevels || {});
87
+ };
88
+ exports.setup = setup;
89
+ const paths = [];
90
+ const getLogger = (path = "") => {
91
+ paths.push(path);
92
+ return exports.logger.child({ path });
93
+ };
94
+ exports.getLogger = getLogger;
95
+ exports.default = exports.setup;
96
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":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