fix(core): update
This commit is contained in:
		
							
								
								
									
										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)" | ||||
|   }, | ||||
|   "devDependencies": { | ||||
|     "@gitzone/tsbuild": "^2.1.17", | ||||
|     "@gitzone/tsrun": "^1.2.8", | ||||
|     "@gitzone/tstest": "^1.0.28", | ||||
|     "@pushrocks/tapbundle": "^3.0.13", | ||||
|     "@types/node": "^12.11.2", | ||||
|     "tslint": "^5.20.0", | ||||
|     "@gitzone/tsbuild": "^2.1.24", | ||||
|     "@gitzone/tsrun": "^1.2.12", | ||||
|     "@gitzone/tstest": "^1.0.33", | ||||
|     "@pushrocks/tapbundle": "^3.2.1", | ||||
|     "@types/node": "^14.0.11", | ||||
|     "tslint": "^6.1.2", | ||||
|     "tslint-config-prettier": "^1.18.0" | ||||
|   }, | ||||
|   "dependencies": { | ||||
|     "@pushrocks/smartlog-interfaces": "^2.0.5" | ||||
|     "@pushrocks/smartlog-interfaces": "^2.0.12" | ||||
|   }, | ||||
|   "files": [ | ||||
|     "ts/**/*", | ||||
|   | ||||
| @@ -9,7 +9,12 @@ tap.test('should produce instance of Smartlog', 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 () => { | ||||
|   | ||||
| @@ -7,7 +7,7 @@ export interface ISmartlogContructorOptions { | ||||
|   minimumLogLevel?: plugins.smartlogInterfaces.TLogLevel; | ||||
| } | ||||
|  | ||||
| export class Smartlog { | ||||
| export class Smartlog implements plugins.smartlogInterfaces.ILogDestination { | ||||
|   private logContext: plugins.smartlogInterfaces.ILogContext; | ||||
|   private minimumLogLevel: plugins.smartlogInterfaces.TLogLevel; | ||||
|  | ||||
| @@ -31,7 +31,25 @@ export class Smartlog { | ||||
|   /** | ||||
|    * 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; | ||||
|   } | ||||
|  | ||||
| @@ -47,11 +65,12 @@ export class Smartlog { | ||||
|   public log( | ||||
|     logLevelArg: plugins.smartlogInterfaces.TLogLevel, | ||||
|     logMessageArg: string, | ||||
|     logDataArg?: any | ||||
|     logDataArg?: any, | ||||
|     logCorrelationIdArg: string = '123' | ||||
|   ) { | ||||
|     if (this.consoleEnabled) { | ||||
|       console.log( | ||||
|         `LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLevelArg}: ${logMessageArg}` | ||||
|       this.safeConsoleLog( | ||||
|         `${logLevelArg}: ${logMessageArg}` | ||||
|       ); | ||||
|     } | ||||
|     const logPackage: plugins.smartlogInterfaces.ILogPackage = { | ||||
| @@ -59,6 +78,7 @@ export class Smartlog { | ||||
|       type: 'log', | ||||
|       context: this.logContext, | ||||
|       level: logLevelArg, | ||||
|       correlationId: logCorrelationIdArg, | ||||
|       message: logMessageArg | ||||
|     }; | ||||
|     if (logDataArg) { | ||||
| @@ -67,20 +87,30 @@ export class Smartlog { | ||||
|     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) { | ||||
|       console.log(`INCREMENT: ${logLevelArg}: ${logMessageArg}`); | ||||
|       this.safeConsoleLog(`INCREMENT: ${logLevelArg}: ${logMessageArg}`); | ||||
|     } | ||||
|     this.logRouter.routeLog({ | ||||
|       timestamp: Date.now(), | ||||
|       type: 'increment', | ||||
|       context: this.logContext, | ||||
|       level: logLevelArg, | ||||
|       message: logMessageArg | ||||
|       message: logMessageArg, | ||||
|       correlationId: logCorrelationIdArg | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   public handleLogPackage(logPackageArg: plugins.smartlogInterfaces.ILogPackage) { | ||||
|   public handleLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage) { | ||||
|     this.logRouter.routeLog(logPackageArg); | ||||
|   } | ||||
|  | ||||
|   private safeConsoleLog(logLine: string) { | ||||
|     console.log(`LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLine}`); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user