Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
a604b8e375 | |||
2cc3e6c906 | |||
5a475260dd | |||
9c79a26d04 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartlog",
|
"name": "@pushrocks/smartlog",
|
||||||
"version": "2.0.25",
|
"version": "2.0.27",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartlog",
|
"name": "@pushrocks/smartlog",
|
||||||
"version": "2.0.25",
|
"version": "2.0.27",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "minimalistic distributed and extensible logging tool",
|
"description": "minimalistic distributed and extensible logging tool",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
31
test/test.ts
31
test/test.ts
@ -1,24 +1,43 @@
|
|||||||
import { expect, tap } from '@pushrocks/tapbundle';
|
import { expect, tap } from '@pushrocks/tapbundle';
|
||||||
import * as smartlog from '../ts/index';
|
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 () => {
|
tap.test('should produce instance of Smartlog', async () => {
|
||||||
defaultLogger = smartlog.defaultLogger;
|
testSmartLog = new smartlog.Smartlog({
|
||||||
expect(defaultLogger).to.be.instanceOf(smartlog.Smartlog);
|
logContext: {
|
||||||
|
environment: 'test',
|
||||||
|
runtime: 'node',
|
||||||
|
zone: 'gitzone',
|
||||||
|
company: 'Lossless GmbH',
|
||||||
|
companyunit: 'Lossless Cloud',
|
||||||
|
containerName: 'testing'
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should enable console logging', async () => {
|
tap.test('should enable console logging', async () => {
|
||||||
defaultLogger.enableConsole({
|
testSmartLog.enableConsole({
|
||||||
captureAll: true
|
captureAll: true
|
||||||
});
|
});
|
||||||
console.log('this is a normal log that should be captured');
|
console.log('this is a normal log that should be captured');
|
||||||
console.log(new Error('hi there'));
|
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 () => {
|
tap.test('should be able to log things', async () => {
|
||||||
defaultLogger.log('silly', 'hi');
|
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();
|
tap.start();
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import * as plugins from './smartlog.plugins';
|
import * as plugins from './smartlog.plugins';
|
||||||
|
import { ConsoleLog } from './smartlog.classes.consolelog';
|
||||||
|
import { LogGroup } from './smartlog.classes.loggroup';
|
||||||
import { Smartlog } from './smartlog.classes.smartlog';
|
import { Smartlog } from './smartlog.classes.smartlog';
|
||||||
|
|
||||||
export { Smartlog };
|
export { ConsoleLog, LogGroup, Smartlog };
|
||||||
|
10
ts/smartlog.classes.consolelog.ts
Normal file
10
ts/smartlog.classes.consolelog.ts
Normal file
@ -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}`);
|
||||||
|
}
|
||||||
|
}
|
@ -1,3 +1,24 @@
|
|||||||
import * as plugins from './smartlog.plugins';
|
import * as plugins from './smartlog.plugins';
|
||||||
|
import { Smartlog } from './smartlog.classes.smartlog';
|
||||||
|
|
||||||
export class LogGroup {}
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
import * as plugins from './smartlog.plugins';
|
import * as plugins from './smartlog.plugins';
|
||||||
|
|
||||||
import { LogRouter } from './smartlog.classes.logrouter';
|
import { LogRouter } from './smartlog.classes.logrouter';
|
||||||
|
import { LogGroup } from '.';
|
||||||
|
|
||||||
export interface ISmartlogContructorOptions {
|
export interface ISmartlogContructorOptions {
|
||||||
logContext: plugins.smartlogInterfaces.ILogContext;
|
logContext: plugins.smartlogInterfaces.ILogContext;
|
||||||
@ -11,7 +12,7 @@ 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;
|
||||||
|
|
||||||
private uniInstanceId: string = plugins.isounique.uni();
|
public uniInstanceId: string = plugins.isounique.uni();
|
||||||
|
|
||||||
private consoleEnabled: boolean;
|
private consoleEnabled: boolean;
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
|||||||
* enables console logging
|
* enables console logging
|
||||||
*/
|
*/
|
||||||
public enableConsole(optionsArg?: { captureAll: boolean }) {
|
public enableConsole(optionsArg?: { captureAll: boolean }) {
|
||||||
if (optionsArg && optionsArg.captureAll) {
|
if (process && optionsArg && optionsArg.captureAll) {
|
||||||
const write = process.stdout.write;
|
const write = process.stdout.write;
|
||||||
/* import * as fs from 'fs';
|
/* import * as fs from 'fs';
|
||||||
const fileStream = fs.createWriteStream(plugins.path.join(paths.nogitDir, 'output.txt'), {
|
const fileStream = fs.createWriteStream(plugins.path.join(paths.nogitDir, 'output.txt'), {
|
||||||
@ -127,4 +128,8 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
|||||||
`LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLine}`
|
`LOG => ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()} => ${logLine}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public createLogGroup(transactionId: string = 'none') {
|
||||||
|
return new LogGroup(this, transactionId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user