Commit 45f1cc23 authored by Eirik Alvær's avatar Eirik Alvær
Browse files

Adds support for fluentd logging.

parent 3181bc98
Pipeline #40487 passed with stage
in 26 seconds
{
"name": "@nsd/log-schema-node",
"version": "3.2.1",
"version": "3.5.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......@@ -823,6 +823,11 @@
"es5-ext": "~0.10.14"
}
},
"event-lite": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/event-lite/-/event-lite-0.1.2.tgz",
"integrity": "sha512-HnSYx1BsJ87/p6swwzv+2v6B4X+uxUteoDfRxsAb1S1BePzQqOLevVmkdA15GHJVd9A9Ok6wygUR18Hu0YeV9g=="
},
"express": {
"version": "4.16.4",
"resolved": "https://registry.npmjs.org/express/-/express-4.16.4.tgz",
......@@ -990,6 +995,14 @@
"integrity": "sha512-a1hQMktqW9Nmqr5aktAux3JMNqaucxGcjtjWnZLHX7yyPCmlSV3M54nGYbqT8K+0GhF3NBgmJCc3ma+WOgX8Jg==",
"dev": true
},
"fluent-logger": {
"version": "3.4.1",
"resolved": "https://registry.npmjs.org/fluent-logger/-/fluent-logger-3.4.1.tgz",
"integrity": "sha512-lERIhXAvhtCYeQq8K7sBDg/HY9GkiVRq5xY3oN+hcSINVKwqwBzG6LQOJK73EnV50qO59U7XEmRnn2hBzLWaHw==",
"requires": {
"msgpack-lite": "*"
}
},
"format-util": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/format-util/-/format-util-1.0.3.tgz",
......@@ -1122,6 +1135,11 @@
"safer-buffer": ">= 2.1.2 < 3"
}
},
"ieee754": {
"version": "1.1.13",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz",
"integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg=="
},
"ignore": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz",
......@@ -1197,6 +1215,11 @@
}
}
},
"int64-buffer": {
"version": "0.1.10",
"resolved": "https://registry.npmjs.org/int64-buffer/-/int64-buffer-0.1.10.tgz",
"integrity": "sha1-J3siiofZWtd30HwTgyAiQGpHNCM="
},
"ipaddr.js": {
"version": "1.8.0",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.8.0.tgz",
......@@ -1214,6 +1237,11 @@
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=",
"dev": true
},
"isarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
},
"isemail": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/isemail/-/isemail-3.2.0.tgz",
......@@ -1595,6 +1623,17 @@
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==",
"dev": true
},
"msgpack-lite": {
"version": "0.1.26",
"resolved": "https://registry.npmjs.org/msgpack-lite/-/msgpack-lite-0.1.26.tgz",
"integrity": "sha1-3TxQsm8FnyXn7e42REGDWOKprYk=",
"requires": {
"event-lite": "^0.1.1",
"ieee754": "^1.1.8",
"int64-buffer": "^0.1.9",
"isarray": "^1.0.0"
}
},
"mute-stream": {
"version": "0.0.7",
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz",
......
{
"name": "@nsd/log-schema-node",
"version": "3.5.0",
"version": "3.6.0",
"main": "lib/index.js",
"types": "lib/index",
"scripts": {
......@@ -17,6 +17,7 @@
"cookie": "0.4.0",
"dotenv": "6.2.0",
"express": "4.16.4",
"fluent-logger": "3.4.1",
"jsonschema": "1.2.4",
"jwt-decode": "2.2.0",
"lodash": "4.17.15"
......
import { LogSchema, schema } from "./index";
import Cookie = require("cookie");
import Express = require("express");
import FluentLogger = require("fluent-logger");
import Http = require("http");
import JsonSchema = require("jsonschema");
import JwtDecode = require("jwt-decode");
......@@ -20,6 +21,7 @@ type LogCallback = (loggedData: any) => void;
let logLevel: LevelName = "DEBUG";
let logCallback: LogCallback;
let useFluent = false;
export function setLogLevel(levelName: LevelName) {
logLevel = levelName;
......@@ -29,9 +31,19 @@ export function setLogCallback(cb: LogCallback) {
logCallback = cb;
}
function makeLogCallback(logData: any) {
export function enableFluent() {
FluentLogger.configure("v3", {
host: "fluent.private.nsd.no"
});
useFluent = true;
}
function dataLoggedEvent(data: any) {
if (logCallback) {
logCallback(logData);
logCallback(data);
}
if (useFluent) {
FluentLogger.emit("", data);
}
}
......@@ -198,7 +210,7 @@ function log(levelName: LogSchema["levelName"], input: LogInput) {
const data = getLogData(fullLogInput);
const str = stringify(data, Number.MAX_SAFE_INTEGER);
console.log(str);
makeLogCallback(data);
dataLoggedEvent(data);
if (isDev()) {
JsonSchema.validate(data, schema, { throwError: true });
}
......@@ -213,7 +225,7 @@ function log(levelName: LogSchema["levelName"], input: LogInput) {
});
const str = stringify(errData, Number.MAX_SAFE_INTEGER);
console.error(str);
makeLogCallback(errData);
dataLoggedEvent(errData);
}
}
......
......@@ -133,4 +133,9 @@ lab.experiment("log-schema-node", () => {
Logger.error({ message });
expect(logged.message).to.equal(message);
});
lab.test("useFluent", () => {
Logger.enableFluent();
Logger.error({ message: "Testing fluent"});
});
});
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment