@spinajs/log
Advanced tools
Comparing version 1.1.1 to 1.1.5
import { IContainer, SyncModule } from "@spinajs/di"; | ||
import { LogTarget } from "./targets/LogTarget"; | ||
import { ICommonTargetOptions, LogLevel, ILogOptions, ILogRule, ILogTargetData, ITargetsOption } from "./types"; | ||
import { DataValidator } from "@spinajs/validation"; | ||
interface ILogTargetDesc { | ||
@@ -40,2 +39,3 @@ instance: LogTarget<ICommonTargetOptions>; | ||
static success(err: Error, message: string, name: string, ...args: any[]): void; | ||
static clearLoggers(): void; | ||
protected static LogBuffer: Map<string, ILogTargetData[]>; | ||
@@ -47,5 +47,4 @@ protected static AttachedToExitEvents: boolean; | ||
protected Targets: ILogTargetDesc[]; | ||
protected Validator: DataValidator; | ||
constructor(Name: string, Variables?: any, Parent?: Log); | ||
resolve(_: IContainer): void; | ||
resolve(container: IContainer): void; | ||
trace(message: string, ...args: any[]): void; | ||
@@ -52,0 +51,0 @@ trace(err: Error, message: string, ...args: any[]): void; |
@@ -36,8 +36,7 @@ "use strict"; | ||
exports.Log = void 0; | ||
const configuration_1 = require("@spinajs/configuration"); | ||
const types_1 = require("@spinajs/configuration/lib/types"); | ||
const di_1 = require("@spinajs/di"); | ||
const types_1 = require("./types"); | ||
const types_2 = require("./types"); | ||
const util = __importStar(require("util")); | ||
const glob_to_regexp_1 = __importDefault(require("glob-to-regexp")); | ||
const validation_1 = require("@spinajs/validation"); | ||
const exceptions_1 = require("@spinajs/exceptions"); | ||
@@ -49,3 +48,3 @@ function createLogMessageObject(err, message, level, logger, variables, ...args) { | ||
Level: level, | ||
Variables: Object.assign({ error: (err instanceof Error) ? err : undefined, level: types_1.LogLevelStrings[level].toUpperCase(), logger, message: tMsg }, variables) | ||
Variables: Object.assign({ error: (err instanceof Error) ? err : undefined, level: types_2.LogLevelStrings[level].toUpperCase(), logger, message: tMsg }, variables) | ||
}; | ||
@@ -80,28 +79,31 @@ } | ||
static trace(err, message, name, ...args) { | ||
Log_1.write(err, message, types_1.LogLevel.Trace, name, ...args); | ||
Log_1.write(err, message, types_2.LogLevel.Trace, name, ...args); | ||
} | ||
static debug(err, message, name, ...args) { | ||
Log_1.write(err, message, types_1.LogLevel.Debug, name, ...args); | ||
Log_1.write(err, message, types_2.LogLevel.Debug, name, ...args); | ||
} | ||
static info(err, message, name, ...args) { | ||
Log_1.write(err, message, types_1.LogLevel.Info, name, ...args); | ||
Log_1.write(err, message, types_2.LogLevel.Info, name, ...args); | ||
} | ||
static warn(err, message, name, ...args) { | ||
Log_1.write(err, message, types_1.LogLevel.Warn, name, ...args); | ||
Log_1.write(err, message, types_2.LogLevel.Warn, name, ...args); | ||
} | ||
static error(err, message, name, ...args) { | ||
Log_1.write(err, message, types_1.LogLevel.Error, name, ...args); | ||
Log_1.write(err, message, types_2.LogLevel.Error, name, ...args); | ||
} | ||
static fatal(err, message, name, ...args) { | ||
Log_1.write(err, message, types_1.LogLevel.Fatal, name, ...args); | ||
Log_1.write(err, message, types_2.LogLevel.Fatal, name, ...args); | ||
} | ||
static security(err, message, name, ...args) { | ||
Log_1.write(err, message, types_1.LogLevel.Security, name, ...args); | ||
Log_1.write(err, message, types_2.LogLevel.Security, name, ...args); | ||
} | ||
static success(err, message, name, ...args) { | ||
Log_1.write(err, message, types_1.LogLevel.Success, name, ...args); | ||
Log_1.write(err, message, types_2.LogLevel.Success, name, ...args); | ||
} | ||
static clearLoggers() { | ||
Log_1.Loggers.clear(); | ||
} | ||
static write(err, message, level, name, ...args) { | ||
const msg = createLogMessageObject(err, message, level, name, {}, ...args); | ||
const logName = arguments.length >= 4 ? name : message; | ||
const logName = name !== null && name !== void 0 ? name : message; | ||
// if we have already created logger write to it | ||
@@ -120,45 +122,34 @@ if (Log_1.Loggers.has(logName)) { | ||
} | ||
resolve(_) { | ||
/** | ||
* Check if options are valid, if not break, break, break | ||
*/ | ||
this.Validator.validate("spinajs/log.configuration.schema.json", this.Options); | ||
resolve(container) { | ||
const config = container.get(types_1.Configuration); | ||
this.Options = config.get("logger"); | ||
this.matchRulesToLogger(); | ||
this.resolveLogTargets(); | ||
if (!Log_1.AttachedToExitEvents) { | ||
process.on("uncaughtException", (err) => { | ||
Log_1.fatal(err, "Unhandled exception occured", "process"); | ||
}); | ||
process.on("unhandledRejection", (reason, p) => { | ||
Log_1.fatal(reason, "Unhandled rejection at Promise %s", "process", p); | ||
}); | ||
Log_1.AttachedToExitEvents = true; | ||
} | ||
this.writeBufferedMessages(); | ||
super.resolve(_); | ||
super.resolve(container); | ||
Log_1.Loggers.set(this.Name, this); | ||
} | ||
trace(err, message, ...args) { | ||
wrapWrite.apply(this, [types_1.LogLevel.Trace])(err, message, ...args); | ||
wrapWrite.apply(this, [types_2.LogLevel.Trace])(err, message, ...args); | ||
} | ||
debug(err, message, ...args) { | ||
wrapWrite.apply(this, [types_1.LogLevel.Debug])(err, message, ...args); | ||
wrapWrite.apply(this, [types_2.LogLevel.Debug])(err, message, ...args); | ||
} | ||
info(err, message, ...args) { | ||
wrapWrite.apply(this, [types_1.LogLevel.Info])(err, message, ...args); | ||
wrapWrite.apply(this, [types_2.LogLevel.Info])(err, message, ...args); | ||
} | ||
warn(err, message, ...args) { | ||
wrapWrite.apply(this, [types_1.LogLevel.Warn])(err, message, ...args); | ||
wrapWrite.apply(this, [types_2.LogLevel.Warn])(err, message, ...args); | ||
} | ||
error(err, message, ...args) { | ||
wrapWrite.apply(this, [types_1.LogLevel.Error])(err, message, ...args); | ||
wrapWrite.apply(this, [types_2.LogLevel.Error])(err, message, ...args); | ||
} | ||
fatal(err, message, ...args) { | ||
wrapWrite.apply(this, [types_1.LogLevel.Fatal])(err, message, ...args); | ||
wrapWrite.apply(this, [types_2.LogLevel.Fatal])(err, message, ...args); | ||
} | ||
security(err, message, ...args) { | ||
wrapWrite.apply(this, [types_1.LogLevel.Security])(err, message, ...args); | ||
wrapWrite.apply(this, [types_2.LogLevel.Security])(err, message, ...args); | ||
} | ||
success(err, message, ...args) { | ||
wrapWrite.apply(this, [types_1.LogLevel.Success])(err, message, ...args); | ||
wrapWrite.apply(this, [types_2.LogLevel.Success])(err, message, ...args); | ||
} | ||
@@ -200,3 +191,3 @@ child(name, variables) { | ||
this.Targets.forEach(t => { | ||
if (level >= types_1.StrToLogLevel[t.rule.level]) { | ||
if (level >= types_2.StrToLogLevel[t.rule.level]) { | ||
t.instance.write(lMsg); | ||
@@ -216,10 +207,2 @@ } | ||
Log.AttachedToExitEvents = false; | ||
__decorate([ | ||
(0, configuration_1.Config)("logger"), | ||
__metadata("design:type", Object) | ||
], Log.prototype, "Options", void 0); | ||
__decorate([ | ||
(0, di_1.Autoinject)(), | ||
__metadata("design:type", validation_1.DataValidator) | ||
], Log.prototype, "Validator", void 0); | ||
Log = Log_1 = __decorate([ | ||
@@ -226,0 +209,0 @@ (0, di_1.NewInstance)(), |
import { IColoredConsoleTargetOptions, ILogTargetData } from './../types'; | ||
import { IContainer } from '@spinajs/di'; | ||
import { LogTarget } from './LogTarget'; | ||
export declare const DEFAULT_THEME: { | ||
security: string[]; | ||
fatal: string; | ||
error: string; | ||
warn: string; | ||
success: string; | ||
info: string; | ||
debug: string; | ||
trace: string; | ||
}; | ||
export declare class ColoredConsoleTarget extends LogTarget<IColoredConsoleTargetOptions> { | ||
@@ -5,0 +15,0 @@ protected StdConsoleCallbackMap: { |
@@ -9,3 +9,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ColoredConsoleTarget = void 0; | ||
exports.ColoredConsoleTarget = exports.DEFAULT_THEME = void 0; | ||
const types_1 = require("./../types"); | ||
@@ -17,2 +17,12 @@ const di_1 = require("@spinajs/di"); | ||
const colors = require('colors/safe'); | ||
exports.DEFAULT_THEME = { | ||
security: ['red', "bgBrightWhite"], | ||
fatal: 'red', | ||
error: 'brightRed', | ||
warn: 'yellow', | ||
success: 'green', | ||
info: 'white', | ||
debug: 'gray', | ||
trace: 'gray', | ||
}; | ||
let ColoredConsoleTarget = class ColoredConsoleTarget extends LogTarget_1.LogTarget { | ||
@@ -33,4 +43,5 @@ constructor() { | ||
resolve(_) { | ||
colors.setTheme(this.Options.theme); | ||
this.resolve(_); | ||
var _a; | ||
colors.setTheme((_a = this.Options.theme) !== null && _a !== void 0 ? _a : exports.DEFAULT_THEME); | ||
super.resolve(_); | ||
} | ||
@@ -37,0 +48,0 @@ async write(data) { |
{ | ||
"name": "@spinajs/log", | ||
"version": "1.1.1", | ||
"version": "1.1.5", | ||
"description": "Log lib for all spinejs related libs", | ||
@@ -28,6 +28,6 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@spinajs/configuration": "^1.1.4", | ||
"@spinajs/configuration": "^1.1.6", | ||
"@spinajs/di": "^1.1.7", | ||
"@spinajs/exceptions": "^1.0.5", | ||
"@spinajs/validation": "^1.0.3", | ||
"@spinajs/validation": "^1.0.5", | ||
"colors": "^1.4.0", | ||
@@ -34,0 +34,0 @@ "glob": "^7.2.0", |
Sorry, the diff of this file is not supported yet
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
199238
51
1500
Updated@spinajs/validation@^1.0.5