@push.rocks/smartlog 3.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.
@@ -0,0 +1,183 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
19
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
20
+ mod
21
+ ));
22
+
23
+ // node_modules/.pnpm/@pushrocks+isounique@1.0.5/node_modules/@pushrocks/isounique/dist_ts/index.js
24
+ var require_dist_ts = __commonJS({
25
+ "node_modules/.pnpm/@pushrocks+isounique@1.0.5/node_modules/@pushrocks/isounique/dist_ts/index.js"(exports) {
26
+ "use strict";
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.uni = void 0;
29
+ var uni = (prefix = "uni") => {
30
+ return `${prefix}_${`xxxxxxxxxxxxxxxxxxxxxxxx`.replace(/[xy]/g, (c) => {
31
+ const r = Math.random() * 16 | 0;
32
+ const v = c === "x" ? r : r & 3 | 8;
33
+ return v.toString(16);
34
+ })}`;
35
+ };
36
+ exports.uni = uni;
37
+ }
38
+ });
39
+
40
+ // ts/smartlog.plugins.ts
41
+ var isounique = __toESM(require_dist_ts(), 1);
42
+
43
+ // ts/smartlog.classes.consolelog.ts
44
+ var ConsoleLog = class {
45
+ log(logLevelArg, logMessageArg, dataArg, correlationArg) {
46
+ console.log(`__# ${logLevelArg}: ${logMessageArg}`);
47
+ }
48
+ };
49
+
50
+ // ts/smartlog.classes.logrouter.ts
51
+ var LogRouter = class {
52
+ constructor() {
53
+ this.logDestinations = [];
54
+ }
55
+ addLogDestination(logDestination) {
56
+ this.logDestinations.push(logDestination);
57
+ }
58
+ async routeLog(logPackageArg) {
59
+ for (const logDestination of this.logDestinations) {
60
+ await logDestination.handleLog(logPackageArg);
61
+ }
62
+ }
63
+ };
64
+
65
+ // ts/smartlog.classes.smartlog.ts
66
+ var Smartlog = class {
67
+ constructor(optionsArg) {
68
+ this.uniInstanceId = isounique.uni();
69
+ this.logRouter = new LogRouter();
70
+ this.logContext = optionsArg.logContext;
71
+ this.minimumLogLevel = optionsArg.minimumLogLevel || "silly";
72
+ }
73
+ addLogDestination(logDestinationArg) {
74
+ this.logRouter.addLogDestination(logDestinationArg);
75
+ }
76
+ enableConsole(optionsArg) {
77
+ if (globalThis.process && optionsArg && optionsArg.captureAll) {
78
+ const process = globalThis.process;
79
+ const write = process.stdout.write;
80
+ process.stdout.write = (...args) => {
81
+ const logString = args[0];
82
+ if (!logString || typeof logString.startsWith !== "function") {
83
+ } else if (!logString.startsWith("LOG") && typeof logString === "string") {
84
+ switch (true) {
85
+ case logString.substr(0, 20).includes("Error:"):
86
+ this.log("error", logString);
87
+ break;
88
+ default:
89
+ this.log("info", logString);
90
+ }
91
+ return true;
92
+ }
93
+ write.apply(process.stdout, args);
94
+ return true;
95
+ };
96
+ process.stderr.write = (...args) => {
97
+ if (!args[0].startsWith("LOG")) {
98
+ this.log("error", args[0]);
99
+ return true;
100
+ }
101
+ write.apply(process.stderr, args);
102
+ return true;
103
+ };
104
+ }
105
+ this.consoleEnabled = true;
106
+ }
107
+ async log(logLevelArg, logMessageArg, logDataArg, correlationArg) {
108
+ correlationArg = {
109
+ ...{
110
+ id: isounique.uni(),
111
+ type: "none",
112
+ instance: this.uniInstanceId
113
+ },
114
+ ...correlationArg
115
+ };
116
+ if (this.consoleEnabled) {
117
+ this.safeConsoleLog(`${logLevelArg}: ${logMessageArg}`);
118
+ }
119
+ const logPackage = {
120
+ timestamp: Date.now(),
121
+ type: "log",
122
+ context: this.logContext,
123
+ level: logLevelArg,
124
+ correlation: correlationArg,
125
+ message: logMessageArg
126
+ };
127
+ if (logDataArg) {
128
+ logPackage.data = logDataArg;
129
+ }
130
+ await this.logRouter.routeLog(logPackage);
131
+ }
132
+ increment(logLevelArg, logMessageArg, logDataArg, correlationArg = {
133
+ id: isounique.uni(),
134
+ type: "none"
135
+ }) {
136
+ if (this.consoleEnabled) {
137
+ this.safeConsoleLog(`INCREMENT: ${logLevelArg}: ${logMessageArg}`);
138
+ }
139
+ this.logRouter.routeLog({
140
+ timestamp: Date.now(),
141
+ type: "increment",
142
+ context: this.logContext,
143
+ level: logLevelArg,
144
+ message: logMessageArg,
145
+ correlation: correlationArg
146
+ });
147
+ }
148
+ async handleLog(logPackageArg) {
149
+ await this.logRouter.routeLog(logPackageArg);
150
+ }
151
+ safeConsoleLog(logLine) {
152
+ console.log(
153
+ `LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLine}`
154
+ );
155
+ }
156
+ createLogGroup(transactionId = "none") {
157
+ return new LogGroup(this, transactionId);
158
+ }
159
+ };
160
+
161
+ // ts/smartlog.classes.loggroup.ts
162
+ var LogGroup = class {
163
+ constructor(smartlogInstance, transactionIdArg) {
164
+ this.groupId = isounique.uni();
165
+ this.smartlogRef = smartlogInstance;
166
+ this.transactionId = transactionIdArg;
167
+ }
168
+ log(logLevelArg, logMessageArg, logDataArg) {
169
+ this.smartlogRef.log(logLevelArg, logMessageArg, logDataArg, {
170
+ id: isounique.uni(),
171
+ type: "none",
172
+ group: this.groupId,
173
+ instance: this.smartlogRef.uniInstanceId,
174
+ transaction: this.transactionId
175
+ });
176
+ }
177
+ };
178
+ export {
179
+ ConsoleLog,
180
+ LogGroup,
181
+ Smartlog
182
+ };
183
+ //# sourceMappingURL=bundle.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../node_modules/.pnpm/@pushrocks+isounique@1.0.5/node_modules/@pushrocks/isounique/ts/index.ts", "../ts/smartlog.plugins.ts", "../ts/smartlog.classes.consolelog.ts", "../ts/smartlog.classes.logrouter.ts", "../ts/smartlog.classes.smartlog.ts", "../ts/smartlog.classes.loggroup.ts"],
4
+ "sourcesContent": [null, "import * as isounique from '@pushrocks/isounique';\nimport * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';\n\nexport { isounique, smartlogInterfaces };\n", "import * as plugins from './smartlog.plugins.js';\n\n/**\n * a console log optimized for smartlog\n */\nexport class ConsoleLog {\n public log(\n logLevelArg: plugins.smartlogInterfaces.TLogLevel,\n logMessageArg: string,\n dataArg?: any,\n correlationArg?: plugins.smartlogInterfaces.ILogCorrelation\n ) {\n console.log(`__# ${logLevelArg}: ${logMessageArg}`);\n }\n}\n", "import * as plugins from './smartlog.plugins.js';\n\nimport { ILogDestination, ILogPackage } from '@pushrocks/smartlog-interfaces';\n\nexport class LogRouter {\n /**\n * all log destinations\n */\n private logDestinations: ILogDestination[] = [];\n\n constructor() {}\n\n public addLogDestination(logDestination: ILogDestination) {\n this.logDestinations.push(logDestination);\n }\n\n // routes the log according to added logDestinations\n public async routeLog(logPackageArg: ILogPackage) {\n for (const logDestination of this.logDestinations) {\n await logDestination.handleLog(logPackageArg);\n }\n }\n}\n", "import * as plugins from './smartlog.plugins.js';\n\nimport { LogRouter } from './smartlog.classes.logrouter.js';\nimport { LogGroup } from './smartlog.classes.loggroup.js';\n\nexport interface ISmartlogContructorOptions {\n logContext: plugins.smartlogInterfaces.ILogContext;\n minimumLogLevel?: plugins.smartlogInterfaces.TLogLevel;\n}\n\nexport class Smartlog implements plugins.smartlogInterfaces.ILogDestination {\n public logContext: plugins.smartlogInterfaces.ILogContext;\n public minimumLogLevel: plugins.smartlogInterfaces.TLogLevel;\n\n public uniInstanceId: string = plugins.isounique.uni();\n\n private consoleEnabled: boolean;\n\n private logRouter = new LogRouter();\n\n public addLogDestination(logDestinationArg: plugins.smartlogInterfaces.ILogDestination) {\n this.logRouter.addLogDestination(logDestinationArg);\n }\n\n constructor(optionsArg: ISmartlogContructorOptions) {\n this.logContext = optionsArg.logContext;\n this.minimumLogLevel = optionsArg.minimumLogLevel || 'silly';\n }\n\n // ============\n // Logger Setup\n // ============\n\n /**\n * enables console logging\n */\n public enableConsole(optionsArg?: { captureAll: boolean }) {\n if (globalThis.process && optionsArg && optionsArg.captureAll) {\n const process = globalThis.process;\n const write = process.stdout.write;\n process.stdout.write = (...args: any) => {\n const logString: string = args[0];\n if (!logString || typeof logString.startsWith !== 'function') {\n // lets continue as planned\n } else if (!logString.startsWith('LOG') && typeof logString === 'string') {\n switch (true) {\n case logString.substr(0, 20).includes('Error:'):\n this.log('error', logString);\n break;\n default:\n this.log('info', logString);\n }\n return true;\n }\n // fileStream.write(args[0]);\n write.apply(process.stdout, args);\n return true;\n };\n\n process.stderr.write = (...args: any) => {\n if (!args[0].startsWith('LOG')) {\n this.log('error', args[0]);\n return true;\n }\n // fileStream.write(args[0]);\n write.apply(process.stderr, args);\n return true;\n };\n }\n this.consoleEnabled = true;\n }\n\n // =============\n // log functions\n // =============\n /**\n * main log method\n * @param logLevelArg - the log level\n * @param logMessageArg - the log message\n * @param logDataArg - any additional log data\n * @param correlationArg - info about corrleations\n */\n public async log(\n logLevelArg: plugins.smartlogInterfaces.TLogLevel,\n logMessageArg: string,\n logDataArg?: any,\n correlationArg?: plugins.smartlogInterfaces.ILogCorrelation\n ) {\n correlationArg = {\n ...{\n id: plugins.isounique.uni(),\n type: 'none',\n instance: this.uniInstanceId,\n },\n ...correlationArg,\n };\n\n if (this.consoleEnabled) {\n this.safeConsoleLog(`${logLevelArg}: ${logMessageArg}`);\n }\n\n const logPackage: plugins.smartlogInterfaces.ILogPackage = {\n timestamp: Date.now(),\n type: 'log',\n context: this.logContext,\n level: logLevelArg,\n correlation: correlationArg,\n message: logMessageArg,\n };\n if (logDataArg) {\n logPackage.data = logDataArg;\n }\n await this.logRouter.routeLog(logPackage);\n }\n\n public increment(\n logLevelArg: plugins.smartlogInterfaces.TLogLevel,\n logMessageArg: string,\n logDataArg?: any,\n correlationArg: plugins.smartlogInterfaces.ILogCorrelation = {\n id: plugins.isounique.uni(),\n type: 'none',\n }\n ) {\n if (this.consoleEnabled) {\n this.safeConsoleLog(`INCREMENT: ${logLevelArg}: ${logMessageArg}`);\n }\n this.logRouter.routeLog({\n timestamp: Date.now(),\n type: 'increment',\n context: this.logContext,\n level: logLevelArg,\n message: logMessageArg,\n correlation: correlationArg,\n });\n }\n\n public async handleLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {\n await this.logRouter.routeLog(logPackageArg);\n }\n\n private safeConsoleLog(logLine: string) {\n console.log(\n `LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLine}`\n );\n }\n\n public createLogGroup(transactionId: string = 'none') {\n return new LogGroup(this, transactionId);\n }\n}\n", "import * as plugins from './smartlog.plugins.js';\nimport { Smartlog } from './smartlog.classes.smartlog.js';\n\nexport class LogGroup {\n public smartlogRef: Smartlog;\n public transactionId: string;\n public groupId = plugins.isounique.uni();\n\n constructor(smartlogInstance: Smartlog, transactionIdArg: string) {\n this.smartlogRef = smartlogInstance;\n this.transactionId = transactionIdArg;\n }\n\n public log(\n logLevelArg: plugins.smartlogInterfaces.TLogLevel,\n logMessageArg: string,\n logDataArg?: any\n ) {\n this.smartlogRef.log(logLevelArg, logMessageArg, logDataArg, {\n id: plugins.isounique.uni(),\n type: 'none',\n group: this.groupId,\n instance: this.smartlogRef.uniInstanceId,\n transaction: this.transactionId,\n });\n }\n}\n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gB,eAAe;AAAA,IACnE;AACA,SAAK,UAAU,SAAS;AAAA,MACtB,WAAW,KAAK,IAAI;AAAA,MACpB,MAAM;AAAA,MACN,SAAS,KAAK;AAAA,MACd,OAAO;AAAA,MACP,SAAS;AAAA,MACT,aAAa;AAAA,IACf,CAAC;AAAA,EACH;AAAA,EAEA,MAAa,UAAU,eAAuD;AAC5E,UAAM,KAAK,UAAU,SAAS,aAAa;AAAA,EAC7C;AAAA,EAEQ,eAAe,SAAiB;AACtC,YAAQ;AAAA,MACN,UAAU,IAAI,KAAK,EAAE,SAAS,KAAK,IAAI,KAAK,EAAE,WAAW,KAAK,IAAI,KAAK,EAAE,WAAW,QAAQ;AAAA,IAC9F;AAAA,EACF;AAAA,EAEO,eAAe,gBAAwB,QAAQ;AACpD,WAAO,IAAI,SAAS,MAAM,aAAa;AAAA,EACzC;AACF;;;ACnJO,IAAM,WAAN,MAAe;AAAA,EAKpB,YAAY,kBAA4B,kBAA0B;AAFlE,SAAO,UAAkB,UAAU,IAAI;AAGrC,SAAK,cAAc;AACnB,SAAK,gBAAgB;AAAA,EACvB;AAAA,EAEO,IACL,aACA,eACA,YACA;AACA,SAAK,YAAY,IAAI,aAAa,eAAe,YAAY;AAAA,MAC3D,IAAY,UAAU,IAAI;AAAA,MAC1B,MAAM;AAAA,MACN,OAAO,KAAK;AAAA,MACZ,UAAU,KAAK,YAAY;AAAA,MAC3B,aAAa,KAAK;AAAA,IACpB,CAAC;AAAA,EACH;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * autocreated commitinfo by @pushrocks/commitinfo
3
+ */
4
+ export declare const commitinfo: {
5
+ name: string;
6
+ version: string;
7
+ description: string;
8
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * autocreated commitinfo by @pushrocks/commitinfo
3
+ */
4
+ export const commitinfo = {
5
+ name: '@pushrocks/smartlog',
6
+ version: '3.0.2',
7
+ description: 'minimalistic distributed and extensible logging tool'
8
+ };
9
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiMDBfY29tbWl0aW5mb19kYXRhLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvMDBfY29tbWl0aW5mb19kYXRhLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBQ0gsTUFBTSxDQUFDLE1BQU0sVUFBVSxHQUFHO0lBQ3hCLElBQUksRUFBRSxxQkFBcUI7SUFDM0IsT0FBTyxFQUFFLE9BQU87SUFDaEIsV0FBVyxFQUFFLHNEQUFzRDtDQUNwRSxDQUFBIn0=
@@ -0,0 +1,4 @@
1
+ import { ConsoleLog } from './smartlog.classes.consolelog.js';
2
+ import { LogGroup } from './smartlog.classes.loggroup.js';
3
+ import { Smartlog } from './smartlog.classes.smartlog.js';
4
+ export { ConsoleLog, LogGroup, Smartlog };
@@ -0,0 +1,6 @@
1
+ import './smartlog.plugins.js';
2
+ import { ConsoleLog } from './smartlog.classes.consolelog.js';
3
+ import { LogGroup } from './smartlog.classes.loggroup.js';
4
+ import { Smartlog } from './smartlog.classes.smartlog.js';
5
+ export { ConsoleLog, LogGroup, Smartlog };
6
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUF5Qix1QkFBdUIsQ0FBQztBQUNqRCxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sa0NBQWtDLENBQUM7QUFDOUQsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQzFELE9BQU8sRUFBRSxRQUFRLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUUxRCxPQUFPLEVBQUUsVUFBVSxFQUFFLFFBQVEsRUFBRSxRQUFRLEVBQUUsQ0FBQyJ9
@@ -0,0 +1,7 @@
1
+ import * as plugins from './smartlog.plugins.js';
2
+ /**
3
+ * a console log optimized for smartlog
4
+ */
5
+ export declare class ConsoleLog {
6
+ log(logLevelArg: plugins.smartlogInterfaces.TLogLevel, logMessageArg: string, dataArg?: any, correlationArg?: plugins.smartlogInterfaces.ILogCorrelation): void;
7
+ }
@@ -0,0 +1,10 @@
1
+ import './smartlog.plugins.js';
2
+ /**
3
+ * a console log optimized for smartlog
4
+ */
5
+ export class ConsoleLog {
6
+ log(logLevelArg, logMessageArg, dataArg, correlationArg) {
7
+ console.log(`__# ${logLevelArg}: ${logMessageArg}`);
8
+ }
9
+ }
10
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRsb2cuY2xhc3Nlcy5jb25zb2xlbG9nLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRsb2cuY2xhc3Nlcy5jb25zb2xlbG9nLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQXlCLHVCQUF1QixDQUFDO0FBRWpEOztHQUVHO0FBQ0gsTUFBTSxPQUFPLFVBQVU7SUFDZCxHQUFHLENBQ1IsV0FBaUQsRUFDakQsYUFBcUIsRUFDckIsT0FBYSxFQUNiLGNBQTJEO1FBRTNELE9BQU8sQ0FBQyxHQUFHLENBQUMsT0FBTyxXQUFXLEtBQUssYUFBYSxFQUFFLENBQUMsQ0FBQztJQUN0RCxDQUFDO0NBQ0YifQ==
@@ -0,0 +1,9 @@
1
+ import * as plugins from './smartlog.plugins.js';
2
+ import { Smartlog } from './smartlog.classes.smartlog.js';
3
+ export declare class LogGroup {
4
+ smartlogRef: Smartlog;
5
+ transactionId: string;
6
+ groupId: string;
7
+ constructor(smartlogInstance: Smartlog, transactionIdArg: string);
8
+ log(logLevelArg: plugins.smartlogInterfaces.TLogLevel, logMessageArg: string, logDataArg?: any): void;
9
+ }
@@ -0,0 +1,19 @@
1
+ import * as plugins from './smartlog.plugins.js';
2
+ import './smartlog.classes.smartlog.js';
3
+ export class LogGroup {
4
+ constructor(smartlogInstance, transactionIdArg) {
5
+ this.groupId = plugins.isounique.uni();
6
+ this.smartlogRef = smartlogInstance;
7
+ this.transactionId = transactionIdArg;
8
+ }
9
+ log(logLevelArg, logMessageArg, logDataArg) {
10
+ this.smartlogRef.log(logLevelArg, logMessageArg, logDataArg, {
11
+ id: plugins.isounique.uni(),
12
+ type: 'none',
13
+ group: this.groupId,
14
+ instance: this.smartlogRef.uniInstanceId,
15
+ transaction: this.transactionId,
16
+ });
17
+ }
18
+ }
19
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRsb2cuY2xhc3Nlcy5sb2dncm91cC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bG9nLmNsYXNzZXMubG9nZ3JvdXAudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLE9BQU8sTUFBTSx1QkFBdUIsQ0FBQztBQUNqRCxPQUF5QixnQ0FBZ0MsQ0FBQztBQUUxRCxNQUFNLE9BQU8sUUFBUTtJQUtuQixZQUFZLGdCQUEwQixFQUFFLGdCQUF3QjtRQUZ6RCxZQUFPLEdBQUcsT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLEVBQUUsQ0FBQztRQUd2QyxJQUFJLENBQUMsV0FBVyxHQUFHLGdCQUFnQixDQUFDO1FBQ3BDLElBQUksQ0FBQyxhQUFhLEdBQUcsZ0JBQWdCLENBQUM7SUFDeEMsQ0FBQztJQUVNLEdBQUcsQ0FDUixXQUFpRCxFQUNqRCxhQUFxQixFQUNyQixVQUFnQjtRQUVoQixJQUFJLENBQUMsV0FBVyxDQUFDLEdBQUcsQ0FBQyxXQUFXLEVBQUUsYUFBYSxFQUFFLFVBQVUsRUFBRTtZQUMzRCxFQUFFLEVBQUUsT0FBTyxDQUFDLFNBQVMsQ0FBQyxHQUFHLEVBQUU7WUFDM0IsSUFBSSxFQUFFLE1BQU07WUFDWixLQUFLLEVBQUUsSUFBSSxDQUFDLE9BQU87WUFDbkIsUUFBUSxFQUFFLElBQUksQ0FBQyxXQUFXLENBQUMsYUFBYTtZQUN4QyxXQUFXLEVBQUUsSUFBSSxDQUFDLGFBQWE7U0FDaEMsQ0FBQyxDQUFDO0lBQ0wsQ0FBQztDQUNGIn0=
@@ -0,0 +1,10 @@
1
+ import { ILogDestination, ILogPackage } from '@pushrocks/smartlog-interfaces';
2
+ export declare class LogRouter {
3
+ /**
4
+ * all log destinations
5
+ */
6
+ private logDestinations;
7
+ constructor();
8
+ addLogDestination(logDestination: ILogDestination): void;
9
+ routeLog(logPackageArg: ILogPackage): Promise<void>;
10
+ }
@@ -0,0 +1,20 @@
1
+ import './smartlog.plugins.js';
2
+ import '@pushrocks/smartlog-interfaces';
3
+ export class LogRouter {
4
+ constructor() {
5
+ /**
6
+ * all log destinations
7
+ */
8
+ this.logDestinations = [];
9
+ }
10
+ addLogDestination(logDestination) {
11
+ this.logDestinations.push(logDestination);
12
+ }
13
+ // routes the log according to added logDestinations
14
+ async routeLog(logPackageArg) {
15
+ for (const logDestination of this.logDestinations) {
16
+ await logDestination.handleLog(logPackageArg);
17
+ }
18
+ }
19
+ }
20
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRsb2cuY2xhc3Nlcy5sb2dyb3V0ZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGxvZy5jbGFzc2VzLmxvZ3JvdXRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUF5Qix1QkFBdUIsQ0FBQztBQUVqRCxPQUE2QyxnQ0FBZ0MsQ0FBQztBQUU5RSxNQUFNLE9BQU8sU0FBUztJQU1wQjtRQUxBOztXQUVHO1FBQ0ssb0JBQWUsR0FBc0IsRUFBRSxDQUFDO0lBRWpDLENBQUM7SUFFVCxpQkFBaUIsQ0FBQyxjQUErQjtRQUN0RCxJQUFJLENBQUMsZUFBZSxDQUFDLElBQUksQ0FBQyxjQUFjLENBQUMsQ0FBQztJQUM1QyxDQUFDO0lBRUQsb0RBQW9EO0lBQzdDLEtBQUssQ0FBQyxRQUFRLENBQUMsYUFBMEI7UUFDOUMsS0FBSyxNQUFNLGNBQWMsSUFBSSxJQUFJLENBQUMsZUFBZSxFQUFFO1lBQ2pELE1BQU0sY0FBYyxDQUFDLFNBQVMsQ0FBQyxhQUFhLENBQUMsQ0FBQztTQUMvQztJQUNILENBQUM7Q0FDRiJ9
@@ -0,0 +1,33 @@
1
+ import * as plugins from './smartlog.plugins.js';
2
+ import { LogGroup } from './smartlog.classes.loggroup.js';
3
+ export interface ISmartlogContructorOptions {
4
+ logContext: plugins.smartlogInterfaces.ILogContext;
5
+ minimumLogLevel?: plugins.smartlogInterfaces.TLogLevel;
6
+ }
7
+ export declare class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
8
+ logContext: plugins.smartlogInterfaces.ILogContext;
9
+ minimumLogLevel: plugins.smartlogInterfaces.TLogLevel;
10
+ uniInstanceId: string;
11
+ private consoleEnabled;
12
+ private logRouter;
13
+ addLogDestination(logDestinationArg: plugins.smartlogInterfaces.ILogDestination): void;
14
+ constructor(optionsArg: ISmartlogContructorOptions);
15
+ /**
16
+ * enables console logging
17
+ */
18
+ enableConsole(optionsArg?: {
19
+ captureAll: boolean;
20
+ }): void;
21
+ /**
22
+ * main log method
23
+ * @param logLevelArg - the log level
24
+ * @param logMessageArg - the log message
25
+ * @param logDataArg - any additional log data
26
+ * @param correlationArg - info about corrleations
27
+ */
28
+ log(logLevelArg: plugins.smartlogInterfaces.TLogLevel, logMessageArg: string, logDataArg?: any, correlationArg?: plugins.smartlogInterfaces.ILogCorrelation): Promise<void>;
29
+ increment(logLevelArg: plugins.smartlogInterfaces.TLogLevel, logMessageArg: string, logDataArg?: any, correlationArg?: plugins.smartlogInterfaces.ILogCorrelation): void;
30
+ handleLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage): Promise<void>;
31
+ private safeConsoleLog;
32
+ createLogGroup(transactionId?: string): LogGroup;
33
+ }
@@ -0,0 +1,116 @@
1
+ import * as plugins from './smartlog.plugins.js';
2
+ import { LogRouter } from './smartlog.classes.logrouter.js';
3
+ import { LogGroup } from './smartlog.classes.loggroup.js';
4
+ export class Smartlog {
5
+ constructor(optionsArg) {
6
+ this.uniInstanceId = plugins.isounique.uni();
7
+ this.logRouter = new LogRouter();
8
+ this.logContext = optionsArg.logContext;
9
+ this.minimumLogLevel = optionsArg.minimumLogLevel || 'silly';
10
+ }
11
+ addLogDestination(logDestinationArg) {
12
+ this.logRouter.addLogDestination(logDestinationArg);
13
+ }
14
+ // ============
15
+ // Logger Setup
16
+ // ============
17
+ /**
18
+ * enables console logging
19
+ */
20
+ enableConsole(optionsArg) {
21
+ if (globalThis.process && optionsArg && optionsArg.captureAll) {
22
+ const process = globalThis.process;
23
+ const write = process.stdout.write;
24
+ process.stdout.write = (...args) => {
25
+ const logString = args[0];
26
+ if (!logString || typeof logString.startsWith !== 'function') {
27
+ // lets continue as planned
28
+ }
29
+ else if (!logString.startsWith('LOG') && typeof logString === 'string') {
30
+ switch (true) {
31
+ case logString.substr(0, 20).includes('Error:'):
32
+ this.log('error', logString);
33
+ break;
34
+ default:
35
+ this.log('info', logString);
36
+ }
37
+ return true;
38
+ }
39
+ // fileStream.write(args[0]);
40
+ write.apply(process.stdout, args);
41
+ return true;
42
+ };
43
+ process.stderr.write = (...args) => {
44
+ if (!args[0].startsWith('LOG')) {
45
+ this.log('error', args[0]);
46
+ return true;
47
+ }
48
+ // fileStream.write(args[0]);
49
+ write.apply(process.stderr, args);
50
+ return true;
51
+ };
52
+ }
53
+ this.consoleEnabled = true;
54
+ }
55
+ // =============
56
+ // log functions
57
+ // =============
58
+ /**
59
+ * main log method
60
+ * @param logLevelArg - the log level
61
+ * @param logMessageArg - the log message
62
+ * @param logDataArg - any additional log data
63
+ * @param correlationArg - info about corrleations
64
+ */
65
+ async log(logLevelArg, logMessageArg, logDataArg, correlationArg) {
66
+ correlationArg = {
67
+ ...{
68
+ id: plugins.isounique.uni(),
69
+ type: 'none',
70
+ instance: this.uniInstanceId,
71
+ },
72
+ ...correlationArg,
73
+ };
74
+ if (this.consoleEnabled) {
75
+ this.safeConsoleLog(`${logLevelArg}: ${logMessageArg}`);
76
+ }
77
+ const logPackage = {
78
+ timestamp: Date.now(),
79
+ type: 'log',
80
+ context: this.logContext,
81
+ level: logLevelArg,
82
+ correlation: correlationArg,
83
+ message: logMessageArg,
84
+ };
85
+ if (logDataArg) {
86
+ logPackage.data = logDataArg;
87
+ }
88
+ await this.logRouter.routeLog(logPackage);
89
+ }
90
+ increment(logLevelArg, logMessageArg, logDataArg, correlationArg = {
91
+ id: plugins.isounique.uni(),
92
+ type: 'none',
93
+ }) {
94
+ if (this.consoleEnabled) {
95
+ this.safeConsoleLog(`INCREMENT: ${logLevelArg}: ${logMessageArg}`);
96
+ }
97
+ this.logRouter.routeLog({
98
+ timestamp: Date.now(),
99
+ type: 'increment',
100
+ context: this.logContext,
101
+ level: logLevelArg,
102
+ message: logMessageArg,
103
+ correlation: correlationArg,
104
+ });
105
+ }
106
+ async handleLog(logPackageArg) {
107
+ await this.logRouter.routeLog(logPackageArg);
108
+ }
109
+ safeConsoleLog(logLine) {
110
+ console.log(`LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLine}`);
111
+ }
112
+ createLogGroup(transactionId = 'none') {
113
+ return new LogGroup(this, transactionId);
114
+ }
115
+ }
116
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRsb2cuY2xhc3Nlcy5zbWFydGxvZy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2Vz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UFVLEVBQUUsT0FBTyxPQUFPLEVBQUUsQ0FDdEcsQ0FBQztJQUNKLENBQUM7SUFFTSxjQUFjLENBQUMsZ0JBQXdCLE1BQU07UUFDbEQsT0FBTyxJQUFJLFFBQVEsQ0FBQyxJQUFJLEVBQUUsYUFBYSxDQUFDLENBQUM7SUFDM0MsQ0FBQztDQUNGIn0=
@@ -0,0 +1,3 @@
1
+ import * as isounique from '@pushrocks/isounique';
2
+ import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';
3
+ export { isounique, smartlogInterfaces };
@@ -0,0 +1,4 @@
1
+ import * as isounique from '@pushrocks/isounique';
2
+ import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';
3
+ export { isounique, smartlogInterfaces };
4
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRsb2cucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0bG9nLnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLFNBQVMsTUFBTSxzQkFBc0IsQ0FBQztBQUNsRCxPQUFPLEtBQUssa0JBQWtCLE1BQU0sZ0NBQWdDLENBQUM7QUFFckUsT0FBTyxFQUFFLFNBQVMsRUFBRSxrQkFBa0IsRUFBRSxDQUFDIn0=
package/license ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 Lossless GmbH (hello@lossless.com)
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
package/npmextra.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "gitzone": {
3
+ "projectType": "npm",
4
+ "module": {
5
+ "githost": "gitlab.com",
6
+ "gitscope": "pushrocks",
7
+ "gitrepo": "smartlog",
8
+ "description": "minimalistic distributed and extensible logging tool",
9
+ "npmPackagename": "@pushrocks/smartlog",
10
+ "license": "MIT",
11
+ "projectDomain": "push.rocks"
12
+ }
13
+ },
14
+ "npmci": {
15
+ "npmGlobalTools": [],
16
+ "npmAccessLevel": "public"
17
+ }
18
+ }
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@push.rocks/smartlog",
3
+ "version": "3.0.2",
4
+ "private": false,
5
+ "description": "minimalistic distributed and extensible logging tool",
6
+ "keywords": [
7
+ "logging",
8
+ "centralized logging",
9
+ "json logging",
10
+ "scalyr",
11
+ "elasticsearch",
12
+ "logdna"
13
+ ],
14
+ "main": "dist_ts/index.js",
15
+ "typings": "dist_ts/index.d.ts",
16
+ "author": "Lossless GmbH",
17
+ "license": "MIT",
18
+ "scripts": {
19
+ "test": "(tstest test/)",
20
+ "build": "(tsbuild --web && tsbundle npm)",
21
+ "format": "(gitzone format)",
22
+ "buildDocs": "tsdoc"
23
+ },
24
+ "devDependencies": {
25
+ "@gitzone/tsbuild": "^2.1.25",
26
+ "@gitzone/tsbundle": "^2.0.6",
27
+ "@gitzone/tsrun": "^1.2.17",
28
+ "@gitzone/tstest": "^1.0.72",
29
+ "@pushrocks/tapbundle": "^5.0.4",
30
+ "@types/node": "^18.6.1"
31
+ },
32
+ "dependencies": {
33
+ "@pushrocks/isounique": "^1.0.4",
34
+ "@pushrocks/smartlog-interfaces": "^3.0.0"
35
+ },
36
+ "files": [
37
+ "ts/**/*",
38
+ "ts_web/**/*",
39
+ "dist/**/*",
40
+ "dist_*/**/*",
41
+ "dist_ts/**/*",
42
+ "dist_ts_web/**/*",
43
+ "assets/**/*",
44
+ "cli.js",
45
+ "npmextra.json",
46
+ "readme.md"
47
+ ],
48
+ "browserslist": [
49
+ "last 1 chrome versions"
50
+ ],
51
+ "type": "module"
52
+ }
package/readme.md ADDED
@@ -0,0 +1,88 @@
1
+ # @pushrocks/smartlog
2
+ minimalistic distributed and extensible logging tool
3
+
4
+ ## Availabililty and Links
5
+ * [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartlog)
6
+ * [gitlab.com (source)](https://gitlab.com/pushrocks/smartlog)
7
+ * [github.com (source mirror)](https://github.com/pushrocks/smartlog)
8
+ * [docs (typedoc)](https://pushrocks.gitlab.io/smartlog/)
9
+
10
+ ## Status for master
11
+
12
+ Status Category | Status Badge
13
+ -- | --
14
+ GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartlog/badges/master/pipeline.svg)](https://lossless.cloud)
15
+ GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartlog/badges/master/coverage.svg)](https://lossless.cloud)
16
+ npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartlog)](https://lossless.cloud)
17
+ Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartlog)](https://lossless.cloud)
18
+ TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
19
+ node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
20
+ Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
21
+ PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartlog)](https://lossless.cloud)
22
+ PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartlog)](https://lossless.cloud)
23
+ BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartlog)](https://lossless.cloud)
24
+ Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
25
+
26
+ ## Usage
27
+
28
+ Use TypeScript for best in class instellisense.
29
+
30
+ smartlog id s minimal logging package that provides a consistent experience across the complete logging stack. Smartlog allows you to create a logger instance like this:
31
+
32
+ ```ts
33
+ import { Smartlog } from '@pushrocks/smartlog';
34
+ const logger = new Smartlog({
35
+ {
36
+ company: 'My awesome company',
37
+ companyunit: 'my awesome cloud team',
38
+ containerName: 'awesome-container',
39
+ environment: 'kubernetes-production',
40
+ runtime: 'node',
41
+ zone: 'zone x'
42
+ }
43
+ })
44
+
45
+ logger.log('silly', `a silly statement`); // log levels are shown to you by the IDE
46
+ ```
47
+
48
+ There is also a default logger available that you can use:
49
+
50
+ ```ts
51
+ import { Smartlog, defaultLogger } from '@pushrocks/smartlog';
52
+
53
+ export class MyAwesomeClass {
54
+ constructor(public logger: Smartlog = defaultLogger) {
55
+ // what happens here that a instance of this class will have instance.logger available
56
+ // if you set a custom logger, than that will be used, if not the default logger.
57
+ }
58
+ }
59
+ ```
60
+
61
+ ### Destinations
62
+
63
+ smartlog supports different kinds of destinations.
64
+
65
+ The following destinations are available:
66
+
67
+ - [@pushrocks/smartlog-destination-local](https://www.npmjs.com/package/@pushrocks/smartlog-destination-local) - outputs logs to the local console in a colorful, nice to read way.
68
+ - [@pushrocks/smartlog-destination-devtools](https://www.npmjs.com/package/@pushrocks/smartlog-destination-devtools) - outputs logs into the browser console in a colorful, nice to read way.
69
+ - [@pushrocks/smartlog-destination-receiver](https://www.npmjs.com/package/@pushrocks/smartlog-destination-receiver) - sends logs to a smartlog receiver (more about that below)
70
+ - [@mojoio/scalyr](https://www.npmjs.com/package/@pushrocks/smartlog-destination-receiver) - an scalyr API package that comes with a smartlog log destination included
71
+ - [@mojoio/elasticsearch](https://www.npmjs.com/package/@mojoio/elasticsearch) - an elasticsearch API package that comes with a smartlog destination included
72
+
73
+ ### Adding a log destination
74
+
75
+ ```
76
+ // TBD
77
+ ```
78
+
79
+ ## Contribution
80
+
81
+ We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
82
+
83
+ For further information read the linked docs at the top of this readme.
84
+
85
+ > MIT licensed | **&copy;** [Lossless GmbH](https://lossless.gmbh)
86
+ | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
87
+
88
+ [![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
@@ -0,0 +1,8 @@
1
+ /**
2
+ * autocreated commitinfo by @pushrocks/commitinfo
3
+ */
4
+ export const commitinfo = {
5
+ name: '@pushrocks/smartlog',
6
+ version: '3.0.2',
7
+ description: 'minimalistic distributed and extensible logging tool'
8
+ }
package/ts/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import * as plugins from './smartlog.plugins.js';
2
+ import { ConsoleLog } from './smartlog.classes.consolelog.js';
3
+ import { LogGroup } from './smartlog.classes.loggroup.js';
4
+ import { Smartlog } from './smartlog.classes.smartlog.js';
5
+
6
+ export { ConsoleLog, LogGroup, Smartlog };
@@ -0,0 +1,15 @@
1
+ import * as plugins from './smartlog.plugins.js';
2
+
3
+ /**
4
+ * a console log optimized for smartlog
5
+ */
6
+ export class ConsoleLog {
7
+ public log(
8
+ logLevelArg: plugins.smartlogInterfaces.TLogLevel,
9
+ logMessageArg: string,
10
+ dataArg?: any,
11
+ correlationArg?: plugins.smartlogInterfaces.ILogCorrelation
12
+ ) {
13
+ console.log(`__# ${logLevelArg}: ${logMessageArg}`);
14
+ }
15
+ }
@@ -0,0 +1,27 @@
1
+ import * as plugins from './smartlog.plugins.js';
2
+ import { Smartlog } from './smartlog.classes.smartlog.js';
3
+
4
+ export class LogGroup {
5
+ public smartlogRef: Smartlog;
6
+ public transactionId: string;
7
+ public groupId = plugins.isounique.uni();
8
+
9
+ constructor(smartlogInstance: Smartlog, transactionIdArg: string) {
10
+ this.smartlogRef = smartlogInstance;
11
+ this.transactionId = transactionIdArg;
12
+ }
13
+
14
+ public log(
15
+ logLevelArg: plugins.smartlogInterfaces.TLogLevel,
16
+ logMessageArg: string,
17
+ logDataArg?: any
18
+ ) {
19
+ this.smartlogRef.log(logLevelArg, logMessageArg, logDataArg, {
20
+ id: plugins.isounique.uni(),
21
+ type: 'none',
22
+ group: this.groupId,
23
+ instance: this.smartlogRef.uniInstanceId,
24
+ transaction: this.transactionId,
25
+ });
26
+ }
27
+ }
@@ -0,0 +1,23 @@
1
+ import * as plugins from './smartlog.plugins.js';
2
+
3
+ import { ILogDestination, ILogPackage } from '@pushrocks/smartlog-interfaces';
4
+
5
+ export class LogRouter {
6
+ /**
7
+ * all log destinations
8
+ */
9
+ private logDestinations: ILogDestination[] = [];
10
+
11
+ constructor() {}
12
+
13
+ public addLogDestination(logDestination: ILogDestination) {
14
+ this.logDestinations.push(logDestination);
15
+ }
16
+
17
+ // routes the log according to added logDestinations
18
+ public async routeLog(logPackageArg: ILogPackage) {
19
+ for (const logDestination of this.logDestinations) {
20
+ await logDestination.handleLog(logPackageArg);
21
+ }
22
+ }
23
+ }
@@ -0,0 +1,151 @@
1
+ import * as plugins from './smartlog.plugins.js';
2
+
3
+ import { LogRouter } from './smartlog.classes.logrouter.js';
4
+ import { LogGroup } from './smartlog.classes.loggroup.js';
5
+
6
+ export interface ISmartlogContructorOptions {
7
+ logContext: plugins.smartlogInterfaces.ILogContext;
8
+ minimumLogLevel?: plugins.smartlogInterfaces.TLogLevel;
9
+ }
10
+
11
+ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
12
+ public logContext: plugins.smartlogInterfaces.ILogContext;
13
+ public minimumLogLevel: plugins.smartlogInterfaces.TLogLevel;
14
+
15
+ public uniInstanceId: string = plugins.isounique.uni();
16
+
17
+ private consoleEnabled: boolean;
18
+
19
+ private logRouter = new LogRouter();
20
+
21
+ public addLogDestination(logDestinationArg: plugins.smartlogInterfaces.ILogDestination) {
22
+ this.logRouter.addLogDestination(logDestinationArg);
23
+ }
24
+
25
+ constructor(optionsArg: ISmartlogContructorOptions) {
26
+ this.logContext = optionsArg.logContext;
27
+ this.minimumLogLevel = optionsArg.minimumLogLevel || 'silly';
28
+ }
29
+
30
+ // ============
31
+ // Logger Setup
32
+ // ============
33
+
34
+ /**
35
+ * enables console logging
36
+ */
37
+ public enableConsole(optionsArg?: { captureAll: boolean }) {
38
+ if (globalThis.process && optionsArg && optionsArg.captureAll) {
39
+ const process = globalThis.process;
40
+ const write = process.stdout.write;
41
+ process.stdout.write = (...args: any) => {
42
+ const logString: string = args[0];
43
+ if (!logString || typeof logString.startsWith !== 'function') {
44
+ // lets continue as planned
45
+ } else if (!logString.startsWith('LOG') && typeof logString === 'string') {
46
+ switch (true) {
47
+ case logString.substr(0, 20).includes('Error:'):
48
+ this.log('error', logString);
49
+ break;
50
+ default:
51
+ this.log('info', logString);
52
+ }
53
+ return true;
54
+ }
55
+ // fileStream.write(args[0]);
56
+ write.apply(process.stdout, args);
57
+ return true;
58
+ };
59
+
60
+ process.stderr.write = (...args: any) => {
61
+ if (!args[0].startsWith('LOG')) {
62
+ this.log('error', args[0]);
63
+ return true;
64
+ }
65
+ // fileStream.write(args[0]);
66
+ write.apply(process.stderr, args);
67
+ return true;
68
+ };
69
+ }
70
+ this.consoleEnabled = true;
71
+ }
72
+
73
+ // =============
74
+ // log functions
75
+ // =============
76
+ /**
77
+ * main log method
78
+ * @param logLevelArg - the log level
79
+ * @param logMessageArg - the log message
80
+ * @param logDataArg - any additional log data
81
+ * @param correlationArg - info about corrleations
82
+ */
83
+ public async log(
84
+ logLevelArg: plugins.smartlogInterfaces.TLogLevel,
85
+ logMessageArg: string,
86
+ logDataArg?: any,
87
+ correlationArg?: plugins.smartlogInterfaces.ILogCorrelation
88
+ ) {
89
+ correlationArg = {
90
+ ...{
91
+ id: plugins.isounique.uni(),
92
+ type: 'none',
93
+ instance: this.uniInstanceId,
94
+ },
95
+ ...correlationArg,
96
+ };
97
+
98
+ if (this.consoleEnabled) {
99
+ this.safeConsoleLog(`${logLevelArg}: ${logMessageArg}`);
100
+ }
101
+
102
+ const logPackage: plugins.smartlogInterfaces.ILogPackage = {
103
+ timestamp: Date.now(),
104
+ type: 'log',
105
+ context: this.logContext,
106
+ level: logLevelArg,
107
+ correlation: correlationArg,
108
+ message: logMessageArg,
109
+ };
110
+ if (logDataArg) {
111
+ logPackage.data = logDataArg;
112
+ }
113
+ await this.logRouter.routeLog(logPackage);
114
+ }
115
+
116
+ public increment(
117
+ logLevelArg: plugins.smartlogInterfaces.TLogLevel,
118
+ logMessageArg: string,
119
+ logDataArg?: any,
120
+ correlationArg: plugins.smartlogInterfaces.ILogCorrelation = {
121
+ id: plugins.isounique.uni(),
122
+ type: 'none',
123
+ }
124
+ ) {
125
+ if (this.consoleEnabled) {
126
+ this.safeConsoleLog(`INCREMENT: ${logLevelArg}: ${logMessageArg}`);
127
+ }
128
+ this.logRouter.routeLog({
129
+ timestamp: Date.now(),
130
+ type: 'increment',
131
+ context: this.logContext,
132
+ level: logLevelArg,
133
+ message: logMessageArg,
134
+ correlation: correlationArg,
135
+ });
136
+ }
137
+
138
+ public async handleLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
139
+ await this.logRouter.routeLog(logPackageArg);
140
+ }
141
+
142
+ private safeConsoleLog(logLine: string) {
143
+ console.log(
144
+ `LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLine}`
145
+ );
146
+ }
147
+
148
+ public createLogGroup(transactionId: string = 'none') {
149
+ return new LogGroup(this, transactionId);
150
+ }
151
+ }
@@ -0,0 +1,4 @@
1
+ import * as isounique from '@pushrocks/isounique';
2
+ import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';
3
+
4
+ export { isounique, smartlogInterfaces };