Compare commits
35 Commits
Author | SHA1 | Date | |
---|---|---|---|
4febec9e89 | |||
b65f3af9cf | |||
373b02adb4 | |||
11b08cc0a3 | |||
a586069305 | |||
8a8c4efcbb | |||
dbb5843f52 | |||
d021e934b9 | |||
3bd8ebb29d | |||
2429e7b7c1 | |||
2bf5665fea | |||
7d62306913 | |||
484e5d51cc | |||
a8bac181a4 | |||
76d3926ba4 | |||
0310c03ecb | |||
9e8efc7dea | |||
00e1b8d862 | |||
c5cedb027d | |||
f075f7f23a | |||
809df76043 | |||
d1dde293f6 | |||
b7ee6bb9a6 | |||
15cfa8fe88 | |||
1e222c7ad8 | |||
91a1571635 | |||
2e39906fd2 | |||
7950cb1649 | |||
b085dc32db | |||
e44aeccdb6 | |||
6c471f3722 | |||
99bfc485cf | |||
a55311c0fd | |||
7a45f829fc | |||
d95d2705b0 |
4
.snyk
Normal file
4
.snyk
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
|
||||||
|
version: v1.12.0
|
||||||
|
ignore: {}
|
||||||
|
patch: {}
|
21
package-lock.json
generated
21
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/logdna",
|
"name": "@mojoio/logdna",
|
||||||
"version": "1.0.4",
|
"version": "1.0.22",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -127,12 +127,19 @@
|
|||||||
"integrity": "sha512-HbH2b6ybd1cD8VTlx5kEt4N/Vgh9TQTHKlUV4kAORFIOTJOQD5WbCMIVWo+VqYHvYQtokoYFCjM1gctp4M1aWw==",
|
"integrity": "sha512-HbH2b6ybd1cD8VTlx5kEt4N/Vgh9TQTHKlUV4kAORFIOTJOQD5WbCMIVWo+VqYHvYQtokoYFCjM1gctp4M1aWw==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@pushrocks/smartlog-interfaces": "^1.0.9"
|
"@pushrocks/smartlog-interfaces": "^1.0.9"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@pushrocks/smartlog-interfaces": {
|
||||||
|
"version": "1.0.15",
|
||||||
|
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-1.0.15.tgz",
|
||||||
|
"integrity": "sha512-dn9a+IhneukhtVGQG031oodOITmmQ5s5hcMThd+cMUQL3XYTbLPnZVuJfTDeWCT0iqLqrBD/qp2d1RRc3W/qIQ=="
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@pushrocks/smartlog-interfaces": {
|
"@pushrocks/smartlog-interfaces": {
|
||||||
"version": "1.0.15",
|
"version": "2.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-1.0.15.tgz",
|
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-2.0.2.tgz",
|
||||||
"integrity": "sha512-dn9a+IhneukhtVGQG031oodOITmmQ5s5hcMThd+cMUQL3XYTbLPnZVuJfTDeWCT0iqLqrBD/qp2d1RRc3W/qIQ=="
|
"integrity": "sha512-kJNQ/6kfljgtwebhoiD8WtRWfdVhOoE1nr8FoUJLlOjLphU8SPa42Hg6/yPkSTaGxWwDhk6PkMJl64O7HNjRUQ=="
|
||||||
},
|
},
|
||||||
"@pushrocks/smartpath": {
|
"@pushrocks/smartpath": {
|
||||||
"version": "4.0.1",
|
"version": "4.0.1",
|
||||||
@ -268,9 +275,9 @@
|
|||||||
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
|
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "10.12.1",
|
"version": "10.12.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.2.tgz",
|
||||||
"integrity": "sha512-i1sl+WCX2OCHeUi9oi7PiCNUtYFrpWhpcx878vpeq/tlZTKzcFdHePlyFHVbWqeuKN0SRPl/9ZFDSTsfv9h7VQ=="
|
"integrity": "sha512-53ElVDSnZeFUUFIYzI8WLQ25IhWzb6vbddNp8UHlXQyU0ET2RhV5zg0NfubzU7iNMh5bBXb0htCzfvrSVNgzaQ=="
|
||||||
},
|
},
|
||||||
"@types/vinyl": {
|
"@types/vinyl": {
|
||||||
"version": "2.0.2",
|
"version": "2.0.2",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/logdna",
|
"name": "@mojoio/logdna",
|
||||||
"version": "1.0.4",
|
"version": "1.0.22",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "anunoffical package for the logdna api",
|
"description": "anunoffical package for the logdna api",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -17,12 +17,13 @@
|
|||||||
"@gitzone/tstest": "^1.0.15",
|
"@gitzone/tstest": "^1.0.15",
|
||||||
"@pushrocks/qenv": "^2.0.2",
|
"@pushrocks/qenv": "^2.0.2",
|
||||||
"@pushrocks/tapbundle": "^3.0.7",
|
"@pushrocks/tapbundle": "^3.0.7",
|
||||||
"@types/node": "^10.11.7",
|
"@types/node": "^10.12.2",
|
||||||
"tslint": "^5.11.0",
|
"tslint": "^5.11.0",
|
||||||
"tslint-config-prettier": "^1.15.0"
|
"tslint-config-prettier": "^1.15.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartlog-interfaces": "^1.0.15",
|
"@pushrocks/lik": "^3.0.1",
|
||||||
|
"@pushrocks/smartlog-interfaces": "^2.0.2",
|
||||||
"@pushrocks/smartrequest": "^1.1.14",
|
"@pushrocks/smartrequest": "^1.1.14",
|
||||||
"@pushrocks/smartstring": "^3.0.4",
|
"@pushrocks/smartstring": "^3.0.4",
|
||||||
"@pushrocks/taskbuffer": "^2.0.5"
|
"@pushrocks/taskbuffer": "^2.0.5"
|
||||||
|
68
readme.md
Normal file
68
readme.md
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
# @mojoio/logdna
|
||||||
|
anunoffical package for the logdna api
|
||||||
|
|
||||||
|
## Availabililty
|
||||||
|
[](https://www.npmjs.com/package/@mojoio/logdna)
|
||||||
|
[](https://GitLab.com/mojoio/logdna)
|
||||||
|
[](https://github.com/mojoio/logdna)
|
||||||
|
[](https://mojoio.gitlab.io/logdna/)
|
||||||
|
|
||||||
|
## Status for master
|
||||||
|
[](https://GitLab.com/mojoio/logdna/commits/master)
|
||||||
|
[](https://GitLab.com/mojoio/logdna/commits/master)
|
||||||
|
[](https://www.npmjs.com/package/@mojoio/logdna)
|
||||||
|
[](https://snyk.io/test/npm/@mojoio/logdna)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||||
|
[](http://standardjs.com/)
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
This package is an unofficial package for the logdna. It comes with the following festures:
|
||||||
|
|
||||||
|
* aggregates logs that require the same uri query parameters and sends them as bundle. This ensures the correct order of logs
|
||||||
|
* resends logs that failed to send.
|
||||||
|
* supports smartlog messages and the smartlog ecosystem
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { ILogPackage } from '@pushrocks/smartlog-interfaces'
|
||||||
|
|
||||||
|
import { LogdnaAccount, LogdnaMessage } from '@mojoio/logdna';
|
||||||
|
|
||||||
|
// lets create a logDnaAccount
|
||||||
|
const logDnaAccount = new LogdnaAccount(process.env.LOGDNA_APIKEY);
|
||||||
|
|
||||||
|
// lets create a smartlog message (smartlog normally takes care of creating those objects)
|
||||||
|
const smartlogPackage: ILogPackage = {
|
||||||
|
timestamp: Date.now(),
|
||||||
|
type: 'log',
|
||||||
|
level: 'info',
|
||||||
|
context: {
|
||||||
|
company: 'Lossless GmbH',
|
||||||
|
companyunit: 'lossless.cloud',
|
||||||
|
containerName: 'ci-mojoio-logdna',
|
||||||
|
environment: 'test',
|
||||||
|
runtime: 'node',
|
||||||
|
zone: 'shipzone'
|
||||||
|
},
|
||||||
|
message: 'this is an awesome log message sent by the tapbundle test'
|
||||||
|
};
|
||||||
|
|
||||||
|
const logdnaMessage = LogdnaMessage.fromSmartLogPackage(smartlogPackage);
|
||||||
|
|
||||||
|
logDnaAccount.sendLogdnaMessage(logdnaMessage);
|
||||||
|
|
||||||
|
// alternatively simply send the smartlogPackage
|
||||||
|
// creation of the LogdnaMessage is done for you
|
||||||
|
logDnaAccount.sendSmartlogPackage(smartlogPackage)
|
||||||
|
|
||||||
|
// most of the above funtions return promises should you want to wait for a log to be fully sent
|
||||||
|
```
|
||||||
|
|
||||||
|
For further information read the linked docs at the top of this README.
|
||||||
|
|
||||||
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
|
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
|
[](https://mojo.io)
|
37
test/test.ts
37
test/test.ts
@ -2,6 +2,7 @@ import { expect, tap } from '@pushrocks/tapbundle';
|
|||||||
import * as logdna from '../ts/index';
|
import * as logdna from '../ts/index';
|
||||||
|
|
||||||
import { Qenv } from '@pushrocks/qenv';
|
import { Qenv } from '@pushrocks/qenv';
|
||||||
|
import { ILogPackage } from '@pushrocks/smartlog-interfaces';
|
||||||
|
|
||||||
const testQenv = new Qenv('./', './.nogit');
|
const testQenv = new Qenv('./', './.nogit');
|
||||||
|
|
||||||
@ -14,21 +15,47 @@ tap.test('should create a valid logDna account', async () => {
|
|||||||
|
|
||||||
tap.test('should create a standard log message', async () => {
|
tap.test('should create a standard log message', async () => {
|
||||||
testLogMessage = logdna.LogdnaMessage.fromSmartLogPackage({
|
testLogMessage = logdna.LogdnaMessage.fromSmartLogPackage({
|
||||||
logContext: {
|
timestamp: Date.now(),
|
||||||
|
type: 'log',
|
||||||
|
level: 'info',
|
||||||
|
context: {
|
||||||
company: 'Lossless GmbH',
|
company: 'Lossless GmbH',
|
||||||
companyunit: 'lossless.cloud',
|
companyunit: 'lossless.cloud',
|
||||||
containerName: 'ci-mojoio-logdna',
|
containerName: 'ci-mojoio-logdna',
|
||||||
environment: 'test',
|
environment: 'test',
|
||||||
runtime: 'node',
|
runtime: 'node',
|
||||||
zone: 'ship.zone'
|
zone: 'shipzone'
|
||||||
},
|
},
|
||||||
logLevel: 'info',
|
message: 'this is an awesome log message sent by the tapbundle test'
|
||||||
message: 'this is a awesome log message :)'
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should send the message', async () => {
|
tap.test('should send the message', async () => {
|
||||||
await testLogDnaAccount.sendLogDnaMessage(testLogMessage);
|
await testLogDnaAccount.sendLogdnaMessage(testLogMessage);
|
||||||
|
});
|
||||||
|
|
||||||
|
tap.test('should send in order', async () => {
|
||||||
|
let i = 1;
|
||||||
|
while (i < 21) {
|
||||||
|
const testSmartlogMessage: ILogPackage = {
|
||||||
|
timestamp: Date.now(),
|
||||||
|
type: 'log',
|
||||||
|
level: 'info',
|
||||||
|
context: {
|
||||||
|
company: 'Lossless GmbH',
|
||||||
|
companyunit: 'lossless.cloud',
|
||||||
|
containerName: 'ci-mojoio-logdna',
|
||||||
|
environment: 'test',
|
||||||
|
runtime: 'node',
|
||||||
|
zone: 'shipzone'
|
||||||
|
},
|
||||||
|
message: `this is an awesome log message sent by the tapbundle test #${i}`
|
||||||
|
};
|
||||||
|
testLogDnaAccount.sendSmartlogPackage(testSmartlogMessage);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
tap.start();
|
tap.start();
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
export * from './logdna.logdnaaccount';
|
export * from './logdna.logdnaaccount';
|
||||||
export * from './logdna.classes.logmessage';
|
export * from './logdna.classes.logmessage';
|
||||||
|
57
ts/logdna.aggregator.ts
Normal file
57
ts/logdna.aggregator.ts
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
import * as plugins from './logdna.plugins';
|
||||||
|
import { LogdnaAccount } from './logdna.logdnaaccount';
|
||||||
|
|
||||||
|
export interface ILogCandidate {
|
||||||
|
urlIdentifier: string;
|
||||||
|
logLines: any[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class LogAggregator {
|
||||||
|
private apiKey: string;
|
||||||
|
private baseUrl = 'https://logs.logdna.com/logs/ingest';
|
||||||
|
|
||||||
|
private logObjectMap = new plugins.lik.Objectmap<ILogCandidate>();
|
||||||
|
|
||||||
|
constructor(apiKeyArg: string) {
|
||||||
|
this.apiKey = apiKeyArg;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create basic authentication
|
||||||
|
*/
|
||||||
|
private createBasicAuth() {
|
||||||
|
const userNamePasswordString = `${this.apiKey}:`;
|
||||||
|
return `Basic ${plugins.smartstring.base64.encode(userNamePasswordString)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
public addLog(urlIdentifierArg: string, logLineArg: any) {
|
||||||
|
let existinglogCandidate = this.logObjectMap.find(logCandidate => {
|
||||||
|
return logCandidate.urlIdentifier === urlIdentifierArg;
|
||||||
|
});
|
||||||
|
if (!existinglogCandidate) {
|
||||||
|
existinglogCandidate = { urlIdentifier: urlIdentifierArg, logLines: [] };
|
||||||
|
this.logObjectMap.add(existinglogCandidate);
|
||||||
|
setTimeout(() => {
|
||||||
|
this.sendAggregatedLogs(existinglogCandidate);
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
existinglogCandidate.logLines.push(logLineArg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async sendAggregatedLogs(logCandidate: ILogCandidate) {
|
||||||
|
this.logObjectMap.remove(logCandidate);
|
||||||
|
// lets post the message to logdna
|
||||||
|
const response = await plugins.smartrequest.postJson(`${this.baseUrl}${logCandidate.urlIdentifier}&now=${Date.now()}` , {
|
||||||
|
headers: {
|
||||||
|
Authorization: this.createBasicAuth(),
|
||||||
|
charset: 'UTF-8'
|
||||||
|
},
|
||||||
|
requestBody: {
|
||||||
|
lines: logCandidate.logLines
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(response.statusCode !== 200) {
|
||||||
|
console.log(response.body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,11 @@ import { TLogLevel, TEnvironment, ILogPackage } from '@pushrocks/smartlog-interf
|
|||||||
* the constructor options for LogdnaMessage
|
* the constructor options for LogdnaMessage
|
||||||
*/
|
*/
|
||||||
export interface ILogdnaMessageContructorOptions {
|
export interface ILogdnaMessageContructorOptions {
|
||||||
|
/**
|
||||||
|
* a timestamp for then the log message was created
|
||||||
|
*/
|
||||||
|
timestamp: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the hostname where the log message was created
|
* the hostname where the log message was created
|
||||||
*/
|
*/
|
||||||
@ -22,7 +27,7 @@ export interface ILogdnaMessageContructorOptions {
|
|||||||
ip: string;
|
ip: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* a text message, that is the core part
|
* a text message, that is the core part
|
||||||
*/
|
*/
|
||||||
line: string;
|
line: string;
|
||||||
|
|
||||||
@ -60,24 +65,28 @@ export class LogdnaMessage {
|
|||||||
* create lgdna messages from smartlog package
|
* create lgdna messages from smartlog package
|
||||||
* @param smartlogPackageArg
|
* @param smartlogPackageArg
|
||||||
*/
|
*/
|
||||||
static fromSmartLogPackage (smartlogPackageArg: ILogPackage): LogdnaMessage {
|
public static fromSmartLogPackage(smartlogPackageArg: ILogPackage): LogdnaMessage {
|
||||||
return new LogdnaMessage({
|
return new LogdnaMessage({
|
||||||
|
timestamp: smartlogPackageArg.timestamp,
|
||||||
line: smartlogPackageArg.message,
|
line: smartlogPackageArg.message,
|
||||||
meta: smartlogPackageArg.logContext,
|
meta: {
|
||||||
env: smartlogPackageArg.logContext.environment,
|
...smartlogPackageArg.context,
|
||||||
hostname: smartlogPackageArg.logContext.zone,
|
logType: smartlogPackageArg.type
|
||||||
level: smartlogPackageArg.logLevel,
|
},
|
||||||
app: smartlogPackageArg.logContext.zone,
|
env: smartlogPackageArg.context.environment,
|
||||||
|
hostname: smartlogPackageArg.context.zone,
|
||||||
|
level: smartlogPackageArg.level,
|
||||||
|
app: smartlogPackageArg.context.containerName,
|
||||||
tags: (() => {
|
tags: (() => {
|
||||||
const tagArray: string[] = [];
|
const tagArray: string[] = [];
|
||||||
tagArray.push(smartlogPackageArg.logContext.company);
|
tagArray.push(smartlogPackageArg.context.company);
|
||||||
tagArray.push(smartlogPackageArg.logContext.companyunit);
|
tagArray.push(smartlogPackageArg.context.companyunit);
|
||||||
return tagArray;
|
return tagArray;
|
||||||
})(),
|
})(),
|
||||||
ip: '0.0.0.0',
|
ip: '0.0.0.0',
|
||||||
mac: 'aa:aa:aa:aa:aa:aa'
|
mac: 'aa:aa:aa:aa:aa:aa'
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the options of this log message
|
* the options of this log message
|
||||||
@ -85,5 +94,5 @@ export class LogdnaMessage {
|
|||||||
public options: ILogdnaMessageContructorOptions;
|
public options: ILogdnaMessageContructorOptions;
|
||||||
constructor(optionsArg: ILogdnaMessageContructorOptions) {
|
constructor(optionsArg: ILogdnaMessageContructorOptions) {
|
||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,69 +1,72 @@
|
|||||||
import * as plugins from './logdna.plugins';
|
import * as plugins from './logdna.plugins';
|
||||||
|
|
||||||
import { LogdnaMessage } from './logdna.classes.logmessage';
|
import { LogdnaMessage } from './logdna.classes.logmessage';
|
||||||
|
import { LogAggregator } from './logdna.aggregator';
|
||||||
|
import { ILogPackage, ILogDestination } from '@pushrocks/smartlog-interfaces';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the main logdna account
|
* the main logdna account
|
||||||
*/
|
*/
|
||||||
export class LogdnaAccount {
|
export class LogdnaAccount {
|
||||||
apiKey: string;
|
private logAggregator: LogAggregator;
|
||||||
baseUrl = 'https://logs.logdna.com/logs/ingest';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create basic authentication
|
|
||||||
*/
|
|
||||||
createBasicAuth() {
|
|
||||||
const userNamePasswordString = `${this.apiKey}:`;
|
|
||||||
return `Basic ${plugins.smartstring.base64.encode(userNamePasswordString)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param apiKeyArg
|
* @param apiKeyArg
|
||||||
*/
|
*/
|
||||||
constructor(apiKeyArg: string) {
|
constructor(apiKeyArg: string) {
|
||||||
this.apiKey = apiKeyArg;
|
this.logAggregator = new LogAggregator(apiKeyArg);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sends a logmessage
|
* sends a logmessage
|
||||||
* async, so it returns a Promise. In most cases it does not make sense to wait for it though.
|
* async, so it returns a Promise. In most cases it does not make sense to wait for it though.
|
||||||
*/
|
*/
|
||||||
public async sendLogDnaMessage(logdnaMessageArg: LogdnaMessage) {
|
public async sendLogdnaMessage(logdnaMessageArg: LogdnaMessage) {
|
||||||
const lm = logdnaMessageArg;
|
const lm = logdnaMessageArg;
|
||||||
const euc = encodeURIComponent;
|
const euc = encodeURIComponent;
|
||||||
|
|
||||||
// let construct the request uri
|
const uriHostname = euc(lm.options.hostname);
|
||||||
const requestUrlWithParams = `${this.baseUrl}?hostname=${euc(lm.options.hostname)}&mac=${euc(
|
const uriMac = euc(lm.options.mac);
|
||||||
lm.options.mac
|
const uriIp = euc(lm.options.ip);
|
||||||
)}&ip=1${euc(lm.options.ip)}&now=${Date.now()}`;
|
const uriTags = euc(
|
||||||
|
(() => {
|
||||||
|
return lm.options.tags.reduce((reduced, newItem) => {
|
||||||
|
return `${reduced},${newItem}`;
|
||||||
|
});
|
||||||
|
})()
|
||||||
|
);
|
||||||
|
|
||||||
const requestBodyObject = {
|
// let construct the request uri
|
||||||
lines: [
|
const requestUrlWithParams = `?hostname=${uriHostname}&mac=${uriMac}&ip=1${uriIp}&tags=${uriTags}`;
|
||||||
{
|
|
||||||
line: lm.options.line,
|
const logLine = {
|
||||||
app: lm.options.app,
|
timestamp: lm.options.timestamp,
|
||||||
level: lm.options.level,
|
line: lm.options.line,
|
||||||
env: lm.options.env,
|
app: lm.options.app,
|
||||||
meta: lm.options.meta,
|
level: lm.options.level,
|
||||||
tags: (() => {
|
env: lm.options.env,
|
||||||
return lm.options.tags.reduce((reduced, newItem) => {
|
meta: lm.options.meta
|
||||||
return `${reduced},${newItem}`;
|
|
||||||
});
|
|
||||||
})()
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(requestBodyObject);
|
this.logAggregator.addLog(requestUrlWithParams, logLine);
|
||||||
|
}
|
||||||
|
|
||||||
// lets post the message to logdna
|
/**
|
||||||
await plugins.smartrequest.postJson(requestUrlWithParams, {
|
* convenience function for smartlog
|
||||||
headers: {
|
*/
|
||||||
Authorization: this.createBasicAuth(),
|
public async sendSmartlogPackage(smartlogPackageArg: ILogPackage) {
|
||||||
charset: 'UTF-8'
|
this.sendLogdnaMessage(LogdnaMessage.fromSmartLogPackage(smartlogPackageArg));
|
||||||
},
|
}
|
||||||
requestBody: requestBodyObject
|
|
||||||
});
|
/**
|
||||||
|
* returns a smartlog compatible log destination
|
||||||
|
*/
|
||||||
|
public get smartlogDestination(): ILogDestination {
|
||||||
|
return {
|
||||||
|
handleLog: logPackageArg => {
|
||||||
|
this.sendSmartlogPackage(logPackageArg);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
|
import * as lik from '@pushrocks/lik';
|
||||||
import * as smartrequest from '@pushrocks/smartrequest';
|
import * as smartrequest from '@pushrocks/smartrequest';
|
||||||
import * as smartstring from '@pushrocks/smartstring';
|
import * as smartstring from '@pushrocks/smartstring';
|
||||||
import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';
|
import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';
|
||||||
|
|
||||||
export {
|
export { lik, smartrequest, smartstring, smartlogInterfaces };
|
||||||
smartrequest,
|
|
||||||
smartstring,
|
|
||||||
smartlogInterfaces
|
|
||||||
};
|
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
curl "https://logs.logdna.com/logs/ingest?hostname=EXAMPLE_HOST&mac=C0:FF:EE:C0:FF:EE&ip=10.0.1.101&now=$(date +%s)" \
|
|
||||||
-u INSERT_INGESTION_KEY: \
|
|
||||||
-H "Content-Type: application/json; charset=UTF-8" \
|
|
||||||
-d \
|
|
||||||
'{
|
|
||||||
"lines": [
|
|
||||||
{
|
|
||||||
"line":"This is an awesome log statement",
|
|
||||||
"app":"myapp",
|
|
||||||
"level": "INFO",
|
|
||||||
"env": "production",
|
|
||||||
"meta": {
|
|
||||||
"customfield": {
|
|
||||||
"nestedfield": "nestedvalue"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}'
|
|
Reference in New Issue
Block a user