Files
logdna/ts/logdna.classes.logmessage.ts

101 lines
2.1 KiB
TypeScript
Raw Permalink Normal View History

2018-11-01 18:13:34 +01: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 18:44:28 +01:00
/**
* a timestamp for then the log message was created
*/
timestamp: number;
2018-11-01 18:13:34 +01: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 16:22:32 +01:00
* a text message, that is the core part
2018-11-01 18:13:34 +01: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 13:57:14 +01:00
meta: any;
2018-11-01 18:13:34 +01:00
/**
* an array of strings
*/
tags: string[];
}
/**
* a basic LogdnaMessage
*/
export class LogdnaMessage {
2018-11-02 13:57:14 +01:00
/**
* create lgdna messages from smartlog package
* @param smartlogPackageArg
*/
2018-11-04 21:11:48 +01:00
public static fromSmartLogPackage(smartlogPackageArg: ILogPackage): LogdnaMessage {
2018-11-01 18:13:34 +01:00
return new LogdnaMessage({
2018-11-04 18:44:28 +01:00
timestamp: smartlogPackageArg.timestamp,
2018-11-01 18:13:34 +01:00
line: smartlogPackageArg.message,
2018-11-04 00:05:36 +01: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-07 01:05:16 +02:00
data: smartlogPackageArg.data || {},
2018-11-04 00:05:36 +01:00
},
2018-11-03 23:31:26 +01:00
env: smartlogPackageArg.context.environment,
hostname: smartlogPackageArg.context.zone,
level: smartlogPackageArg.level,
2018-11-04 15:37:55 +01:00
app: smartlogPackageArg.context.containerName,
2018-11-02 13:57:14 +01:00
tags: (() => {
const tagArray: string[] = [];
2018-11-03 23:31:26 +01:00
tagArray.push(smartlogPackageArg.context.company);
tagArray.push(smartlogPackageArg.context.companyunit);
2018-11-02 13:57:14 +01:00
return tagArray;
})(),
2018-11-01 18:13:34 +01:00
ip: '0.0.0.0',
2021-07-07 01:05:16 +02:00
mac: 'aa:aa:aa:aa:aa:aa',
2018-11-01 18:13:34 +01:00
});
2018-11-03 16:22:32 +01:00
}
2018-11-01 18:13:34 +01:00
2018-11-02 13:57:14 +01:00
/**
* the options of this log message
*/
public options: ILogdnaMessageContructorOptions;
2018-11-01 18:13:34 +01:00
constructor(optionsArg: ILogdnaMessageContructorOptions) {
this.options = optionsArg;
2018-11-03 16:22:32 +01:00
}
}