Compare commits

...

39 Commits

Author SHA1 Message Date
4febec9e89 1.0.22 2018-11-05 23:52:40 +01:00
b65f3af9cf fix(core): update 2018-11-05 23:52:39 +01:00
373b02adb4 1.0.21 2018-11-05 23:41:43 +01:00
11b08cc0a3 fix(core): update 2018-11-05 23:41:43 +01:00
a586069305 1.0.20 2018-11-05 23:29:01 +01:00
8a8c4efcbb fix(core): update 2018-11-05 23:29:01 +01:00
dbb5843f52 1.0.19 2018-11-05 23:25:53 +01:00
d021e934b9 fix(readme): update 2018-11-05 23:25:53 +01:00
3bd8ebb29d 1.0.18 2018-11-04 21:21:34 +01:00
2429e7b7c1 fix(core): update 2018-11-04 21:21:34 +01:00
2bf5665fea 1.0.17 2018-11-04 21:11:48 +01:00
7d62306913 fix(core): update 2018-11-04 21:11:48 +01:00
484e5d51cc 1.0.16 2018-11-04 18:44:28 +01:00
a8bac181a4 fix(core): update 2018-11-04 18:44:28 +01:00
76d3926ba4 1.0.15 2018-11-04 15:49:03 +01:00
0310c03ecb 1.0.14 2018-11-04 15:37:55 +01:00
9e8efc7dea fix(core): update 2018-11-04 15:37:55 +01:00
00e1b8d862 1.0.13 2018-11-04 15:25:27 +01:00
c5cedb027d fix(core): update 2018-11-04 15:25:27 +01:00
f075f7f23a 1.0.12 2018-11-04 14:56:25 +01:00
809df76043 fix(core): update 2018-11-04 14:56:25 +01:00
d1dde293f6 1.0.11 2018-11-04 14:24:13 +01:00
b7ee6bb9a6 fix(smartlog): add getSmartlogDestination() 2018-11-04 14:24:12 +01:00
15cfa8fe88 1.0.10 2018-11-04 02:41:46 +01:00
1e222c7ad8 fix(core): update 2018-11-04 02:41:45 +01:00
91a1571635 1.0.9 2018-11-04 00:05:36 +01:00
2e39906fd2 fix(core): update 2018-11-04 00:05:36 +01:00
7950cb1649 1.0.8 2018-11-03 23:32:31 +01:00
b085dc32db fix(core): update 2018-11-03 23:32:31 +01:00
e44aeccdb6 1.0.7 2018-11-03 23:31:26 +01:00
6c471f3722 fix(core): update 2018-11-03 23:31:26 +01:00
99bfc485cf 1.0.6 2018-11-03 16:22:32 +01:00
a55311c0fd fix(structure): format 2018-11-03 16:22:32 +01:00
7a45f829fc 1.0.5 2018-11-03 14:17:30 +01:00
d95d2705b0 fix(core): update 2018-11-03 14:17:29 +01:00
65312ebd49 1.0.4 2018-11-02 19:13:01 +01:00
3dc0c1cae7 add tests 2018-11-02 19:12:16 +01:00
5e494cb767 1.0.3 2018-11-02 13:57:14 +01:00
e03d4872cf fix(core): update 2018-11-02 13:57:14 +01:00
12 changed files with 363 additions and 98 deletions

4
.snyk Normal file
View File

@ -0,0 +1,4 @@
# Snyk (https://snyk.io) policy file, patches or ignores known vulnerabilities.
version: v1.12.0
ignore: {}
patch: {}

