Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
373b02adb4 | |||
11b08cc0a3 | |||
a586069305 | |||
8a8c4efcbb | |||
dbb5843f52 | |||
d021e934b9 |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/logdna",
|
"name": "@mojoio/logdna",
|
||||||
"version": "1.0.18",
|
"version": "1.0.21",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mojoio/logdna",
|
"name": "@mojoio/logdna",
|
||||||
"version": "1.0.18",
|
"version": "1.0.21",
|
||||||
"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",
|
||||||
|
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)
|
@ -41,7 +41,7 @@ export class LogAggregator {
|
|||||||
private async sendAggregatedLogs(logCandidate: ILogCandidate) {
|
private async sendAggregatedLogs(logCandidate: ILogCandidate) {
|
||||||
this.logObjectMap.remove(logCandidate);
|
this.logObjectMap.remove(logCandidate);
|
||||||
// lets post the message to logdna
|
// 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: {
|
headers: {
|
||||||
Authorization: this.createBasicAuth(),
|
Authorization: this.createBasicAuth(),
|
||||||
charset: 'UTF-8'
|
charset: 'UTF-8'
|
||||||
@ -50,5 +50,8 @@ export class LogAggregator {
|
|||||||
lines: logCandidate.logLines
|
lines: logCandidate.logLines
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if(response.statusCode !== 200) {
|
||||||
|
console.log(response.body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,16 +26,19 @@ export class LogdnaAccount {
|
|||||||
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 = `?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)}&tags=${euc(
|
const uriTags = euc(
|
||||||
(() => {
|
(() => {
|
||||||
return lm.options.tags.reduce((reduced, newItem) => {
|
return lm.options.tags.reduce((reduced, newItem) => {
|
||||||
return `${reduced},${newItem}`;
|
return `${reduced},${newItem}`;
|
||||||
});
|
});
|
||||||
})()
|
})()
|
||||||
)}`;
|
);
|
||||||
|
|
||||||
|
// let construct the request uri
|
||||||
|
const requestUrlWithParams = `?hostname=${uriHostname}&mac=${uriMac}&ip=1${uriIp}&tags=${uriTags}`;
|
||||||
|
|
||||||
const logLine = {
|
const logLine = {
|
||||||
timestamp: lm.options.timestamp,
|
timestamp: lm.options.timestamp,
|
||||||
@ -47,7 +50,6 @@ export class LogdnaAccount {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this.logAggregator.addLog(requestUrlWithParams, logLine);
|
this.logAggregator.addLog(requestUrlWithParams, logLine);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user