From 9c79a26d04ff8ca5d3cbea03a58c0348f0a7ec6e Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Mon, 8 Jun 2020 18:51:11 +0000 Subject: [PATCH] fix(core): update --- test/test.ts | 26 ++++++++++++++++++++------ ts/index.ts | 4 +++- ts/smartlog.classes.consolelog.ts | 10 ++++++++++ ts/smartlog.classes.smartlog.ts | 2 +- 4 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 ts/smartlog.classes.consolelog.ts diff --git a/test/test.ts b/test/test.ts index 11f2eb2..5e882f2 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,24 +1,38 @@ import { expect, tap } from '@pushrocks/tapbundle'; import * as smartlog from '../ts/index'; -let defaultLogger: smartlog.Smartlog; +let testConsoleLog: smartlog.ConsoleLog; +let testSmartLog: smartlog.Smartlog; + +tap.test('should produce a valid ConsoleLog instance', async () => { + testConsoleLog = new smartlog.ConsoleLog(); + testConsoleLog.log('ok', 'this is ok'); +}) tap.test('should produce instance of Smartlog', async () => { - defaultLogger = smartlog.defaultLogger; - expect(defaultLogger).to.be.instanceOf(smartlog.Smartlog); + testSmartLog = new smartlog.Smartlog({ + logContext: { + environment: 'test', + runtime: 'node', + zone: 'gitzone', + company: 'Lossless GmbH', + companyunit: 'Lossless Cloud', + containerName: 'testing' + } + }); }); tap.test('should enable console logging', async () => { - defaultLogger.enableConsole({ + testSmartLog.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'); + testSmartLog.log('info', 'this should only be printed once'); }); tap.test('should be able to log things', async () => { - defaultLogger.log('silly', 'hi'); + testSmartLog.log('silly', 'hi'); }); tap.start(); diff --git a/ts/index.ts b/ts/index.ts index 5b7f38d..6ba00dc 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -1,4 +1,6 @@ import * as plugins from './smartlog.plugins'; +import { ConsoleLog } from './smartlog.classes.consolelog'; +import { LogGroup } from './smartlog.classes.loggroup'; import { Smartlog } from './smartlog.classes.smartlog'; -export { Smartlog }; +export { ConsoleLog, LogGroup, Smartlog }; diff --git a/ts/smartlog.classes.consolelog.ts b/ts/smartlog.classes.consolelog.ts new file mode 100644 index 0000000..054d159 --- /dev/null +++ b/ts/smartlog.classes.consolelog.ts @@ -0,0 +1,10 @@ +import * as plugins from './smartlog.plugins'; + +/** + * a console log optimized for smartlog + */ +export class ConsoleLog { + public log(logLevelArg: plugins.smartlogInterfaces.TLogLevel, logMessageArg: string) { + console.log(`__# ${logLevelArg}: ${logMessageArg}`); + } +} diff --git a/ts/smartlog.classes.smartlog.ts b/ts/smartlog.classes.smartlog.ts index ecafd7e..5e83d0b 100644 --- a/ts/smartlog.classes.smartlog.ts +++ b/ts/smartlog.classes.smartlog.ts @@ -34,7 +34,7 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination { * enables console logging */ public enableConsole(optionsArg?: { captureAll: boolean }) { - if (optionsArg && optionsArg.captureAll) { + if (process && optionsArg && optionsArg.captureAll) { const write = process.stdout.write; /* import * as fs from 'fs'; const fileStream = fs.createWriteStream(plugins.path.join(paths.nogitDir, 'output.txt'), {