Compare commits

..

4 Commits

Author SHA1 Message Date
89429ac679 2.0.23 2020-06-05 09:25:29 +00:00
9f81cdfb8a fix(core): update 2020-06-05 09:25:28 +00:00
ab9a7891a7 2.0.22 2020-06-05 01:53:10 +00:00
58358dd479 fix(core): update 2020-06-05 01:53:09 +00:00
5 changed files with 3714 additions and 591 deletions

4223
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartlog", "name": "@pushrocks/smartlog",
"version": "2.0.21", "version": "2.0.23",
"private": false, "private": false,
"description": "minimalistic distributed and extensible logging tool", "description": "minimalistic distributed and extensible logging tool",
"keywords": [ "keywords": [
@ -21,16 +21,17 @@
"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/isounique": "^1.0.4",
"@pushrocks/smartlog-interfaces": "^2.0.15"
}, },
"files": [ "files": [
"ts/**/*", "ts/**/*",

View File

@ -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 () => {

View File

@ -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;
} }
@ -43,15 +61,20 @@ export class Smartlog {
* @param logLevelArg - the log level * @param logLevelArg - the log level
* @param logMessageArg - the log message * @param logMessageArg - the log message
* @param logDataArg - any additional log data * @param logDataArg - any additional log data
* @param correlationArg - info about corrleations
*/ */
public log( public log(
logLevelArg: plugins.smartlogInterfaces.TLogLevel, logLevelArg: plugins.smartlogInterfaces.TLogLevel,
logMessageArg: string, logMessageArg: string,
logDataArg?: any logDataArg?: any,
correlationArg: plugins.smartlogInterfaces.ILogCorrelation = {
id: plugins.isounique.uni(),
type: 'none'
}
) { ) {
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 +82,7 @@ export class Smartlog {
type: 'log', type: 'log',
context: this.logContext, context: this.logContext,
level: logLevelArg, level: logLevelArg,
correlation: correlationArg,
message: logMessageArg message: logMessageArg
}; };
if (logDataArg) { if (logDataArg) {
@ -67,20 +91,33 @@ 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,
correlationArg: plugins.smartlogInterfaces.ILogCorrelation = {
id: plugins.isounique.uni(),
type: 'none'
}
) {
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,
correlation: correlationArg
}); });
} }
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}`);
}
} }

View File

@ -1,3 +1,4 @@
import * as isounique from '@pushrocks/isounique';
import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces'; import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';
export { smartlogInterfaces }; export { isounique, smartlogInterfaces };