fix(core): update
This commit is contained in:
parent
fc13271878
commit
58358dd479
4212
package-lock.json
generated
4212
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@ -21,16 +21,16 @@
|
|||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.17",
|
"@gitzone/tsbuild": "^2.1.24",
|
||||||
"@gitzone/tsrun": "^1.2.8",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.28",
|
"@gitzone/tstest": "^1.0.33",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^3.2.1",
|
||||||
"@types/node": "^12.11.2",
|
"@types/node": "^14.0.11",
|
||||||
"tslint": "^5.20.0",
|
"tslint": "^6.1.2",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartlog-interfaces": "^2.0.5"
|
"@pushrocks/smartlog-interfaces": "^2.0.12"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
@ -9,7 +9,12 @@ tap.test('should produce instance of Smartlog', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should enable console logging', async () => {
|
tap.test('should enable console logging', async () => {
|
||||||
defaultLogger.enableConsole();
|
defaultLogger.enableConsole({
|
||||||
|
captureAll: true
|
||||||
|
});
|
||||||
|
console.log('this is a normal log that should be captured');
|
||||||
|
console.log(new Error('hi there'));
|
||||||
|
defaultLogger.log('info', 'this should only be printed once');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should be able to log things', async () => {
|
tap.test('should be able to log things', async () => {
|
||||||
|
@ -7,7 +7,7 @@ export interface ISmartlogContructorOptions {
|
|||||||
minimumLogLevel?: plugins.smartlogInterfaces.TLogLevel;
|
minimumLogLevel?: plugins.smartlogInterfaces.TLogLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Smartlog {
|
export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
||||||
private logContext: plugins.smartlogInterfaces.ILogContext;
|
private logContext: plugins.smartlogInterfaces.ILogContext;
|
||||||
private minimumLogLevel: plugins.smartlogInterfaces.TLogLevel;
|
private minimumLogLevel: plugins.smartlogInterfaces.TLogLevel;
|
||||||
|
|
||||||
@ -31,7 +31,25 @@ export class Smartlog {
|
|||||||
/**
|
/**
|
||||||
* enables console logging
|
* enables console logging
|
||||||
*/
|
*/
|
||||||
public enableConsole() {
|
public enableConsole(optionsArg?: {
|
||||||
|
captureAll: boolean;
|
||||||
|
}) {
|
||||||
|
if (optionsArg && optionsArg.captureAll) {
|
||||||
|
const write = process.stdout.write;
|
||||||
|
/* import * as fs from 'fs';
|
||||||
|
const fileStream = fs.createWriteStream(plugins.path.join(paths.nogitDir, 'output.txt'), {
|
||||||
|
flags: 'a+'
|
||||||
|
}); */
|
||||||
|
process.stdout.write = (...args) => {
|
||||||
|
if (!args[0].startsWith('LOG')) {
|
||||||
|
this.log('info', args[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// fileStream.write(args[0]);
|
||||||
|
write.apply(process.stdout, args);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
}
|
||||||
this.consoleEnabled = true;
|
this.consoleEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,11 +65,12 @@ export class Smartlog {
|
|||||||
public log(
|
public log(
|
||||||
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||||
logMessageArg: string,
|
logMessageArg: string,
|
||||||
logDataArg?: any
|
logDataArg?: any,
|
||||||
|
logCorrelationIdArg: string = '123'
|
||||||
) {
|
) {
|
||||||
if (this.consoleEnabled) {
|
if (this.consoleEnabled) {
|
||||||
console.log(
|
this.safeConsoleLog(
|
||||||
`LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLevelArg}: ${logMessageArg}`
|
`${logLevelArg}: ${logMessageArg}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const logPackage: plugins.smartlogInterfaces.ILogPackage = {
|
const logPackage: plugins.smartlogInterfaces.ILogPackage = {
|
||||||
@ -59,6 +78,7 @@ export class Smartlog {
|
|||||||
type: 'log',
|
type: 'log',
|
||||||
context: this.logContext,
|
context: this.logContext,
|
||||||
level: logLevelArg,
|
level: logLevelArg,
|
||||||
|
correlationId: logCorrelationIdArg,
|
||||||
message: logMessageArg
|
message: logMessageArg
|
||||||
};
|
};
|
||||||
if (logDataArg) {
|
if (logDataArg) {
|
||||||
@ -67,20 +87,30 @@ export class Smartlog {
|
|||||||
this.logRouter.routeLog(logPackage);
|
this.logRouter.routeLog(logPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public increment(logLevelArg: plugins.smartlogInterfaces.TLogLevel, logMessageArg) {
|
public increment(
|
||||||
|
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||||
|
logMessageArg: string,
|
||||||
|
logDataArg?: any,
|
||||||
|
logCorrelationIdArg: string = '123'
|
||||||
|
) {
|
||||||
if (this.consoleEnabled) {
|
if (this.consoleEnabled) {
|
||||||
console.log(`INCREMENT: ${logLevelArg}: ${logMessageArg}`);
|
this.safeConsoleLog(`INCREMENT: ${logLevelArg}: ${logMessageArg}`);
|
||||||
}
|
}
|
||||||
this.logRouter.routeLog({
|
this.logRouter.routeLog({
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
type: 'increment',
|
type: 'increment',
|
||||||
context: this.logContext,
|
context: this.logContext,
|
||||||
level: logLevelArg,
|
level: logLevelArg,
|
||||||
message: logMessageArg
|
message: logMessageArg,
|
||||||
|
correlationId: logCorrelationIdArg
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public handleLogPackage(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
|
public handleLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
|
||||||
this.logRouter.routeLog(logPackageArg);
|
this.logRouter.routeLog(logPackageArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private safeConsoleLog(logLine: string) {
|
||||||
|
console.log(`LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLine}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user