Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
7be0e70754 | |||
8b0ceb759d | |||
7b5cfb2c95 | |||
a4a5b18849 | |||
47583bd955 | |||
018bc7054a | |||
5ca4cb9964 | |||
27bb9a789c | |||
5f7e68d5b7 | |||
da0edc478c | |||
d2be068597 | |||
4113a9a211 | |||
3575262001 | |||
1cc75afc32 | |||
7d72b24770 | |||
ffff60772c | |||
a604b8e375 | |||
2cc3e6c906 |
14
package-lock.json
generated
14
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartlog",
|
||||
"version": "2.0.26",
|
||||
"version": "2.0.35",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -1188,9 +1188,9 @@
|
||||
}
|
||||
},
|
||||
"@pushrocks/smartlog-interfaces": {
|
||||
"version": "2.0.18",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartlog-interfaces/-/smartlog-interfaces-2.0.18.tgz",
|
||||
"integrity": "sha512-2CUGyTJsf4/pTqJqu7FUCsB/I5Vsz+DwpwPG/2sQk5VxT9oX8AUWtz2BspLrGNlMg7wTJR79f4yA6Dk5xQ6qFQ==",
|
||||
"version": "2.0.20",
|
||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartlog-interfaces/-/smartlog-interfaces-2.0.20.tgz",
|
||||
"integrity": "sha512-PR3l5UVor+//UoeOLws7hX4AtL2eWEHUC4uvjRY9wkrZt3XxemzWzPYXXlBUrdr5DPqt1b7tKcOx8xyUoUei9g==",
|
||||
"requires": {
|
||||
"@apiglobal/typedrequest-interfaces": "^1.0.13"
|
||||
}
|
||||
@ -1599,9 +1599,9 @@
|
||||
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "14.0.11",
|
||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-14.0.11.tgz",
|
||||
"integrity": "sha512-lCvvI24L21ZVeIiyIUHZ5Oflv1hhHQ5E1S25IRlKIXaRkVgmXpJMI3wUJkmym2bTbCe+WoIibQnMVAU3FguaOg=="
|
||||
"version": "14.0.13",
|
||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-14.0.13.tgz",
|
||||
"integrity": "sha512-rouEWBImiRaSJsVA+ITTFM6ZxibuAlTuNOCyxVbwreu6k6+ujs7DfnU9o+PShFhET78pMBl3eH+AGSI5eOTkPA=="
|
||||
},
|
||||
"@types/portscanner": {
|
||||
"version": "2.1.0",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@pushrocks/smartlog",
|
||||
"version": "2.0.26",
|
||||
"version": "2.0.35",
|
||||
"private": false,
|
||||
"description": "minimalistic distributed and extensible logging tool",
|
||||
"keywords": [
|
||||
@ -25,14 +25,14 @@
|
||||
"@gitzone/tsrun": "^1.2.12",
|
||||
"@gitzone/tstest": "^1.0.33",
|
||||
"@pushrocks/tapbundle": "^3.2.1",
|
||||
"@types/node": "^14.0.11",
|
||||
"@types/node": "^14.0.13",
|
||||
"tslint": "^6.1.2",
|
||||
"tslint-config-prettier": "^1.18.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@gitzone/tsbundle": "^1.0.69",
|
||||
"@pushrocks/isounique": "^1.0.4",
|
||||
"@pushrocks/smartlog-interfaces": "^2.0.18"
|
||||
"@pushrocks/smartlog-interfaces": "^2.0.20"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
@ -76,7 +76,6 @@ The following destinations are available:
|
||||
// TBD
|
||||
```
|
||||
|
||||
|
||||
## Contribution
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
|
12
test/test.ts
12
test/test.ts
@ -7,7 +7,7 @@ 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 () => {
|
||||
testSmartLog = new smartlog.Smartlog({
|
||||
@ -35,4 +35,14 @@ 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.test('should catch error', async () => {
|
||||
console.error(new Error('hey'));
|
||||
// throw new Error('hey');
|
||||
});
|
||||
|
||||
tap.start();
|
||||
|
@ -4,7 +4,12 @@ import * as plugins from './smartlog.plugins';
|
||||
* a console log optimized for smartlog
|
||||
*/
|
||||
export class ConsoleLog {
|
||||
public log(logLevelArg: plugins.smartlogInterfaces.TLogLevel, logMessageArg: string) {
|
||||
public log(
|
||||
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||
logMessageArg: string,
|
||||
dataArg?: any,
|
||||
correlationArg?: plugins.smartlogInterfaces.ILogCorrelation
|
||||
) {
|
||||
console.log(`__# ${logLevelArg}: ${logMessageArg}`);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,27 @@
|
||||
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
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,9 @@ export class LogRouter {
|
||||
}
|
||||
|
||||
// routes the log according to added logDestinations
|
||||
routeLog(logPackageArg: ILogPackage) {
|
||||
public async routeLog(logPackageArg: ILogPackage) {
|
||||
for (const logDestination of this.logDestinations) {
|
||||
logDestination.handleLog(logPackageArg);
|
||||
await logDestination.handleLog(logPackageArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
@ -41,14 +42,31 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
||||
flags: 'a+'
|
||||
}); */
|
||||
process.stdout.write = (...args) => {
|
||||
if (!args[0].startsWith('LOG')) {
|
||||
this.log('info', args[0]);
|
||||
const logString: string = args[0];
|
||||
if (!logString.startsWith('LOG') && typeof logString === 'string') {
|
||||
switch(true) {
|
||||
case logString.substr(0, 20).includes('Error:'):
|
||||
this.log('error', logString);
|
||||
break;
|
||||
default:
|
||||
this.log('info', logString);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// fileStream.write(args[0]);
|
||||
write.apply(process.stdout, args);
|
||||
return true;
|
||||
};
|
||||
|
||||
process.stderr.write = (...args) => {
|
||||
if (!args[0].startsWith('LOG')) {
|
||||
this.log('error', args[0]);
|
||||
return;
|
||||
}
|
||||
// fileStream.write(args[0]);
|
||||
write.apply(process.stderr, args);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
this.consoleEnabled = true;
|
||||
}
|
||||
@ -63,7 +81,7 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
||||
* @param logDataArg - any additional log data
|
||||
* @param correlationArg - info about corrleations
|
||||
*/
|
||||
public log(
|
||||
public async log(
|
||||
logLevelArg: plugins.smartlogInterfaces.TLogLevel,
|
||||
logMessageArg: string,
|
||||
logDataArg?: any,
|
||||
@ -93,7 +111,7 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
||||
if (logDataArg) {
|
||||
logPackage.data = logDataArg;
|
||||
}
|
||||
this.logRouter.routeLog(logPackage);
|
||||
await this.logRouter.routeLog(logPackage);
|
||||
}
|
||||
|
||||
public increment(
|
||||
@ -118,8 +136,8 @@ export class Smartlog implements plugins.smartlogInterfaces.ILogDestination {
|
||||
});
|
||||
}
|
||||
|
||||
public handleLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
|
||||
this.logRouter.routeLog(logPackageArg);
|
||||
public async handleLog(logPackageArg: plugins.smartlogInterfaces.ILogPackage) {
|
||||
await this.logRouter.routeLog(logPackageArg);
|
||||
}
|
||||
|
||||
private safeConsoleLog(logLine: string) {
|
||||
@ -127,4 +145,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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user