logdna/ts/logdna.classes.logmessage.ts

90 lines
1.8 KiB
TypeScript
Raw Permalink 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-02 12:57:14 +00:00
meta: smartlogPackageArg.logContext,
2018-11-01 17:13:34 +00:00
env: smartlogPackageArg.logContext.environment,
hostname: smartlogPackageArg.logContext.zone,
level: smartlogPackageArg.logLevel,
app: smartlogPackageArg.logContext.zone,
2018-11-02 12:57:14 +00:00
tags: (() => {
const tagArray: string[] = [];
tagArray.push(smartlogPackageArg.logContext.company);
tagArray.push(smartlogPackageArg.logContext.companyunit);
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
}
}