115
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@mojoio/logdna",
"version": "1.0.2",
"version": "1.0.22",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -74,6 +74,19 @@
"@pushrocks/smartpromise": "^2.0.5"
}
},
"@pushrocks/lik": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@pushrocks/lik/-/lik-3.0.1.tgz",
"integrity": "sha512-6dwRg7WMdY9drlqfo6NzOcw5ubVWYvIOSSMZz4Jsojpa8aDVwXd2VkD7sxO/PJRrbZzHkx/JXoY/epcWRjngUw==",
"requires": {
"@pushrocks/smartpromise": "^2.0.5",
"@types/lodash": "^4.14.112",
"@types/minimatch": "^3.0.3",
"lodash": "^4.17.10",
"minimatch": "^3.0.4",
"symbol-tree": "^3.2.2"
}
},
"@pushrocks/qenv": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@pushrocks/qenv/-/qenv-2.0.2.tgz",
@ -87,7 +100,6 @@
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@pushrocks/smartdelay/-/smartdelay-2.0.2.tgz",
"integrity": "sha512-4xf6tMKwZcxBynKgXrM4SQKgeASfRvx43LUmR5DkStp26ZHAsarCXUdKJS6y8QIPygEOTOCP8we97JAcCzBuMg==",
"dev": true,
"requires": {
"@pushrocks/smartpromise": "^2.0.5"
}
@ -113,15 +125,21 @@
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog/-/smartlog-2.0.3.tgz",
"integrity": "sha512-HbH2b6ybd1cD8VTlx5kEt4N/Vgh9TQTHKlUV4kAORFIOTJOQD5WbCMIVWo+VqYHvYQtokoYFCjM1gctp4M1aWw==",
"dev": true,
"requires": {
"@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": {
"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=="
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/@pushrocks/smartlog-interfaces/-/smartlog-interfaces-2.0.2.tgz",
"integrity": "sha512-kJNQ/6kfljgtwebhoiD8WtRWfdVhOoE1nr8FoUJLlOjLphU8SPa42Hg6/yPkSTaGxWwDhk6PkMJl64O7HNjRUQ=="
},
"@pushrocks/smartpath": {
"version": "4.0.1",
@ -180,6 +198,20 @@
"smartchai": "^2.0.1"
}
},
"@pushrocks/taskbuffer": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/@pushrocks/taskbuffer/-/taskbuffer-2.0.5.tgz",
"integrity": "sha512-frzuSoz7Lhlt4y+5vP513BJ/blSalkLH1A4Es0QtxQ6258ekxP/FWC7Bq0Hy7XnNDIlws0WDvd1KN2prSIKZDg==",
"requires": {
"@pushrocks/lik": "^3.0.1",
"@pushrocks/smartdelay": "^2.0.1",
"@pushrocks/smartlog": "^2.0.1",
"@pushrocks/smartpromise": "^2.0.5",
"@types/cron": "^1.3.0",
"cron": "^1.3.0",
"rxjs": "^6.2.2"
}
},
"@types/chai": {
"version": "4.1.7",
"resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.1.7.tgz",
@ -204,6 +236,11 @@
"@types/chai": "*"
}
},
"@types/cron": {
"version": "1.3.0",
"resolved": "http://registry.npmjs.org/@types/cron/-/cron-1.3.0.tgz",
"integrity": "sha512-RNJ6Hbxs9CbUw+Bxt8kpN8/yNlYG1xli0JZSO1xTJJxFjgD2KWctFSkJeJpjf9iLJU0jeNPoJ5LEru7eBN3xuA=="
},
"@types/figures": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@types/figures/-/figures-2.0.0.tgz",
@ -227,10 +264,20 @@
"@types/node": "*"
}
},
"@types/lodash": {
"version": "4.14.117",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.117.tgz",
"integrity": "sha512-xyf2m6tRbz8qQKcxYZa7PA4SllYcay+eh25DN3jmNYY6gSTL7Htc/bttVdkqj2wfJGbeWlQiX8pIyJpKU+tubw=="
},
"@types/minimatch": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.3.tgz",
"integrity": "sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA=="
},
"@types/node": {
"version": "10.12.1",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.1.tgz",
"integrity": "sha512-i1sl+WCX2OCHeUi9oi7PiCNUtYFrpWhpcx878vpeq/tlZTKzcFdHePlyFHVbWqeuKN0SRPl/9ZFDSTsfv9h7VQ=="
"version": "10.12.2",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.12.2.tgz",
"integrity": "sha512-53ElVDSnZeFUUFIYzI8WLQ25IhWzb6vbddNp8UHlXQyU0ET2RhV5zg0NfubzU7iNMh5bBXb0htCzfvrSVNgzaQ=="
},
"@types/vinyl": {
"version": "2.0.2",
@ -320,8 +367,7 @@
"balanced-match": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
"dev": true
"integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
},
"bindings": {
"version": "1.3.0",
@ -333,7 +379,6 @@
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -478,8 +523,7 @@
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"dev": true
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"core-util-is": {
"version": "1.0.2",
@ -487,6 +531,14 @@
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=",
"dev": true
},
"cron": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/cron/-/cron-1.5.0.tgz",
"integrity": "sha512-j7zMFLrcSta53xqOvETUt8ge+PM14GtF47gEGJJeVlM6qP24/eWHSgtiWiEiKBR2sHS8xZaBQZq4D7vFXg8dcQ==",
"requires": {
"moment-timezone": "^0.5.x"
}
},
"crypto-random-string": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/crypto-random-string/-/crypto-random-string-1.0.0.tgz",
@ -715,6 +767,11 @@
"integrity": "sha512-XI5MPzVNApjAyhQzphX8BkmKsKUxD4LdyK24iZeQGinBN9yTQT3bFlCBy/aVx2HrNcqQGsdot8ghrjyrvMCoEA==",
"dev": true
},
"lodash": {
"version": "4.17.11",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz",
"integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg=="
},
"make-error": {
"version": "1.3.5",
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.5.tgz",
@ -743,7 +800,6 @@
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"dev": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -771,6 +827,19 @@
}
}
},
"moment": {
"version": "2.22.2",
"resolved": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz",
"integrity": "sha1-PCV/mDn8DpP/UxSWMiOeuQeD/2Y="
},
"moment-timezone": {
"version": "0.5.23",
"resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.23.tgz",
"integrity": "sha512-WHFH85DkCfiNMDX5D3X7hpNH3/PUhjTGcD0U1SgfBGZxJ3qUmJh5FdvaFjcClxOvB3rzdfj4oRffbI38jEnC1w==",
"requires": {
"moment": ">= 2.9.0"
}
},
"nan": {
"version": "2.11.1",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.11.1.tgz",
@ -873,6 +942,14 @@
"path-parse": "^1.0.5"
}
},
"rxjs": {
"version": "6.3.3",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.3.3.tgz",
"integrity": "sha512-JTWmoY9tWCs7zvIk/CvRjhjGaOd+OVBM987mxFo+OW66cGpdKjZcpmc74ES1sB//7Kl/PAe8+wEakuhG4pcgOw==",
"requires": {
"tslib": "^1.9.0"
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
@ -978,6 +1055,11 @@
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=",
"dev": true
},
"symbol-tree": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.2.tgz",
"integrity": "sha1-rifbOPZgp64uHDt9G8KQgZuFGeY="
},
"ts-node": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz",
@ -997,8 +1079,7 @@
"tslib": {
"version": "1.9.3",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-1.9.3.tgz",
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==",
"dev": true
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
},
"tslint": {
"version": "5.11.0",

View File

@ -1,6 +1,6 @@
{
"name": "@mojoio/logdna",
"version": "1.0.2",
"version": "1.0.22",
"private": false,
"description": "anunoffical package for the logdna api",
"main": "dist/index.js",
@ -17,13 +17,15 @@
"@gitzone/tstest": "^1.0.15",
"@pushrocks/qenv": "^2.0.2",
"@pushrocks/tapbundle": "^3.0.7",
"@types/node": "^10.11.7",
"@types/node": "^10.12.2",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0"
},
"dependencies": {
"@pushrocks/smartlog-interfaces": "^1.0.15",
"@pushrocks/lik": "^3.0.1",
"@pushrocks/smartlog-interfaces": "^2.0.2",
"@pushrocks/smartrequest": "^1.1.14",
"@pushrocks/smartstring": "^3.0.4"
"@pushrocks/smartstring": "^3.0.4",
"@pushrocks/taskbuffer": "^2.0.5"
}
}

