fix(core): update
This commit is contained in:
@ -44,7 +44,7 @@ export interface ILogdnaMessageContructorOptions {
|
||||
/**
|
||||
* any metadata that is used
|
||||
*/
|
||||
metaData: any;
|
||||
meta: any;
|
||||
|
||||
/**
|
||||
* an array of strings
|
||||
@ -56,21 +56,33 @@ export interface ILogdnaMessageContructorOptions {
|
||||
* a basic LogdnaMessage
|
||||
*/
|
||||
export class LogdnaMessage {
|
||||
/**
|
||||
* create lgdna messages from smartlog package
|
||||
* @param smartlogPackageArg
|
||||
*/
|
||||
static fromSmartLogPackage (smartlogPackageArg: ILogPackage): LogdnaMessage {
|
||||
return new LogdnaMessage({
|
||||
line: smartlogPackageArg.message,
|
||||
metaData: smartlogPackageArg.logContext,
|
||||
meta: smartlogPackageArg.logContext,
|
||||
env: smartlogPackageArg.logContext.environment,
|
||||
hostname: smartlogPackageArg.logContext.zone,
|
||||
level: smartlogPackageArg.logLevel,
|
||||
app: smartlogPackageArg.logContext.zone,
|
||||
tags: [],
|
||||
tags: (() => {
|
||||
const tagArray: string[] = [];
|
||||
tagArray.push(smartlogPackageArg.logContext.company);
|
||||
tagArray.push(smartlogPackageArg.logContext.companyunit);
|
||||
return tagArray;
|
||||
})(),
|
||||
ip: '0.0.0.0',
|
||||
mac: 'aa:aa:aa:aa:aa:aa'
|
||||
});
|
||||
};
|
||||
|
||||
options: ILogdnaMessageContructorOptions;
|
||||
/**
|
||||
* the options of this log message
|
||||
*/
|
||||
public options: ILogdnaMessageContructorOptions;
|
||||
constructor(optionsArg: ILogdnaMessageContructorOptions) {
|
||||
this.options = optionsArg;
|
||||
};
|
||||
|
@ -32,9 +32,13 @@ export class LogdnaAccount {
|
||||
public async sendLogDnaMessage(logdnaMessageArg: LogdnaMessage) {
|
||||
const lm = logdnaMessageArg;
|
||||
const euc = encodeURIComponent;
|
||||
|
||||
// let construct the request uri
|
||||
const requestUrlWithParams = `${this.baseUrl}?hostname=${euc(
|
||||
lm.options.hostname
|
||||
)}&mac=${euc(lm.options.mac)}&ip=1${euc(lm.options.ip)}&now=${Date.now()}`;
|
||||
|
||||
// lets post the message to logdna
|
||||
await plugins.smartrequest.postJson(requestUrlWithParams, {
|
||||
headers: {
|
||||
'Authorization': this.createBasicAuth(),
|
||||
@ -43,15 +47,11 @@ export class LogdnaAccount {
|
||||
requestBody: {
|
||||
"lines": [
|
||||
{
|
||||
"line":"This is an awesome log statement",
|
||||
"app":"myapp",
|
||||
"level": "INFO",
|
||||
"env": "production",
|
||||
"meta": {
|
||||
"customfield": {
|
||||
"nestedfield": "nestedvalue"
|
||||
}
|
||||
}
|
||||
"line": lm.options.line,
|
||||
"app": lm.options.app,
|
||||
"level": lm.options.level,
|
||||
"env": lm.options.env,
|
||||
"meta": lm.options.meta
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user