@spinajs/log-common
Advanced tools
Comparing version 2.0.110 to 2.0.111
@@ -1,2 +0,2 @@ | ||
import { SyncService } from "@spinajs/di"; | ||
import { Container, SyncService } from "@spinajs/di"; | ||
export declare enum LogLevel { | ||
@@ -159,36 +159,52 @@ Security = 999, | ||
} | ||
export interface ILog { | ||
Targets: ILogTargetDesc[]; | ||
trace(message: string, ...args: any[]): void; | ||
trace(err: Error, message: string, ...args: any[]): void; | ||
trace(err: Error | string, message: string | any[], ...args: any[]): void; | ||
debug(message: string, ...args: any[]): void; | ||
debug(err: Error, message: string, ...args: any[]): void; | ||
debug(err: Error | string, message: string | any[], ...args: any[]): void; | ||
info(message: string, ...args: any[]): void; | ||
info(err: Error, message: string, ...args: any[]): void; | ||
info(err: Error | string, message: string | any[], ...args: any[]): void; | ||
warn(message: string, ...args: any[]): void; | ||
warn(err: Error, message: string, ...args: any[]): void; | ||
warn(err: Error | string, message: string | any[], ...args: any[]): void; | ||
error(message: string, ...args: any[]): void; | ||
error(err: Error, message: string, ...args: any[]): void; | ||
error(err: Error | string, message: string | any[], ...args: any[]): void; | ||
fatal(message: string, ...args: any[]): void; | ||
fatal(err: Error, message: string, ...args: any[]): void; | ||
fatal(err: Error | string, message: string | any[], ...args: any[]): void; | ||
security(message: string, ...args: any[]): void; | ||
security(err: Error, message: string, ...args: any[]): void; | ||
security(err: Error | string, message: string | any[], ...args: any[]): void; | ||
success(message: string, ...args: any[]): void; | ||
success(err: Error, message: string, ...args: any[]): void; | ||
success(err: Error | string, message: string | any[], ...args: any[]): void; | ||
child(name: string, variables?: LogVariables): ILog; | ||
write(entry: ILogEntry): Promise<PromiseSettledResult<void>[]>; | ||
export declare function createLogMessageObject(err: Error | string, message: string | any[], level: LogLevel, logger: string, variables: any, ...args: any[]): ILogEntry; | ||
export declare abstract class Log extends SyncService { | ||
static Loggers: Map<string, Log>; | ||
static InternalLoggers: Map<string, Log>; | ||
Timers: Map<string, Date>; | ||
protected Targets: ILogTargetDesc[]; | ||
Name: string; | ||
protected static AttachedToExitEvents: boolean; | ||
protected Options: ILogOptions; | ||
protected Rules: ILogRule[]; | ||
protected Container: Container; | ||
protected Variables: Record<string, any>; | ||
static clearLoggers(): Promise<Promise<void>[]>; | ||
addVariable(name: string, value: unknown): void; | ||
timeStart(name: string): void; | ||
timeEnd(name: string): number; | ||
child(name: string, variables?: LogVariables): Log; | ||
abstract trace(message: string, ...args: any[]): void; | ||
abstract trace(err: Error, message: string, ...args: any[]): void; | ||
abstract trace(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract debug(message: string, ...args: any[]): void; | ||
abstract debug(err: Error, message: string, ...args: any[]): void; | ||
abstract debug(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract info(message: string, ...args: any[]): void; | ||
abstract info(err: Error, message: string, ...args: any[]): void; | ||
abstract info(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract warn(message: string, ...args: any[]): void; | ||
abstract warn(err: Error, message: string, ...args: any[]): void; | ||
abstract warn(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract error(message: string, ...args: any[]): void; | ||
abstract error(err: Error, message: string, ...args: any[]): void; | ||
abstract error(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract fatal(message: string, ...args: any[]): void; | ||
abstract fatal(err: Error, message: string, ...args: any[]): void; | ||
abstract fatal(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract security(message: string, ...args: any[]): void; | ||
abstract security(err: Error, message: string, ...args: any[]): void; | ||
abstract security(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract success(message: string, ...args: any[]): void; | ||
abstract success(err: Error, message: string, ...args: any[]): void; | ||
abstract success(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract write(entry: ILogEntry): Promise<PromiseSettledResult<void>[]>; | ||
} | ||
/** | ||
* Creates ( if not exists ) new logger instance with given name and optional variables | ||
* @param name - name of logger | ||
* @param variables - optional log variables | ||
*/ | ||
export declare function Logger(name: string, variables?: Record<string, unknown>): (target: any, key: string) => any; | ||
export type LogVariables = ILogStaticVariables & ILogVariable; | ||
export declare function createLogMessageObject(err: Error | string, message: string | any[], level: LogLevel, logger: string, variables: any, ...args: any[]): ILogEntry; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -18,2 +18,8 @@ "use strict"; | ||
}); | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
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; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
@@ -26,2 +32,5 @@ if (mod && mod.__esModule) return mod; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -31,3 +40,3 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createLogMessageObject = exports.LogTarget = exports.LogLevelStrings = exports.StrToLogLevel = exports.LogLevel = void 0; | ||
exports.Logger = exports.Log = exports.createLogMessageObject = exports.LogTarget = exports.LogLevelStrings = exports.StrToLogLevel = exports.LogLevel = void 0; | ||
const di_1 = require("@spinajs/di"); | ||
@@ -97,2 +106,83 @@ const lodash_1 = __importDefault(require("lodash")); | ||
exports.createLogMessageObject = createLogMessageObject; | ||
class Log extends di_1.SyncService { | ||
constructor() { | ||
super(...arguments); | ||
this.Timers = new Map(); | ||
this.Variables = {}; | ||
} | ||
static clearLoggers() { | ||
return Promise.all([...Log.Loggers.values()].map((l) => l.dispose())).then(() => { | ||
Log.Loggers.clear(); | ||
}).then(() => { | ||
return [...Log.InternalLoggers.values()].map((l) => l.dispose()); | ||
}); | ||
} | ||
addVariable(name, value) { | ||
this.Variables[`${name}`] = value; | ||
} | ||
timeStart(name) { | ||
if (this.Timers.has(name)) { | ||
return; | ||
} | ||
this.Timers.set(name, new Date()); | ||
} | ||
timeEnd(name) { | ||
if (this.Timers.has(name)) { | ||
const cTime = new Date(); | ||
const diff = cTime.getTime() - this.Timers.get(name).getTime(); | ||
this.Timers.delete(name); | ||
return diff; | ||
} | ||
return 0; | ||
} | ||
child(name, variables) { | ||
return di_1.DI.resolve(Log, [ | ||
`${this.Name}.${name}`, | ||
{ | ||
...this.Variables, | ||
...variables, | ||
}, | ||
this, | ||
]); | ||
} | ||
} | ||
Log.Loggers = new Map(); | ||
Log.InternalLoggers = new Map(); | ||
Log.AttachedToExitEvents = false; | ||
__decorate([ | ||
(0, di_1.Autoinject)(), | ||
__metadata("design:type", di_1.Container) | ||
], Log.prototype, "Container", void 0); | ||
exports.Log = Log; | ||
/** | ||
* Creates ( if not exists ) new logger instance with given name and optional variables | ||
* @param name - name of logger | ||
* @param variables - optional log variables | ||
*/ | ||
function Logger(name, variables) { | ||
return (target, key) => { | ||
let logger; | ||
// property getter | ||
const getter = () => { | ||
if (!logger) { | ||
const allLoggers = di_1.DI.get(Array.ofType(Log)); | ||
const found = allLoggers.find((l) => l.Name === name); | ||
if (found) { | ||
logger = found; | ||
} | ||
else { | ||
logger = di_1.DI.resolve(Log, [name, variables]); | ||
} | ||
} | ||
return logger; | ||
}; | ||
// Create new property with getter and setter | ||
Object.defineProperty(target, key, { | ||
get: getter, | ||
enumerable: false, | ||
configurable: false, | ||
}); | ||
}; | ||
} | ||
exports.Logger = Logger; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { SyncService } from "@spinajs/di"; | ||
import { Container, SyncService } from "@spinajs/di"; | ||
export declare enum LogLevel { | ||
@@ -159,36 +159,52 @@ Security = 999, | ||
} | ||
export interface ILog { | ||
Targets: ILogTargetDesc[]; | ||
trace(message: string, ...args: any[]): void; | ||
trace(err: Error, message: string, ...args: any[]): void; | ||
trace(err: Error | string, message: string | any[], ...args: any[]): void; | ||
debug(message: string, ...args: any[]): void; | ||
debug(err: Error, message: string, ...args: any[]): void; | ||
debug(err: Error | string, message: string | any[], ...args: any[]): void; | ||
info(message: string, ...args: any[]): void; | ||
info(err: Error, message: string, ...args: any[]): void; | ||
info(err: Error | string, message: string | any[], ...args: any[]): void; | ||
warn(message: string, ...args: any[]): void; | ||
warn(err: Error, message: string, ...args: any[]): void; | ||
warn(err: Error | string, message: string | any[], ...args: any[]): void; | ||
error(message: string, ...args: any[]): void; | ||
error(err: Error, message: string, ...args: any[]): void; | ||
error(err: Error | string, message: string | any[], ...args: any[]): void; | ||
fatal(message: string, ...args: any[]): void; | ||
fatal(err: Error, message: string, ...args: any[]): void; | ||
fatal(err: Error | string, message: string | any[], ...args: any[]): void; | ||
security(message: string, ...args: any[]): void; | ||
security(err: Error, message: string, ...args: any[]): void; | ||
security(err: Error | string, message: string | any[], ...args: any[]): void; | ||
success(message: string, ...args: any[]): void; | ||
success(err: Error, message: string, ...args: any[]): void; | ||
success(err: Error | string, message: string | any[], ...args: any[]): void; | ||
child(name: string, variables?: LogVariables): ILog; | ||
write(entry: ILogEntry): Promise<PromiseSettledResult<void>[]>; | ||
export declare function createLogMessageObject(err: Error | string, message: string | any[], level: LogLevel, logger: string, variables: any, ...args: any[]): ILogEntry; | ||
export declare abstract class Log extends SyncService { | ||
static Loggers: Map<string, Log>; | ||
static InternalLoggers: Map<string, Log>; | ||
Timers: Map<string, Date>; | ||
protected Targets: ILogTargetDesc[]; | ||
Name: string; | ||
protected static AttachedToExitEvents: boolean; | ||
protected Options: ILogOptions; | ||
protected Rules: ILogRule[]; | ||
protected Container: Container; | ||
protected Variables: Record<string, any>; | ||
static clearLoggers(): Promise<Promise<void>[]>; | ||
addVariable(name: string, value: unknown): void; | ||
timeStart(name: string): void; | ||
timeEnd(name: string): number; | ||
child(name: string, variables?: LogVariables): Log; | ||
abstract trace(message: string, ...args: any[]): void; | ||
abstract trace(err: Error, message: string, ...args: any[]): void; | ||
abstract trace(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract debug(message: string, ...args: any[]): void; | ||
abstract debug(err: Error, message: string, ...args: any[]): void; | ||
abstract debug(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract info(message: string, ...args: any[]): void; | ||
abstract info(err: Error, message: string, ...args: any[]): void; | ||
abstract info(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract warn(message: string, ...args: any[]): void; | ||
abstract warn(err: Error, message: string, ...args: any[]): void; | ||
abstract warn(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract error(message: string, ...args: any[]): void; | ||
abstract error(err: Error, message: string, ...args: any[]): void; | ||
abstract error(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract fatal(message: string, ...args: any[]): void; | ||
abstract fatal(err: Error, message: string, ...args: any[]): void; | ||
abstract fatal(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract security(message: string, ...args: any[]): void; | ||
abstract security(err: Error, message: string, ...args: any[]): void; | ||
abstract security(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract success(message: string, ...args: any[]): void; | ||
abstract success(err: Error, message: string, ...args: any[]): void; | ||
abstract success(err: Error | string, message: string | any[], ...args: any[]): void; | ||
abstract write(entry: ILogEntry): Promise<PromiseSettledResult<void>[]>; | ||
} | ||
/** | ||
* Creates ( if not exists ) new logger instance with given name and optional variables | ||
* @param name - name of logger | ||
* @param variables - optional log variables | ||
*/ | ||
export declare function Logger(name: string, variables?: Record<string, unknown>): (target: any, key: string) => any; | ||
export type LogVariables = ILogStaticVariables & ILogVariable; | ||
export declare function createLogMessageObject(err: Error | string, message: string | any[], level: LogLevel, logger: string, variables: any, ...args: any[]): ILogEntry; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,2 +0,11 @@ | ||
import { SyncService } from "@spinajs/di"; | ||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | ||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | ||
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; | ||
return c > 3 && r && Object.defineProperty(target, key, r), r; | ||
}; | ||
var __metadata = (this && this.__metadata) || function (k, v) { | ||
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); | ||
}; | ||
import { Autoinject, Container, DI, SyncService } from "@spinajs/di"; | ||
import _ from "lodash"; | ||
@@ -63,2 +72,81 @@ import * as util from "util"; | ||
} | ||
export class Log extends SyncService { | ||
constructor() { | ||
super(...arguments); | ||
this.Timers = new Map(); | ||
this.Variables = {}; | ||
} | ||
static clearLoggers() { | ||
return Promise.all([...Log.Loggers.values()].map((l) => l.dispose())).then(() => { | ||
Log.Loggers.clear(); | ||
}).then(() => { | ||
return [...Log.InternalLoggers.values()].map((l) => l.dispose()); | ||
}); | ||
} | ||
addVariable(name, value) { | ||
this.Variables[`${name}`] = value; | ||
} | ||
timeStart(name) { | ||
if (this.Timers.has(name)) { | ||
return; | ||
} | ||
this.Timers.set(name, new Date()); | ||
} | ||
timeEnd(name) { | ||
if (this.Timers.has(name)) { | ||
const cTime = new Date(); | ||
const diff = cTime.getTime() - this.Timers.get(name).getTime(); | ||
this.Timers.delete(name); | ||
return diff; | ||
} | ||
return 0; | ||
} | ||
child(name, variables) { | ||
return DI.resolve(Log, [ | ||
`${this.Name}.${name}`, | ||
{ | ||
...this.Variables, | ||
...variables, | ||
}, | ||
this, | ||
]); | ||
} | ||
} | ||
Log.Loggers = new Map(); | ||
Log.InternalLoggers = new Map(); | ||
Log.AttachedToExitEvents = false; | ||
__decorate([ | ||
Autoinject(), | ||
__metadata("design:type", Container) | ||
], Log.prototype, "Container", void 0); | ||
/** | ||
* Creates ( if not exists ) new logger instance with given name and optional variables | ||
* @param name - name of logger | ||
* @param variables - optional log variables | ||
*/ | ||
export function Logger(name, variables) { | ||
return (target, key) => { | ||
let logger; | ||
// property getter | ||
const getter = () => { | ||
if (!logger) { | ||
const allLoggers = DI.get(Array.ofType(Log)); | ||
const found = allLoggers.find((l) => l.Name === name); | ||
if (found) { | ||
logger = found; | ||
} | ||
else { | ||
logger = DI.resolve(Log, [name, variables]); | ||
} | ||
} | ||
return logger; | ||
}; | ||
// Create new property with getter and setter | ||
Object.defineProperty(target, key, { | ||
get: getter, | ||
enumerable: false, | ||
configurable: false, | ||
}); | ||
}; | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"version": "2.0.110", | ||
"version": "2.0.111", | ||
"description": "Log lib for all spinejs related libs", | ||
@@ -56,4 +56,4 @@ | ||
"dependencies": { | ||
"@spinajs/di": "^2.0.110" | ||
"@spinajs/di": "^2.0.111" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
175819
749
Updated@spinajs/di@^2.0.111