Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
3066503a70 | |||
cf899609be | |||
7be0e70754 | |||
8b0ceb759d | |||
7b5cfb2c95 | |||
a4a5b18849 | |||
47583bd955 | |||
018bc7054a | |||
5ca4cb9964 | |||
27bb9a789c | |||
5f7e68d5b7 | |||
da0edc478c | |||
d2be068597 | |||
4113a9a211 | |||
3575262001 | |||
1cc75afc32 |
8389
package-lock.json
generated
8389
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartlog",
|
"name": "@pushrocks/smartlog",
|
||||||
"version": "2.0.28",
|
"version": "2.0.36",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "minimalistic distributed and extensible logging tool",
|
"description": "minimalistic distributed and extensible logging tool",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@ -22,17 +22,17 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.24",
|
"@gitzone/tsbuild": "^2.1.24",
|
||||||
|
"@gitzone/tsbundle": "^1.0.72",
|
||||||
"@gitzone/tsrun": "^1.2.12",
|
"@gitzone/tsrun": "^1.2.12",
|
||||||
"@gitzone/tstest": "^1.0.33",
|
"@gitzone/tstest": "^1.0.43",
|
||||||
"@pushrocks/tapbundle": "^3.2.1",
|
"@pushrocks/tapbundle": "^3.2.9",
|
||||||
"@types/node": "^14.0.11",
|
"@types/node": "^14.0.27",
|
||||||
"tslint": "^6.1.2",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@gitzone/tsbundle": "^1.0.69",
|
|
||||||
"@pushrocks/isounique": "^1.0.4",
|
"@pushrocks/isounique": "^1.0.4",
|
||||||
"@pushrocks/smartlog-interfaces": "^2.0.18"
|
"@pushrocks/smartlog-interfaces": "^2.0.20"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
@ -40,4 +40,9 @@ tap.test('should create a log group', async () => {
|
|||||||
logGroup.log('info', 'this is logged from a log group');
|
logGroup.log('info', 'this is logged from a log group');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
tap.test('should catch error', async () => {
|
||||||
|
console.error(new Error('hey'));
|
||||||
|
// throw new Error('hey');
|
||||||
|
});
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -4,7 +4,12 @@ import * as plugins from './smartlog.plugins';
|
|||||||
* a console log optimized for smartlog
|
* a console log optimized for smartlog
|
||||||
*/
|
*/
|
||||||
export class ConsoleLog {
|
export class ConsoleLog {
|
||||||
public log(logLevelArg: plugins.smartlogInterfaces.TLogLevel, logMessageArg: string) {
|
public log(
|
||||||
|
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||||
|
logMessageArg: string,
|
||||||
|
dataArg?: any,
|
||||||
|
correlationArg?: plugins.smartlogInterfaces.ILogCorrelation
|
||||||
|
) {
|
||||||
console.log(`__# ${logLevelArg}: ${logMessageArg}`);
|
console.log(`__# ${logLevelArg}: ${logMessageArg}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,9 @@ export class LogRouter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// routes the log according to added logDestinations
|
// routes the log according to added logDestinations
|
||||||
routeLog(logPackageArg: ILogPackage) {
|
public async routeLog(logPackageArg: ILogPackage) {
|
||||||
for (const logDestination of this.logDestinations) {
|
for (const logDestination of this.logDestinations) {
|
||||||
logDestination.handleLog(logPackageArg);
|
await logDestination.handleLog(logPackageArg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,19 +37,33 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
|||||||
public enableConsole(optionsArg?: { captureAll: boolean }) {
|
public enableConsole(optionsArg?: { captureAll: boolean }) {
|
||||||
if (process && optionsArg && optionsArg.captureAll) {
|
if (process && optionsArg && optionsArg.captureAll) {
|
||||||
const write = process.stdout.write;
|
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) => {
|
process.stdout.write = (...args) => {
|
||||||
if (!args[0].startsWith('LOG')) {
|
const logString: string = args[0];
|
||||||
this.log('info', args[0]);
|
if (!logString.startsWith('LOG') && typeof logString === 'string') {
|
||||||
|
switch(true) {
|
||||||
|
case logString.substr(0, 20).includes('Error:'):
|
||||||
|
this.log('error', logString);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.log('info', logString);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// fileStream.write(args[0]);
|
// fileStream.write(args[0]);
|
||||||
write.apply(process.stdout, args);
|
write.apply(process.stdout, args);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
process.stderr.write = (...args) => {
|
||||||
|
if (!args[0].startsWith('LOG')) {
|
||||||
|
this.log('error', args[0]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// fileStream.write(args[0]);
|
||||||
|
write.apply(process.stderr, args);
|
||||||
|
return true;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
this.consoleEnabled = true;
|
this.consoleEnabled = true;
|
||||||
}
|
}
|
||||||
@ -64,7 +78,7 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
|||||||
* @param logDataArg - any additional log data
|
* @param logDataArg - any additional log data
|
||||||
* @param correlationArg - info about corrleations
|
* @param correlationArg - info about corrleations
|
||||||
*/
|
*/
|
||||||
public log(
|
public async log(
|
||||||
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||||
logMessageArg: string,
|
logMessageArg: string,
|
||||||
logDataArg?: any,
|
logDataArg?: any,
|
||||||
@ -94,7 +108,7 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
|||||||
if (logDataArg) {
|
if (logDataArg) {
|
||||||
logPackage.data = logDataArg;
|
logPackage.data = logDataArg;
|
||||||
}
|
}
|
||||||
this.logRouter.routeLog(logPackage);
|
await this.logRouter.routeLog(logPackage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public increment(
|
public increment(
|
||||||
@ -119,8 +133,8 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public handleLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
|
public async handleLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
|
||||||
this.logRouter.routeLog(logPackageArg);
|
await this.logRouter.routeLog(logPackageArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
private safeConsoleLog(logLine: string) {
|
private safeConsoleLog(logLine: string) {
|
||||||
|
Reference in New Issue
Block a user