@spinajs/log 2.0.45 → 2.0.48

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,43 +1,45 @@
1
- /*
2
- 👋 Hi! This file was autogenerated by tslint-to-eslint-config.
3
- https://github.com/typescript-eslint/tslint-to-eslint-config
4
-
5
- It represents the closest reasonable ESLint configuration to this
6
- project's original TSLint configuration.
7
-
8
- We recommend eventually switching this configuration to extend from
9
- the recommended rulesets in typescript-eslint.
10
- https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md
11
-
12
- Happy linting! 💖
13
- */
14
- module.exports = {
15
- root: true,
16
- env: {
17
- browser: true,
18
- es6: true,
19
- },
20
- ignorePatterns: ['.eslintrc.js'],
21
- extends: [
22
- 'plugin:security/recommended',
23
- 'plugin:import/errors',
24
- 'plugin:import/warnings',
25
- 'plugin:import/typescript',
26
- 'plugin:promise/recommended',
27
- 'plugin:@typescript-eslint/recommended',
28
- 'plugin:@typescript-eslint/recommended-requiring-type-checking',
29
- ],
30
- parser: '@typescript-eslint/parser',
31
- parserOptions: {
32
- project: 'tsconfig.json',
33
- sourceType: 'module',
34
- },
35
- plugins: ['promise', 'prettier', 'eslint-plugin-import', 'eslint-plugin-prefer-arrow', '@typescript-eslint', 'tsdoc', 'security'],
36
- rules: {
37
- 'tsdoc/syntax': 'warn',
38
- "@typescript-eslint/require-await": "off",
39
- "security/detect-unsafe-regex" : "off",
40
- '@typescript-eslint/no-explicit-any': 'off',
41
- },
42
- };
1
+ /*
2
+ 👋 Hi! This file was autogenerated by tslint-to-eslint-config.
3
+ https://github.com/typescript-eslint/tslint-to-eslint-config
4
+
5
+ It represents the closest reasonable ESLint configuration to this
6
+ project's original TSLint configuration.
7
+
8
+ We recommend eventually switching this configuration to extend from
9
+ the recommended rulesets in typescript-eslint.
10
+ https://github.com/typescript-eslint/tslint-to-eslint-config/blob/master/docs/FAQs.md
11
+
12
+ Happy linting! 💖
13
+ */
14
+ module.exports = {
15
+ root: true,
16
+ env: {
17
+ browser: true,
18
+ es6: true,
19
+ },
20
+ ignorePatterns: ['.eslintrc.js'],
21
+ extends: [
22
+ 'plugin:security/recommended',
23
+ 'plugin:import/errors',
24
+ 'plugin:import/warnings',
25
+ 'plugin:import/typescript',
26
+ 'plugin:promise/recommended',
27
+ 'plugin:@typescript-eslint/recommended',
28
+ 'plugin:@typescript-eslint/recommended-requiring-type-checking',
29
+ ],
30
+ parser: '@typescript-eslint/parser',
31
+ parserOptions: {
32
+ project: 'tsconfig.json',
33
+ sourceType: 'module',
34
+ },
35
+ plugins: ['promise', 'prettier', 'eslint-plugin-import', 'eslint-plugin-prefer-arrow', '@typescript-eslint', 'tsdoc', 'security'],
36
+ rules: {
37
+ 'tsdoc/syntax': 'warn',
38
+ 'import/no-unresolved': 'off',
39
+
40
+ "@typescript-eslint/require-await": "off",
41
+ "security/detect-unsafe-regex" : "off",
42
+ '@typescript-eslint/no-explicit-any': 'off',
43
+ },
44
+ };
43
45
 
