logdna/ts/logdna.classes.logmessage.ts

101 lines
2.1 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 {
2018-11-04 17:44:28 +00:00
/**
* a timestamp for then the log message was created
*/
timestamp: number;
2018-11-01 17:13:34 +00:00
/**
* 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-04 20:11:48 +00:00
public static fromSmartLogPackage(smartlogPackageArg: ILogPackage): LogdnaMessage {
2018-11-01 17:13:34 +00:00
return new LogdnaMessage({
2018-11-04 17:44:28 +00:00
timestamp: smartlogPackageArg.timestamp,
2018-11-01 17:13:34 +00:00
line: smartlogPackageArg.message,
2018-11-03 23:05:36 +00:00
meta: {
...smartlogPackageArg.context,
2020-06-05 16:06:52 +00:00
logType: smartlogPackageArg.type,
2020-06-10 08:46:44 +00:00
correlation: smartlogPackageArg.correlation,
2021-07-06 23:05:16 +00:00
data: smartlogPackageArg.data || {},
2018-11-03 23:05:36 +00:00
},
2018-11-03 22:31:26 +00:00
env: smartlogPackageArg.context.environment,
hostname: smartlogPackageArg.context.zone,
level: smartlogPackageArg.level,
2018-11-04 14:37:55 +00:00
app: smartlogPackageArg.context.containerName,
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',
2021-07-06 23:05:16 +00:00
mac: 'aa:aa:aa:aa:aa:aa',
2018-11-01 17:13:34 +00:00
});
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
}
}