initial
This commit is contained in:
3
ts/index.ts
Normal file
3
ts/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import * as plugins from './logdna.plugins';
|
||||
|
||||
export let standardExport = 'Hi there! :) This is an exported string';
|
77
ts/logdna.classes.logmessage.ts
Normal file
77
ts/logdna.classes.logmessage.ts
Normal file
@ -0,0 +1,77 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* a text message, that is the core part
|
||||
*/
|
||||
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
|
||||
*/
|
||||
metaData: any;
|
||||
|
||||
/**
|
||||
* an array of strings
|
||||
*/
|
||||
tags: string[];
|
||||
}
|
||||
|
||||
/**
|
||||
* a basic LogdnaMessage
|
||||
*/
|
||||
export class LogdnaMessage {
|
||||
static fromSmartLogPackage (smartlogPackageArg: ILogPackage): LogdnaMessage {
|
||||
return new LogdnaMessage({
|
||||
line: smartlogPackageArg.message,
|
||||
metaData: smartlogPackageArg.logContext,
|
||||
env: smartlogPackageArg.logContext.environment,
|
||||
hostname: smartlogPackageArg.logContext.zone,
|
||||
level: smartlogPackageArg.logLevel,
|
||||
app: smartlogPackageArg.logContext.zone,
|
||||
tags: [],
|
||||
ip: '0.0.0.0',
|
||||
mac: 'aa:aa:aa:aa:aa:aa'
|
||||
});
|
||||
};
|
||||
|
||||
options: ILogdnaMessageContructorOptions;
|
||||
constructor(optionsArg: ILogdnaMessageContructorOptions) {
|
||||
this.options = optionsArg;
|
||||
};
|
||||
}
|
60
ts/logdna.logdnaaccount.ts
Normal file
60
ts/logdna.logdnaaccount.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import * as plugins from './logdna.plugins';
|
||||
|
||||
import { LogdnaMessage } from './logdna.classes.logmessage';
|
||||
|
||||
/**
|
||||
* the main logdna account
|
||||
*/
|
||||
export class LogdnaAccount {
|
||||
apiKey: string;
|
||||
baseUrl = 'https://logs.logdna.com/logs/ingest';
|
||||
|
||||
/**
|
||||
* Create basic authentication
|
||||
*/
|
||||
createBasicAuth() {
|
||||
const userNamePasswordString = `${this.apiKey}:`;
|
||||
return `Basic ${plugins.smartstring.base64.encode(userNamePasswordString)}`;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param apiKeyArg
|
||||
*/
|
||||
constructor(apiKeyArg: string) {
|
||||
this.apiKey = apiKeyArg;
|
||||
}
|
||||
|
||||
/**
|
||||
* sends a logmessage
|
||||
* async, so it returns a Promise. In most cases it does not make sense to wait for it though.
|
||||
*/
|
||||
public async sendLogDnaMessage(logdnaMessageArg: LogdnaMessage) {
|
||||
const lm = logdnaMessageArg;
|
||||
const euc = encodeURIComponent;
|
||||
const requestUrlWithParams = `${this.baseUrl}?hostname=${euc(
|
||||
lm.options.hostname
|
||||
)}&mac=${euc(lm.options.mac)}&ip=1${euc(lm.options.ip)}&now=${Date.now()}`;
|
||||
await plugins.smartrequest.postJson(requestUrlWithParams, {
|
||||
headers: {
|
||||
'Authorization': this.createBasicAuth(),
|
||||
'charset': 'UTF-8'
|
||||
},
|
||||
requestBody: {
|
||||
"lines": [
|
||||
{
|
||||
"line":"This is an awesome log statement",
|
||||
"app":"myapp",
|
||||
"level": "INFO",
|
||||
"env": "production",
|
||||
"meta": {
|
||||
"customfield": {
|
||||
"nestedfield": "nestedvalue"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
9
ts/logdna.plugins.ts
Normal file
9
ts/logdna.plugins.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import * as smartrequest from '@pushrocks/smartrequest';
|
||||
import * as smartstring from '@pushrocks/smartstring';
|
||||
import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';
|
||||
|
||||
export {
|
||||
smartrequest,
|
||||
smartstring,
|
||||
smartlogInterfaces
|
||||
};
|
0
ts/request.sh
Normal file
0
ts/request.sh
Normal file
Reference in New Issue
Block a user