package/.mocharc.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extensions": ["ts"],
3
+ "spec": ["packages/configuration/test/*.test.ts"],
4
+ "node-option": [
5
+ "experimental-specifier-resolution=node",
6
+ "loader=ts-node/esm"
7
+ ]
8
+ }
package/package.json CHANGED
@@ -1,50 +1,54 @@
1
- {
2
- "name": "@spinajs/log",
3
- "version": "2.0.45",
4
- "description": "Log lib for all spinejs related libs",
5
- "main": "lib/index.js",
6
- "private": false,
7
- "scripts": {
8
- "test": "ts-mocha -p tsconfig.json test/**/*.test.ts",
9
- "coverage": "nyc npm run test",
10
- "build-docs": "rimraf docs && typedoc --options typedoc.json src/",
11
- "build": "npm run clean && npm run compile",
12
- "compile": "tsc -p tsconfig.build.json",
13
- "clean": "",
14
- "prepare": "npm run build",
15
- "format": "prettier --write \"src/**/*.ts\"",
16
- "lint": "eslint -c .eslintrc.js --ext .ts src",
17
- "prepublishOnly": "npm test && npm run lint",
18
- "preversion": "npm run lint",
19
- "version": "git add -A src",
20
- "postversion": "git push && git push --tags"
21
- },
22
- "author": "SpinaJS <spinajs@coderush.pl> (https://github.com/spinajs/log)",
23
- "license": "MIT",
24
- "bugs": {
25
- "url": "https://github.com/spinajs/log/issues"
26
- },
27
- "homepage": "https://github.com/spinajs/log#readme",
28
- "dependencies": {
29
- "@colors/colors": "^1.5.0",
30
- "@spinajs/configuration": "^2.0.45",
31
- "@spinajs/di": "^2.0.45",
32
- "@spinajs/exceptions": "^2.0.39",
33
- "@spinajs/log-common": "^2.0.45",
34
- "ajv": "^8.11.0",
35
- "chalk": "4.1.2",
36
- "glob": "^7.2.0",
37
- "glob-to-regexp": "^0.4.1",
38
- "lodash": "^4.17.14",
39
- "luxon": "^3.2.1",
40
- "node-schedule": "^2.1.0"
41
- },
42
- "devDependencies": {
43
- "@types/glob": "7.2.0",
44
- "@types/glob-to-regexp": "^0.4.1",
45
- "@types/mock-fs": "^4.13.1",
46
- "@types/node-schedule": "^1.3.2",
47
- "mock-fs": "^5.1.2"
48
- },
49
- "gitHead": "3aa423c570eae952dc79fe6a4704c3d2ccc178be"
50
- }
1
+ {
2
+ "name": "@spinajs/log",
3
+ "version": "2.0.48",
4
+ "description": "Log lib for all spinejs related libs",
5
+ "exports": "./lib/index.js",
6
+ "type": "module",
7
+ "private": false,
8
+ "engines": {
9
+ "node": ">=16.11"
10
+ },
11
+ "scripts": {
12
+ "build": "npm run clean && npm run compile",
13
+ "compile": "tsc -b tsconfig.json",
14
+ "rimraf": "./node_modules/rimraf/bin.js",
15
+ "clean": "rimraf lib/ && rimraf tsconfig.tsbuildinfo",
16
+ "test": "ts-mocha -p tsconfig.json test/**/*.test.ts",
17
+ "coverage": "nyc npm run test",
18
+ "build-docs": "rimraf docs && typedoc --options typedoc.json src/",
19
+ "format": "prettier --write \"src/**/*.ts\"",
20
+ "lint": "eslint -c .eslintrc.cjs --ext .ts src --fix",
21
+ "preversion": "npm run lint",
22
+ "version": "npm run format && git add -A src",
23
+ "postinstall": "npm run build"
24
+ },
25
+ "author": "SpinaJS <spinajs@coderush.pl> (https://github.com/spinajs/log)",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/spinajs/log/issues"
29
+ },
30
+ "homepage": "https://github.com/spinajs/log#readme",
31
+ "dependencies": {
32
+ "@colors/colors": "^1.5.0",
33
+ "@spinajs/configuration": "^2.0.46",
34
+ "@spinajs/di": "^2.0.46",
35
+ "@spinajs/exceptions": "^2.0.39",
36
+ "@spinajs/internal-logger": "^2.0.46",
37
+ "@spinajs/log-common": "^2.0.46",
38
+ "ajv": "^8.12.0",
39
+ "chalk": "5.2.0",
40
+ "glob": "^8.1.0",
41
+ "glob-to-regexp": "^0.4.1",
42
+ "lodash": "^4.17.21",
43
+ "luxon": "^3.2.1",
44
+ "node-schedule": "^2.1.1"
45
+ },
46
+ "devDependencies": {
47
+ "@types/glob": "8.0.1",
48
+ "@types/glob-to-regexp": "^0.4.1",
49
+ "@types/mock-fs": "^4.13.1",
50
+ "@types/node-schedule": "^2.1.0",
51
+ "mock-fs": "^5.2.0"
52
+ },
53
+ "gitHead": "002dc553b0ffffd72193d0121ac425a4083bc9ee"
54
+ }
@@ -1,4 +0,0 @@
1
- import { Bootstrapper } from "@spinajs/di";
2
- export declare class LogBotstrapper extends Bootstrapper {
3
- bootstrap(): void;
4
- }
package/lib/bootstrap.js DELETED
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.LogBotstrapper = void 0;
13
- const di_1 = require("@spinajs/di");
14
- const log_1 = require("./log");
15
- const log_configuration_1 = __importDefault(require("./schemas/log.configuration"));
16
- let LogBotstrapper = class LogBotstrapper extends di_1.Bootstrapper {
17
- bootstrap() {
18
- di_1.DI.register(log_configuration_1.default).asValue("__configurationSchema__");
19
- // check if we run tests,
20
- // hook for uncaughtException causes to not showing
21
- // mocha errors in console
22
- if (!process.env.TESTING) {
23
- process.on("uncaughtException", (err) => {
24
- const log = di_1.DI.resolve(log_1.Log, ["process"]);
25
- log.fatal(err, "Unhandled exception occured");
26
- });
27
- process.on("unhandledRejection", (reason, p) => {
28
- const log = di_1.DI.resolve(log_1.Log, ["process"]);
29
- log.fatal(reason, "Unhandled rejection at Promise %s", p);
30
- });
31
- }
32
- }
33
- };
34
- LogBotstrapper = __decorate([
35
- (0, di_1.Injectable)(di_1.Bootstrapper)
36
- ], LogBotstrapper);
37
- exports.LogBotstrapper = LogBotstrapper;
38
- //# sourceMappingURL=bootstrap.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bootstrap.js","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAA2D;AAC3D,+BAA4B;AAC5B,oFAA+D;AAG/D,IAAa,cAAc,GAA3B,MAAa,cAAe,SAAQ,iBAAY;IACvC,SAAS;QACd,OAAE,CAAC,QAAQ,CAAC,2BAAoB,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAErE,yBAAyB;QACzB,mDAAmD;QACnD,0BAA0B;QAC1B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE;YACxB,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,CAAC,GAAG,EAAE,EAAE;gBACtC,MAAM,GAAG,GAAG,OAAE,CAAC,OAAO,CAAC,SAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;gBACzC,GAAG,CAAC,KAAK,CAAC,GAAG,EAAE,6BAA6B,CAAC,CAAC;YAChD,CAAC,CAAC,CAAC;YAEH,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBAC7C,MAAM,GAAG,GAAG,OAAE,CAAC,OAAO,CAAC,SAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;gBACzC,GAAG,CAAC,KAAK,CAAC,MAAe,EAAE,mCAAmC,EAAE,CAAC,CAAC,CAAC;YACrE,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAA;AAnBY,cAAc;IAD1B,IAAA,eAAU,EAAC,iBAAY,CAAC;GACZ,cAAc,CAmB1B;AAnBY,wCAAc"}
@@ -1,6 +0,0 @@
1
- /**
2
- * Creates ( if not exists ) new logger instance with given name and optional variables
3
- * @param name - name of logger
4
- * @param variables - optional log variables
5
- */
6
- export declare function Logger(name: string, variables?: Record<string, unknown>): (target: any, key: string) => any;
package/lib/decorators.js DELETED
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Logger = void 0;
4
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
5
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
6
- const di_1 = require("@spinajs/di");
7
- const log_1 = require("./log");
8
- /**
9
- * Creates ( if not exists ) new logger instance with given name and optional variables
10
- * @param name - name of logger
11
- * @param variables - optional log variables
12
- */
13
- function Logger(name, variables) {
14
- return (target, key) => {
15
- let logger;
16
- // property getter
17
- const getter = () => {
18
- if (!logger) {
19
- const allLoggers = di_1.DI.get(Array.ofType(log_1.Log));
20
- const found = allLoggers.find((l) => l.Name);
21
- if (found) {
22
- logger = found;
23
- }
24
- else {
25
- logger = di_1.DI.resolve(log_1.Log, [name, variables]);
26
- }
27
- }
28
- return logger;
29
- };
30
- // Create new property with getter and setter
31
- Object.defineProperty(target, key, {
32
- get: getter,
33
- enumerable: false,
34
- configurable: false,
35
- });
36
- };
37
- }
38
- exports.Logger = Logger;
39
- //# sourceMappingURL=decorators.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"decorators.js","sourceRoot":"","sources":["../src/decorators.ts"],"names":[],"mappings":";;;AAAA,+DAA+D;AAC/D,4DAA4D;AAC5D,oCAAiC;AACjC,+BAA4B;AAE5B;;;;GAIG;AACH,SAAgB,MAAM,CAAC,IAAY,EAAE,SAAmC;IACtE,OAAO,CAAC,MAAW,EAAE,GAAW,EAAO,EAAE;QACvC,IAAI,MAAW,CAAC;QAEhB,kBAAkB;QAClB,MAAM,MAAM,GAAG,GAAG,EAAE;YAClB,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,UAAU,GAAG,OAAE,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,SAAG,CAAC,CAAC,CAAC;gBAC7C,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAE7C,IAAI,KAAK,EAAE;oBACT,MAAM,GAAG,KAAK,CAAC;iBAChB;qBAAM;oBACL,MAAM,GAAG,OAAE,CAAC,OAAO,CAAC,SAAG,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;iBAC7C;aACF;YACD,OAAO,MAAM,CAAC;QAChB,CAAC,CAAC;QAEF,6CAA6C;QAC7C,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE;YACjC,GAAG,EAAE,MAAM;YACX,UAAU,EAAE,KAAK;YACjB,YAAY,EAAE,KAAK;SACpB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AA1BD,wBA0BC"}
package/lib/index.d.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from "@spinajs/log-common";
2
- export * from "./targets";
3
- export * from "./log";
4
- export * from "./decorators";
5
- export * from "./bootstrap";
package/lib/index.js DELETED
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("@spinajs/log-common"), exports);
18
- __exportStar(require("./targets"), exports);
19
- __exportStar(require("./log"), exports);
20
- __exportStar(require("./decorators"), exports);
21
- __exportStar(require("./bootstrap"), exports);
22
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAoC;AACpC,4CAA0B;AAC1B,wCAAsB;AACtB,+CAA6B;AAC7B,8CAA4B"}
package/lib/log.d.ts DELETED
@@ -1,49 +0,0 @@
1
- import { Container, SyncService } from "@spinajs/di";
2
- import { ILogOptions, ILogRule, ILogEntry, LogVariables, ILog, ILogTargetDesc } from "@spinajs/log-common";
3
- /**
4
- * Default log implementation interface. Taken from bunyan. Feel free to implement own.
5
- */
6
- export declare class Log extends SyncService implements ILog {
7
- Name: string;
8
- protected Parent?: Log;
9
- /**
10
- * STATIC METHODS FOR LOGGER, ALLOWS TO LOG TO ANY TARGET
11
- * EVEN BEFORE LOG MODULE INITIALIZATION.
12
- *
13
- * Prevents from losing log message when initializing modules
14
- */
15
- static Loggers: Map<string, Log>;
16
- Timers: Map<string, Date>;
17
- Targets: ILogTargetDesc[];
18
- static clearLoggers(): void;
19
- protected static AttachedToExitEvents: boolean;
20
- protected Options: ILogOptions;
21
- protected Rules: ILogRule[];
22
- protected Variables: Record<string, any>;
23
- protected Container: Container;
24
- constructor(Name: string, variables?: Record<string, unknown>, Parent?: Log);
25
- addVariable(name: string, value: unknown): void;
26
- timeStart(name: string): void;
27
- timeEnd(name: string): number;
28
- resolve(): void;
29
- trace(message: string, ...args: any[]): void;
30
- trace(err: Error, message: string, ...args: any[]): void;
31
- debug(message: string, ...args: any[]): void;
32
- debug(err: Error, message: string, ...args: any[]): void;
33
- info(message: string, ...args: any[]): void;
34
- info(err: Error, message: string, ...args: any[]): void;
35
- warn(message: string, ...args: any[]): void;
36
- warn(err: Error, message: string, ...args: any[]): void;
37
- error(message: string, ...args: any[]): void;
38
- error(err: Error, message: string, ...args: any[]): void;
39
- fatal(message: string, ...args: any[]): void;
40
- fatal(err: Error, message: string, ...args: any[]): void;
41
- security(message: string, ...args: any[]): void;
42
- security(err: Error, message: string, ...args: any[]): void;
43
- success(message: string, ...args: any[]): void;
44
- success(err: Error, message: string, ...args: any[]): void;
45
- write(entry: ILogEntry): Promise<PromiseSettledResult<void>[]>;
46
- child(name: string, variables?: LogVariables): Log;
47
- protected resolveLogTargets(): void;
48
- protected matchRulesToLogger(): void;
49
- }
package/lib/log.js DELETED
@@ -1,194 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- var Log_1;
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.Log = void 0;
17
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
18
- /* eslint-disable @typescript-eslint/no-unsafe-call */
19
- /* eslint-disable @typescript-eslint/no-unsafe-argument */
20
- const configuration_1 = require("@spinajs/configuration");
21
- const di_1 = require("@spinajs/di");
22
- const log_common_1 = require("@spinajs/log-common");
23
- const glob_to_regexp_1 = __importDefault(require("glob-to-regexp"));
24
- const exceptions_1 = require("@spinajs/exceptions");
25
- function wrapWrite(level) {
26
- return (err, message, ...args) => {
27
- if (err instanceof Error) {
28
- return this.write((0, log_common_1.createLogMessageObject)(err, message, level, this.Name, this.Variables, ...args));
29
- }
30
- else {
31
- if (message) {
32
- return this.write((0, log_common_1.createLogMessageObject)(err, null, level, this.Name, this.Variables, ...[message, ...args]));
33
- }
34
- else {
35
- return this.write((0, log_common_1.createLogMessageObject)(err, null, level, this.Name, this.Variables, ...args));
36
- }
37
- }
38
- };
39
- }
40
- /**
41
- * Default log implementation interface. Taken from bunyan. Feel free to implement own.
42
- */
43
- let Log = Log_1 = class Log extends di_1.SyncService {
44
- constructor(Name, variables, Parent) {
45
- super();
46
- this.Name = Name;
47
- this.Parent = Parent;
48
- this.Timers = new Map();
49
- this.Variables = {};
50
- this.Variables = variables !== null && variables !== void 0 ? variables : {};
51
- }
52
- static clearLoggers() {
53
- Log_1.Loggers.clear();
54
- }
55
- addVariable(name, value) {
56
- this.Variables[`${name}`] = value;
57
- }
58
- timeStart(name) {
59
- if (this.Timers.has(name)) {
60
- return;
61
- }
62
- this.Timers.set(name, new Date());
63
- }
64
- timeEnd(name) {
65
- if (this.Timers.has(name)) {
66
- const cTime = new Date();
67
- const diff = cTime.getTime() - this.Timers.get(name).getTime();
68
- this.Timers.delete(name);
69
- return diff;
70
- }
71
- return 0;
72
- }
73
- resolve() {
74
- const config = this.Container.get(configuration_1.Configuration);
75
- if (!config) {
76
- throw new Error(`Configuration module is not avaible. Please resolve configuration module before any logging can occur`);
77
- }
78
- this.Options = config.get("logger", {
79
- targets: [
80
- {
81
- name: "Console",
82
- type: "ConsoleTarget",
83
- },
84
- ],
85
- rules: [{ name: "*", level: "trace", target: "Console" }],
86
- });
87
- this.matchRulesToLogger();
88
- this.resolveLogTargets();
89
- super.resolve();
90
- Log_1.Loggers.set(this.Name, this);
91
- }
92
- trace(err, message, ...args) {
93
- wrapWrite.apply(this, [log_common_1.LogLevel.Trace])(err, message, ...args);
94
- }
95
- debug(err, message, ...args) {
96
- wrapWrite.apply(this, [log_common_1.LogLevel.Debug])(err, message, ...args);
97
- }
98
- info(err, message, ...args) {
99
- wrapWrite.apply(this, [log_common_1.LogLevel.Info])(err, message, ...args);
100
- }
101
- warn(err, message, ...args) {
102
- wrapWrite.apply(this, [log_common_1.LogLevel.Warn])(err, message, ...args);
103
- }
104
- error(err, message, ...args) {
105
- wrapWrite.apply(this, [log_common_1.LogLevel.Error])(err, message, ...args);
106
- }
107
- fatal(err, message, ...args) {
108
- wrapWrite.apply(this, [log_common_1.LogLevel.Fatal])(err, message, ...args);
109
- }
110
- security(err, message, ...args) {
111
- wrapWrite.apply(this, [log_common_1.LogLevel.Security])(err, message, ...args);
112
- }
113
- success(err, message, ...args) {
114
- wrapWrite.apply(this, [log_common_1.LogLevel.Success])(err, message, ...args);
115
- }
116
- write(entry) {
117
- if (entry.Variables.logger === this.Name) {
118
- return Promise.allSettled(this.Targets.filter((t) => entry.Level >= log_common_1.StrToLogLevel[t.rule.level]).map((t) => {
119
- if (!t.instance) {
120
- throw new exceptions_1.InvalidOperation(`Target for rule ${t.rule.name} not exists`);
121
- }
122
- return t.instance.write(entry);
123
- }));
124
- }
125
- }
126
- child(name, variables) {
127
- return di_1.DI.resolve(Log_1, [
128
- `${this.Name}.${name}`,
129
- Object.assign(Object.assign({}, this.Variables), variables),
130
- this,
131
- ]);
132
- }
133
- resolveLogTargets() {
134
- this.Targets = this.Rules.map((r) => {
135
- const found = this.Options.targets.filter((t) => {
136
- return Array.isArray(r.target) ? r.target.includes(t.name) : r.target === t.name;
137
- });
138
- if (!found) {
139
- throw new exceptions_1.InvalidOption(`No target matching rule ${r.name}`);
140
- }
141
- return found.map((f) => {
142
- return {
143
- instance: di_1.DI.resolve(f.type, [f]),
144
- options: f,
145
- rule: r,
146
- };
147
- });
148
- }).reduce((prev, curr) => prev.concat(...curr), []);
149
- }
150
- matchRulesToLogger() {
151
- this.Rules = this.Options.rules.filter((r) => {
152
- const g = (0, glob_to_regexp_1.default)(r.name);
153
- // BUG: g.test throws vscode err ?
154
- return g.test(this.Name);
155
- });
156
- }
157
- };
158
- /**
159
- * STATIC METHODS FOR LOGGER, ALLOWS TO LOG TO ANY TARGET
160
- * EVEN BEFORE LOG MODULE INITIALIZATION.
161
- *
162
- * Prevents from losing log message when initializing modules
163
- */
164
- Log.Loggers = new Map();
165
- Log.AttachedToExitEvents = false;
166
- __decorate([
167
- (0, di_1.Autoinject)(),
168
- __metadata("design:type", di_1.Container)
169
- ], Log.prototype, "Container", void 0);
170
- Log = Log_1 = __decorate([
171
- (0, di_1.NewInstance)(),
172
- __metadata("design:paramtypes", [String, Object, Log])
173
- ], Log);
174
- exports.Log = Log;
175
- const logFactoryFunction = (container, logName) => {
176
- if (Log.Loggers.has(logName)) {
177
- return Log.Loggers.get(logName);
178
- }
179
- return container.resolve("__logImplementation__", [logName]);
180
- };
181
- // register as string identifier to allow for
182
- // resolving logs without referencing class
183
- // to avoid circular dependencies in some @spinajs packages
184
- // it should not be used in production code
185
- di_1.DI.register(logFactoryFunction).as("__log__");
186
- // register log factory function as Log class
187
- // this way we can create or return already created
188
- // log objects
189
- di_1.DI.register(logFactoryFunction).as(Log);
190
- // register Log class as string literal
191
- // so we can resolve Log class
192
- // it should not be used in production code
193
- di_1.DI.register(Log).as("__logImplementation__");
194
- //# sourceMappingURL=log.js.map
package/lib/log.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA4D;AAC5D,sDAAsD;AACtD,0DAA0D;AAC1D,0DAAuD;AACvD,oCAA8F;AAC9F,oDAA6L;AAC7L,oEAA0C;AAC1C,oDAAsE;AAEtE,SAAS,SAAS,CAAY,KAAe;IAC3C,OAAO,CAAC,GAAmB,EAAE,OAAuB,EAAE,GAAG,IAAW,EAAE,EAAE;QACtE,IAAI,GAAG,YAAY,KAAK,EAAE;YACxB,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,mCAAsB,EAAC,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;SACpG;aAAM;YACL,IAAI,OAAO,EAAE;gBACX,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,mCAAsB,EAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;aAC/G;iBAAM;gBACL,OAAO,IAAI,CAAC,KAAK,CAAC,IAAA,mCAAsB,EAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC;aACjG;SACF;IACH,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AAEH,IAAa,GAAG,WAAhB,MAAa,GAAI,SAAQ,gBAAW;IA0BlC,YAAmB,IAAY,EAAE,SAAmC,EAAY,MAAY;QAC1F,KAAK,EAAE,CAAC;QADS,S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