@spinajs/internal-logger
Advanced tools
Comparing version 2.0.39 to 2.0.44
import { Bootstrapper } from "@spinajs/di"; | ||
import { ILogEntry, LogLevel } from "@spinajs/log-common"; | ||
/** | ||
* This class is used only in some spinajs packages | ||
* to avoid circular dependencies with logger and/or config packages | ||
* | ||
* It should not be used in production | ||
*/ | ||
export declare class InternalLogger extends Bootstrapper { | ||
bootstrap(): void | Promise<void>; | ||
bootstrap(): void; | ||
protected static LogBuffer: Map<string, ILogEntry[]>; | ||
@@ -12,0 +6,0 @@ static trace(message: string, name: string, ...args: any[]): void; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
@@ -8,7 +24,16 @@ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var InternalLogger_1; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.InternalLogger = void 0; | ||
const configuration_common_1 = require("@spinajs/configuration-common"); | ||
const di_1 = require("@spinajs/di"); | ||
const log_common_1 = require("@spinajs/log-common"); | ||
const _ = __importStar(require("lodash")); | ||
/** | ||
@@ -20,2 +45,21 @@ * This class is used only in some spinajs packages | ||
*/ | ||
function writeLogEntry(entry, logName) { | ||
const logger = di_1.DI.resolve("__log__", [logName]); | ||
if (logger) { | ||
logger | ||
.write(entry) | ||
.then((values) => { | ||
values.forEach((v) => { | ||
if (v.status === "rejected") { | ||
console.error(`Couldnt write to logger ${logName} message ${JSON.stringify({ | ||
level: entry.Level, | ||
vars: _.pick(entry.Variables, ["message"]), | ||
})}, reason: ${v.reason}`); | ||
} | ||
}); | ||
return; | ||
}) | ||
.catch(null); | ||
} | ||
} | ||
let InternalLogger = InternalLogger_1 = class InternalLogger extends di_1.Bootstrapper { | ||
@@ -25,18 +69,5 @@ bootstrap() { | ||
InternalLogger_1.LogBuffer.forEach((value, lName) => { | ||
const logger = di_1.DI.resolve("__log__", [lName]); | ||
if (logger) { | ||
value.forEach((msg) => { | ||
logger | ||
.write(msg) | ||
.then((values) => { | ||
values.forEach((v) => { | ||
if (v.status === "rejected") { | ||
console.error(`Couldnt write to logger ${lName} message ${JSON.stringify(msg)}, reason: ${v.reason}`); | ||
} | ||
}); | ||
return; | ||
}) | ||
.catch(null); | ||
}); | ||
} | ||
value.forEach((entry) => { | ||
writeLogEntry(entry, lName); | ||
}); | ||
}); | ||
@@ -49,3 +80,3 @@ InternalLogger_1.LogBuffer.clear(); | ||
// write all buffered messages to it | ||
if (di_1.DI.has("Configuration")) { | ||
if (di_1.DI.has(configuration_common_1.Configuration)) { | ||
// if we botstrapped before logger | ||
@@ -56,3 +87,5 @@ write(); | ||
// if not wait for event to occur | ||
di_1.DI.once("di.resolved.Configuration", () => write()); | ||
di_1.DI.once("di.resolved.Configuration", () => { | ||
write(); | ||
}); | ||
} | ||
@@ -88,17 +121,7 @@ } | ||
// when we have log system working, write directly to it | ||
if (di_1.DI.has("Configuration")) { | ||
const logger = di_1.DI.resolve("__log__", [logName]); | ||
if (logger) { | ||
// eslint-disable-next-line promise/no-promise-in-callback | ||
logger | ||
.write(msg) | ||
.then((values) => { | ||
values.forEach((v) => { | ||
if (v.status === "rejected") { | ||
console.error(v.reason); | ||
} | ||
}); | ||
return; | ||
}) | ||
.catch(null); | ||
// first we must check if Configuration module is resolved | ||
// to obtain information about log targets etc. | ||
if (di_1.DI.has(configuration_common_1.Configuration)) { | ||
if (di_1.DI.resolve("__log__", [logName])) { | ||
writeLogEntry(msg, logName); | ||
} | ||
@@ -105,0 +128,0 @@ else { |
{ | ||
"name": "@spinajs/internal-logger", | ||
"version": "2.0.39", | ||
"version": "2.0.44", | ||
"description": "internal logger used by some packages. do not use it in production environment", | ||
@@ -16,4 +16,11 @@ "homepage": "https://github.com/spinajs/main#readme", | ||
}, | ||
"devDependencies": { | ||
"@spinajs/configuration": "^2.0.44", | ||
"@spinajs/log": "^2.0.44", | ||
"chai": "^4.3.7", | ||
"sinon": "15.0.1" | ||
}, | ||
"dependencies": { | ||
"@spinajs/di": "^2.0.39" | ||
"@spinajs/di": "^2.0.44", | ||
"lodash": "^4.17.21" | ||
}, | ||
@@ -38,3 +45,3 @@ "scripts": { | ||
}, | ||
"gitHead": "002dc553b0ffffd72193d0121ac425a4083bc9ee" | ||
"gitHead": "1857a6e3626e0fed22ffb0b44b48d587c79898db" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15311
229
2
4
9
+ Addedlodash@^4.17.21
Updated@spinajs/di@^2.0.44