Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
5dff4961fb | |||
3a98c2e7d9 | |||
39d08ef53a | |||
74e6bc7a3c | |||
5d0056558a | |||
2b920e2f5e | |||
793cd38381 | |||
7a05e4484d | |||
2fe657f5af | |||
5508beae25 | |||
f2c0f1acff | |||
5805cc51a6 | |||
c9c38368c1 | |||
640eddae2d |
22
package-lock.json
generated
22
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartlog",
|
"name": "@pushrocks/smartlog",
|
||||||
"version": "2.0.2",
|
"version": "2.0.9",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -157,12 +157,20 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"@pushrocks/smartlog-interfaces": "^1.0.9"
|
"@pushrocks/smartlog-interfaces": "^1.0.9"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@pushrocks/smartlog-interfaces": {
|
||||||
|
"version": "1.0.15",
|
||||||
|
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-1.0.15.tgz",
|
||||||
|
"integrity": "sha512-dn9a+IhneukhtVGQG031oodOITmmQ5s5hcMThd+cMUQL3XYTbLPnZVuJfTDeWCT0iqLqrBD/qp2d1RRc3W/qIQ==",
|
||||||
|
"dev": true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@pushrocks/smartlog-interfaces": {
|
"@pushrocks/smartlog-interfaces": {
|
||||||
"version": "1.0.9",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-1.0.9.tgz",
|
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-2.0.2.tgz",
|
||||||
"integrity": "sha512-0qwpomrRN0kFjmhR9m1iHYXoISoNuXtRP0Wr+JtkYyURLwKHMaW8Xoznf8MzXJptRfqufJi3Fxh5HodpPrIZUA=="
|
"integrity": "sha512-kJNQ/6kfljgtwebhoiD8WtRWfdVhOoE1nr8FoUJLlOjLphU8SPa42Hg6/yPkSTaGxWwDhk6PkMJl64O7HNjRUQ=="
|
||||||
},
|
},
|
||||||
"@pushrocks/smartpath": {
|
"@pushrocks/smartpath": {
|
||||||
"version": "4.0.1",
|
"version": "4.0.1",
|
||||||
@ -251,9 +259,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "10.12.1",
|
"version": "10.12.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.2.tgz",
|
||||||
"integrity": "sha512-i1sl+WCX2OCHeUi9oi7PiCNUtYFrpWhpcx878vpeq/tlZTKzcFdHePlyFHVbWqeuKN0SRPl/9ZFDSTsfv9h7VQ==",
|
"integrity": "sha512-53ElVDSnZeFUUFIYzI8WLQ25IhWzb6vbddNp8UHlXQyU0ET2RhV5zg0NfubzU7iNMh5bBXb0htCzfvrSVNgzaQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/vinyl": {
|
"@types/vinyl": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartlog",
|
"name": "@pushrocks/smartlog",
|
||||||
"version": "2.0.2",
|
"version": "2.0.9",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "winston based logger for large scale projects",
|
"description": "winston based logger for large scale projects",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -17,11 +17,11 @@
|
|||||||
"@gitzone/tsrun": "^1.1.13",
|
"@gitzone/tsrun": "^1.1.13",
|
||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.15",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
"@types/node": "^10.12.1",
|
"@types/node": "^10.12.2",
|
||||||
"tslint": "^5.11.0",
|
"tslint": "^5.11.0",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartlog-interfaces": "^1.0.9"
|
"@pushrocks/smartlog-interfaces": "^2.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
ts/index.ts
11
ts/index.ts
@ -1,5 +1,14 @@
|
|||||||
import * as plugins from './smartlog.plugins';
|
import * as plugins from './smartlog.plugins';
|
||||||
import { Smartlog } from './smartlog.classes.smartlog';
|
import { Smartlog } from './smartlog.classes.smartlog';
|
||||||
const defaultLogger: Smartlog = new Smartlog();
|
const defaultLogger: Smartlog = new Smartlog({
|
||||||
|
logContext: {
|
||||||
|
company: 'undefined',
|
||||||
|
companyunit: 'undefefined',
|
||||||
|
containerName: 'undefined',
|
||||||
|
environment: 'local',
|
||||||
|
runtime: 'node',
|
||||||
|
zone: 'undefined'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export { Smartlog, defaultLogger };
|
export { Smartlog, defaultLogger };
|
||||||
|
@ -1,19 +1,31 @@
|
|||||||
import * as plugins from './smartlog.plugins';
|
import * as plugins from './smartlog.plugins';
|
||||||
|
|
||||||
// interfaces
|
// interfaces
|
||||||
import { TEnvironment, ILogContext, TLogLevel, TRuntime } from '@pushrocks/smartlog-interfaces';
|
import { TLogType, TEnvironment, ILogContext, TLogLevel, TRuntime, ILogDestination, ILogPackage } from '@pushrocks/smartlog-interfaces';
|
||||||
|
|
||||||
import { LogRouter } from './smartlog.classes.logrouter';
|
import { LogRouter } from './smartlog.classes.logrouter';
|
||||||
|
|
||||||
|
export interface ISmartlogContructorOptions {
|
||||||
|
logContext: ILogContext;
|
||||||
|
minimumLogLevel?: TLogLevel;
|
||||||
|
}
|
||||||
|
|
||||||
export class Smartlog {
|
export class Smartlog {
|
||||||
private logContext: ILogContext;
|
private logContext: ILogContext;
|
||||||
|
private minimumLogLevel: TLogLevel;
|
||||||
|
|
||||||
private consoleEnabled: boolean;
|
private consoleEnabled: boolean;
|
||||||
private minimumLevel: TLogLevel;
|
|
||||||
private runtime: TRuntime;
|
|
||||||
|
|
||||||
public logRouter = new LogRouter();
|
private logRouter = new LogRouter();
|
||||||
|
|
||||||
public addLogDestination = this.logRouter.addLogDestination;
|
public addLogDestination (logDestinationArg: ILogDestination) {
|
||||||
|
this.logRouter.addLogDestination(logDestinationArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
constructor(optionsArg: ISmartlogContructorOptions) {
|
||||||
|
this.logContext = optionsArg.logContext;
|
||||||
|
this.minimumLogLevel = optionsArg.minimumLogLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ============
|
// ============
|
||||||
@ -27,48 +39,46 @@ export class Smartlog {
|
|||||||
this.consoleEnabled = true;
|
this.consoleEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* set a minimum serverity level to log
|
|
||||||
* @param levelArg
|
|
||||||
*/
|
|
||||||
level(levelArg: TLogLevel) {}
|
|
||||||
|
|
||||||
// =============
|
// =============
|
||||||
// log functions
|
// log functions
|
||||||
// =============
|
// =============
|
||||||
/**
|
/**
|
||||||
* log stuff
|
* main log method
|
||||||
* @param logLevelArg
|
* @param logLevelArg - the log level
|
||||||
* @param logMessageArg
|
* @param logMessageArg - the log message
|
||||||
|
* @param logDataArg - any additional log data
|
||||||
*/
|
*/
|
||||||
public log(logLevelArg: TLogLevel, logMessageArg: string) {
|
public log(logLevelArg: TLogLevel, logMessageArg: string, logDataArg?: any) {
|
||||||
if (this.consoleEnabled) {
|
if (this.consoleEnabled) {
|
||||||
console.log(`${logLevelArg}: ${logMessageArg}`);
|
console.log(`LOG: ${logLevelArg}: ${logMessageArg}`);
|
||||||
|
}
|
||||||
|
const logPackage: ILogPackage = {
|
||||||
|
timestamp: Date.now(),
|
||||||
|
type: 'log',
|
||||||
|
context: this.logContext,
|
||||||
|
level: logLevelArg,
|
||||||
|
message: logMessageArg
|
||||||
|
};
|
||||||
|
if(logDataArg) {
|
||||||
|
logPackage.data = logDataArg;
|
||||||
|
}
|
||||||
|
this.logRouter.routeLog(logPackage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public increment(logLevelArg: TLogLevel, logMessageArg) {
|
||||||
|
if (this.consoleEnabled) {
|
||||||
|
console.log(`INCREMENT: ${logLevelArg}: ${logMessageArg}`);
|
||||||
}
|
}
|
||||||
this.logRouter.routeLog({
|
this.logRouter.routeLog({
|
||||||
logContext: this.logContext,
|
timestamp: Date.now(),
|
||||||
logLevel: logLevelArg,
|
type: 'increment',
|
||||||
|
context: this.logContext,
|
||||||
|
level: logLevelArg,
|
||||||
message: logMessageArg
|
message: logMessageArg
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public silly(logMessageArg: string) {
|
public handleLogPackage(logPackageArg: ILogPackage) {
|
||||||
this.log('silly', logMessageArg);
|
this.logRouter.routeLog(logPackageArg);
|
||||||
}
|
|
||||||
|
|
||||||
public debug(logMessageArg) {
|
|
||||||
this.log('debug', logMessageArg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public info(logMessageArg: string) {
|
|
||||||
this.log('info', logMessageArg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public warn(logMessageArg) {
|
|
||||||
this.log('warn', logMessageArg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public error(logMessageArg) {
|
|
||||||
this.log('error', logMessageArg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user