Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a475260dd | |||
| 9c79a26d04 | |||
| 3fbd87cab1 | |||
| 5fe5c1d315 |
568
package-lock.json
generated
568
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartlog",
|
"name": "@pushrocks/smartlog",
|
||||||
"version": "2.0.24",
|
"version": "2.0.26",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "minimalistic distributed and extensible logging tool",
|
"description": "minimalistic distributed and extensible logging tool",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/)",
|
"test": "(tstest test/)",
|
||||||
"build": "(tsbuild --web)",
|
"build": "(tsbuild --web && tsbundle npm)",
|
||||||
"format": "(gitzone format)"
|
"format": "(gitzone format)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -30,8 +30,9 @@
|
|||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@gitzone/tsbundle": "^1.0.69",
|
||||||
"@pushrocks/isounique": "^1.0.4",
|
"@pushrocks/isounique": "^1.0.4",
|
||||||
"@pushrocks/smartlog-interfaces": "^2.0.15"
|
"@pushrocks/smartlog-interfaces": "^2.0.18"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
|||||||
26
test/test.ts
26
test/test.ts
@@ -1,24 +1,38 @@
|
|||||||
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.start();
|
tap.start();
|
||||||
|
|||||||
16
ts/index.ts
16
ts/index.ts
@@ -1,16 +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';
|
||||||
const defaultLogger: Smartlog = new Smartlog({
|
|
||||||
logContext: {
|
|
||||||
company: 'undefined',
|
|
||||||
companyunit: 'undefefined',
|
|
||||||
containerName: 'undefined',
|
|
||||||
environment: 'local',
|
|
||||||
runtime: 'node',
|
|
||||||
zone: 'undefined'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
defaultLogger.enableConsole();
|
export { ConsoleLog, LogGroup, Smartlog };
|
||||||
|
|
||||||
export { Smartlog, defaultLogger };
|
|
||||||
|
|||||||
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}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
3
ts/smartlog.classes.loggroup.ts
Normal file
3
ts/smartlog.classes.loggroup.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import * as plugins from './smartlog.plugins';
|
||||||
|
|
||||||
|
export class LogGroup {}
|
||||||
@@ -11,6 +11,8 @@ 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();
|
||||||
|
|
||||||
private consoleEnabled: boolean;
|
private consoleEnabled: boolean;
|
||||||
|
|
||||||
private logRouter = new LogRouter();
|
private logRouter = new LogRouter();
|
||||||
@@ -32,7 +34,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'), {
|
||||||
@@ -65,14 +67,21 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
|||||||
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||||
logMessageArg: string,
|
logMessageArg: string,
|
||||||
logDataArg?: any,
|
logDataArg?: any,
|
||||||
correlationArg: plugins.smartlogInterfaces.ILogCorrelation = {
|
correlationArg?: plugins.smartlogInterfaces.ILogCorrelation
|
||||||
id: plugins.isounique.uni(),
|
|
||||||
type: 'none'
|
|
||||||
}
|
|
||||||
) {
|
) {
|
||||||
|
correlationArg = {
|
||||||
|
...{
|
||||||
|
id: plugins.isounique.uni(),
|
||||||
|
type: 'none',
|
||||||
|
instance: this.uniInstanceId
|
||||||
|
},
|
||||||
|
...correlationArg
|
||||||
|
};
|
||||||
|
|
||||||
if (this.consoleEnabled) {
|
if (this.consoleEnabled) {
|
||||||
this.safeConsoleLog(`${logLevelArg}: ${logMessageArg}`);
|
this.safeConsoleLog(`${logLevelArg}: ${logMessageArg}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const logPackage: plugins.smartlogInterfaces.ILogPackage = {
|
const logPackage: plugins.smartlogInterfaces.ILogPackage = {
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
type: 'log',
|
type: 'log',
|
||||||
|
|||||||
Reference in New Issue
Block a user