View File

@ -1,2 +1,2 @@
vars:
-
- LOGDNA_APIKEY

68
readme.md Normal file
View File

@ -0,0 +1,68 @@
# @mojoio/logdna
anunoffical package for the logdna api
## Availabililty
[![npm](https://mojoio.gitlab.io/assets/repo-button-npm.svg)](https://www.npmjs.com/package/@mojoio/logdna)
[![git](https://mojoio.gitlab.io/assets/repo-button-git.svg)](https://GitLab.com/mojoio/logdna)
[![git](https://mojoio.gitlab.io/assets/repo-button-mirror.svg)](https://github.com/mojoio/logdna)
[![docs](https://mojoio.gitlab.io/assets/repo-button-docs.svg)](https://mojoio.gitlab.io/logdna/)
## Status for master
[![build status](https://GitLab.com/mojoio/logdna/badges/master/build.svg)](https://GitLab.com/mojoio/logdna/commits/master)
[![coverage report](https://GitLab.com/mojoio/logdna/badges/master/coverage.svg)](https://GitLab.com/mojoio/logdna/commits/master)
[![npm downloads per month](https://img.shields.io/npm/dm/@mojoio/logdna.svg)](https://www.npmjs.com/package/@mojoio/logdna)
[![Known Vulnerabilities](https://snyk.io/test/npm/@mojoio/logdna/badge.svg)](https://snyk.io/test/npm/@mojoio/logdna)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](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)
[![repo-footer](https://mojoio.gitlab.io/assets/repo-footer.svg)](https://mojo.io)

View File

@ -2,6 +2,7 @@ import { expect, tap } from '@pushrocks/tapbundle';
import * as logdna from '../ts/index';
import { Qenv } from '@pushrocks/qenv';
import { ILogPackage } from '@pushrocks/smartlog-interfaces';
const testQenv = new Qenv('./', './.nogit');
@ -9,11 +10,52 @@ let testLogDnaAccount: logdna.LogdnaAccount;
let testLogMessage: logdna.LogdnaMessage;
tap.test('should create a valid logDna account', async () => {
testLogDnaAccount = new logdna.LogdnaAccount();
testLogDnaAccount = new logdna.LogdnaAccount(process.env.LOGDNA_APIKEY);
});
tap.test('should create a standard log message', async () => {
testLogMessage = logdna.LogdnaMessage.fromSmartLogPackage({
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'
});
});
tap.test('should send the message', async () => {
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();

View File

@ -1,2 +1,2 @@
export * from './logdna.logdnaaccount';
export * from './logdna.classes.logmessage';
export * from './logdna.classes.logmessage';

57
ts/logdna.aggregator.ts Normal file
View 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);
}
}
}

View File

@ -6,6 +6,11 @@ import { TLogLevel, TEnvironment, ILogPackage } from '@pushrocks/smartlog-interf
* the constructor options for LogdnaMessage
*/
export interface ILogdnaMessageContructorOptions {
/**
* a timestamp for then the log message was created
*/
timestamp: number;
/**
* the hostname where the log message was created
*/
@ -22,7 +27,7 @@ export interface ILogdnaMessageContructorOptions {
ip: string;
/**
* a text message, that is the core part
* a text message, that is the core part
*/
line: string;
@ -44,7 +49,7 @@ export interface ILogdnaMessageContructorOptions {
/**
* any metadata that is used
*/
metaData: any;
meta: any;
/**
* an array of strings
@ -56,22 +61,38 @@ export interface ILogdnaMessageContructorOptions {
* a basic LogdnaMessage
*/
export class LogdnaMessage {
static fromSmartLogPackage (smartlogPackageArg: ILogPackage): LogdnaMessage {
/**
* create lgdna messages from smartlog package
* @param smartlogPackageArg
*/
public static fromSmartLogPackage(smartlogPackageArg: ILogPackage): LogdnaMessage {
return new LogdnaMessage({
timestamp: smartlogPackageArg.timestamp,
line: smartlogPackageArg.message,
metaData: smartlogPackageArg.logContext,
env: smartlogPackageArg.logContext.environment,
hostname: smartlogPackageArg.logContext.zone,
level: smartlogPackageArg.logLevel,
app: smartlogPackageArg.logContext.zone,
tags: [],
meta: {
...smartlogPackageArg.context,
logType: smartlogPackageArg.type
},
env: smartlogPackageArg.context.environment,
hostname: smartlogPackageArg.context.zone,
level: smartlogPackageArg.level,
app: smartlogPackageArg.context.containerName,
tags: (() => {
const tagArray: string[] = [];
tagArray.push(smartlogPackageArg.context.company);
tagArray.push(smartlogPackageArg.context.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

@ -1,60 +1,72 @@
import * as plugins from './logdna.plugins';
import { LogdnaMessage } from './logdna.classes.logmessage';
import { LogAggregator } from './logdna.aggregator';
import { ILogPackage, ILogDestination } from '@pushrocks/smartlog-interfaces';
/**
* 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)}`;
}
private logAggregator: LogAggregator;
/**
*
* @param apiKeyArg
*/
constructor(apiKeyArg: string) {
this.apiKey = apiKeyArg;
this.logAggregator = new LogAggregator(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) {
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"
}
}
}
]
}
});
const uriHostname = euc(lm.options.hostname);
const uriMac = euc(lm.options.mac);
const uriIp = euc(lm.options.ip);
const uriTags = euc(
(() => {
return lm.options.tags.reduce((reduced, newItem) => {
return `${reduced},${newItem}`;
});
})()
);
// let construct the request uri
const requestUrlWithParams = `?hostname=${uriHostname}&mac=${uriMac}&ip=1${uriIp}&tags=${uriTags}`;
const logLine = {
timestamp: lm.options.timestamp,
line: lm.options.line,
app: lm.options.app,
level: lm.options.level,
env: lm.options.env,
meta: lm.options.meta
};
this.logAggregator.addLog(requestUrlWithParams, logLine);
}
/**
* convenience function for smartlog
*/
public async sendSmartlogPackage(smartlogPackageArg: ILogPackage) {
this.sendLogdnaMessage(LogdnaMessage.fromSmartLogPackage(smartlogPackageArg));
}
/**
* returns a smartlog compatible log destination
*/
public get smartlogDestination(): ILogDestination {
return {
handleLog: logPackageArg => {
this.sendSmartlogPackage(logPackageArg);
}
};
}
}

View File

@ -1,9 +1,6 @@
import * as lik from '@pushrocks/lik';
import * as smartrequest from '@pushrocks/smartrequest';
import * as smartstring from '@pushrocks/smartstring';
import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';
export {
smartrequest,
smartstring,
smartlogInterfaces
};
export { lik, smartrequest, smartstring, smartlogInterfaces };

View File

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