fix(core): update

This commit is contained in:
2018-11-02 13:57:14 +01:00
parent 35ac4a76b8
commit e03d4872cf
6 changed files with 125 additions and 27 deletions

View File

@ -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;
};

View File

@ -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
}
]
}