From d021e934b95fa3ee3a1a88e784aa3e9ce6d5fd23 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Mon, 5 Nov 2018 23:25:53 +0100 Subject: [PATCH] fix(readme): update --- readme.md | 68 ++++++++++++++++++++++++++++++++++++++ ts/logdna.aggregator.ts | 5 ++- ts/logdna.logdnaaccount.ts | 16 +++++---- 3 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 readme.md diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..1645168 --- /dev/null +++ b/readme.md @@ -0,0 +1,68 @@ +# 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. + +> 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) diff --git a/ts/logdna.aggregator.ts b/ts/logdna.aggregator.ts index d230dde..bac444a 100644 --- a/ts/logdna.aggregator.ts +++ b/ts/logdna.aggregator.ts @@ -41,7 +41,7 @@ export class LogAggregator { private async sendAggregatedLogs(logCandidate: ILogCandidate) { this.logObjectMap.remove(logCandidate); // lets post the message to logdna - await plugins.smartrequest.postJson(`${this.baseUrl}${logCandidate.urlIdentifier}&now=${Date.now()}` , { + const response = await plugins.smartrequest.postJson(`${this.baseUrl}${logCandidate.urlIdentifier}&now=${Date.now()}` , { headers: { Authorization: this.createBasicAuth(), charset: 'UTF-8' @@ -50,5 +50,8 @@ export class LogAggregator { lines: logCandidate.logLines } }); + if(response.statusCode !== 200) { + console.log(response.body); + } } } diff --git a/ts/logdna.logdnaaccount.ts b/ts/logdna.logdnaaccount.ts index cb67979..86b601a 100644 --- a/ts/logdna.logdnaaccount.ts +++ b/ts/logdna.logdnaaccount.ts @@ -26,17 +26,20 @@ export class LogdnaAccount { const lm = logdnaMessageArg; const euc = encodeURIComponent; - // let construct the request uri - const requestUrlWithParams = `?hostname=${euc(lm.options.hostname)}&mac=${euc( - lm.options.mac - )}&ip=1${euc(lm.options.ip)}&tags=${euc( + 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, @@ -47,7 +50,6 @@ export class LogdnaAccount { }; this.logAggregator.addLog(requestUrlWithParams, logLine); - } /**