logdna/ts/logdna.classes.logmessage.ts

93 lines
1.9 KiB
TypeScript
Raw Normal View History

2018-11-01 17:13:34 +00:00
import * as plugins from './logdna.plugins';
import { TLogLevel, TEnvironment, ILogPackage } from '@pushrocks/smartlog-interfaces';
/**
* the constructor options for LogdnaMessage
*/
export interface ILogdnaMessageContructorOptions {
/**
* the hostname where the log message was created
*/
hostname: string;
/**
* mac
*/
mac: string;
/**
* the ip ip where the message was created
*/
ip: string;
/**
2018-11-03 15:22:32 +00:00
* a text message, that is the core part
2018-11-01 17:13:34 +00:00
*/
line: string;
/**
* the app name of the app logging
*/
app: string;
/**
* the level of the log message
*/
level: TLogLevel;
/**
* the environment of the log message
*/
env: TEnvironment;
/**
* any metadata that is used
*/
2018-11-02 12:57:14 +00:00
meta: any;
2018-11-01 17:13:34 +00:00
/**
* an array of strings
*/
tags: string[];
}
/**
* a basic LogdnaMessage
*/
export class LogdnaMessage {
2018-11-02 12:57:14 +00:00
/**
* create lgdna messages from smartlog package
* @param smartlogPackageArg
*/
2018-11-03 15:22:32 +00:00
static fromSmartLogPackage(smartlogPackageArg: ILogPackage): LogdnaMessage {
2018-11-01 17:13:34 +00:00
return new LogdnaMessage({
line: smartlogPackageArg.message,
2018-11-03 23:05:36 +00:00
meta: {
...smartlogPackageArg.context,
logType: smartlogPackageArg.type
},
2018-11-03 22:31:26 +00:00
env: smartlogPackageArg.context.environment,
hostname: smartlogPackageArg.context.zone,
level: smartlogPackageArg.level,
app: smartlogPackageArg.context.zone,
2018-11-02 12:57:14 +00:00
tags: (() => {
const tagArray: string[] = [];
2018-11-03 22:31:26 +00:00
tagArray.push(smartlogPackageArg.context.company);
tagArray.push(smartlogPackageArg.context.companyunit);
2018-11-02 12:57:14 +00:00
return tagArray;
})(),
2018-11-01 17:13:34 +00:00
ip: '0.0.0.0',
mac: 'aa:aa:aa:aa:aa:aa'
});
2018-11-03 15:22:32 +00:00
}
2018-11-01 17:13:34 +00:00
2018-11-02 12:57:14 +00:00
/**
* the options of this log message
*/
public options: ILogdnaMessageContructorOptions;
2018-11-01 17:13:34 +00:00
constructor(optionsArg: ILogdnaMessageContructorOptions) {
this.options = optionsArg;
2018-11-03 15:22:32 +00:00
}
}