diff --git a/test/test.ts b/test/test.ts index 5e882f2..7baa164 100644 --- a/test/test.ts +++ b/test/test.ts @@ -35,4 +35,9 @@ tap.test('should be able to log things', async () => { testSmartLog.log('silly', 'hi'); }); +tap.test('should create a log group', async () => { + const logGroup = testSmartLog.createLogGroup('some cool transaction'); + logGroup.log('info', 'this is logged from a log group'); +}) + tap.start(); diff --git a/ts/smartlog.classes.loggroup.ts b/ts/smartlog.classes.loggroup.ts index d4e20f6..3543b49 100644 --- a/ts/smartlog.classes.loggroup.ts +++ b/ts/smartlog.classes.loggroup.ts @@ -1,3 +1,24 @@ import * as plugins from './smartlog.plugins'; +import { Smartlog } from './smartlog.classes.smartlog'; -export class LogGroup {} \ No newline at end of file +export class LogGroup { + public smartlogRef: Smartlog; + public transactionId: string; + public groupId = plugins.isounique.uni(); + + constructor(smartlogInstance: Smartlog, transactionIdArg: string) { + this.smartlogRef = smartlogInstance; + this.transactionId = transactionIdArg; + } + + public log(logLevelArg: plugins.smartlogInterfaces.TLogLevel, logMessageArg: string, logDataArg?: any) { + this.smartlogRef.log(logLevelArg, logMessageArg, logDataArg, { + id: plugins.isounique.uni(), + type: 'none', + group: this.groupId, + instance: this.smartlogRef.uniInstanceId, + transaction: this.transactionId + }); + } + +} \ No newline at end of file diff --git a/ts/smartlog.classes.smartlog.ts b/ts/smartlog.classes.smartlog.ts index 5e83d0b..a9f0bf6 100644 --- a/ts/smartlog.classes.smartlog.ts +++ b/ts/smartlog.classes.smartlog.ts @@ -1,6 +1,7 @@ import * as plugins from './smartlog.plugins'; import { LogRouter } from './smartlog.classes.logrouter'; +import { LogGroup } from '.'; export interface ISmartlogContructorOptions { logContext: plugins.smartlogInterfaces.ILogContext; @@ -11,7 +12,7 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination { private logContext: plugins.smartlogInterfaces.ILogContext; private minimumLogLevel: plugins.smartlogInterfaces.TLogLevel; - private uniInstanceId: string = plugins.isounique.uni(); + public uniInstanceId: string = plugins.isounique.uni(); private consoleEnabled: boolean; @@ -127,4 +128,8 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination { `LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLine}` ); } + + public createLogGroup(transactionId: string = 'none') { + return new LogGroup(this, transactionId); + } }