pino-logflare
Advanced tools
Comparing version 0.3.6 to 0.3.7-4f99496c
@@ -9,2 +9,3 @@ "use strict"; | ||
var stream_1 = __importDefault(require("stream")); | ||
var utils_2 = require("./utils"); | ||
var createConsoleWriteStream = function (options) { | ||
@@ -20,2 +21,3 @@ var writeStream = new stream_1.default.Writable({ | ||
.map(utils_1.toLogEntry) | ||
.map(function (logEntry) { return utils_2.addLogflareTransformDirectives(logEntry, options); }) | ||
.map(JSON.stringify) | ||
@@ -22,0 +24,0 @@ .forEach(function (x) { |
@@ -17,3 +17,3 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
@@ -29,3 +29,3 @@ return result; | ||
var parseJsonStream = streams.parseJsonStream(); | ||
var toLogEntryStream = streams.toLogEntryStream(); | ||
var toLogEntryStream = streams.toLogEntryStream(options); | ||
var batchStream = streams.batchStream(size); | ||
@@ -32,0 +32,0 @@ var writeStream = new logflare_transport_core_1.LogflareHttpClient(options).insertStream(); |
@@ -6,8 +6,8 @@ /// <reference types="node" /> | ||
import { LogflareUserOptionsI } from "logflare-transport-core"; | ||
declare const createPinoBrowserSend: (options: LogflareUserOptionsI) => (level: number, logEvent: pinoBrowserLogEventI) => void; | ||
declare const createPinoBrowserSend: (options: LogflareUserOptionsI) => (level: string, logEvent: pinoBrowserLogEventI) => void; | ||
declare const logflarePinoVercel: (options: LogflareUserOptionsI) => { | ||
stream: import("stream").Writable; | ||
send: (level: number, logEvent: pinoBrowserLogEventI) => void; | ||
send: (level: string, logEvent: pinoBrowserLogEventI) => void; | ||
}; | ||
declare const createWriteStream: typeof createHttpWriteStream; | ||
export { createWriteStream, logflarePinoVercel, createPinoBrowserSend, createConsoleWriteStream, createHttpWriteStream }; |
@@ -33,3 +33,4 @@ "use strict"; | ||
var logflareLogEvent = utils_1.formatPinoBrowserLogEvent(logEvent); | ||
client.postLogEvents([logflareLogEvent]); | ||
var maybeWithTransforms = utils_1.addLogflareTransformDirectives(logflareLogEvent, options); | ||
client.postLogEvents([maybeWithTransforms]); | ||
}; | ||
@@ -36,0 +37,0 @@ }; |
/// <reference types="node" /> | ||
import { LogflareUserOptionsI } from "logflare-transport-core"; | ||
declare function batchStream(size: number): any; | ||
declare function parseJsonStream(): import("stream").Transform; | ||
declare function toLogEntryStream(): import("stream").Transform; | ||
declare function toLogEntryStream(options: LogflareUserOptionsI): import("stream").Transform; | ||
export { batchStream, parseJsonStream, toLogEntryStream, }; |
@@ -25,6 +25,7 @@ "use strict"; | ||
exports.parseJsonStream = parseJsonStream; | ||
function toLogEntryStream() { | ||
function toLogEntryStream(options) { | ||
return through2_1.default.obj(function (chunk, enc, cb) { | ||
var entry = utils_1.toLogEntry(chunk); | ||
cb(null, entry); | ||
var maybeWithTransforms = utils_1.addLogflareTransformDirectives(entry, options); | ||
cb(null, maybeWithTransforms); | ||
}); | ||
@@ -31,0 +32,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import _ from "lodash"; | ||
import { LogflareUserOptionsI } from "logflare-transport-core"; | ||
interface pinoBrowserLogEventI { | ||
@@ -20,10 +20,4 @@ ts: number; | ||
}; | ||
declare function toLogEntry(item: Record<string, any>): { | ||
metadata: { | ||
context: _.Dictionary<any>; | ||
level: string; | ||
}; | ||
message: any; | ||
timestamp: any; | ||
}; | ||
export { toLogEntry, formatPinoBrowserLogEvent, pinoBrowserLogEventI }; | ||
declare function addLogflareTransformDirectives(item: Record<string, any>, options: LogflareUserOptionsI): Record<string, any>; | ||
declare function toLogEntry(item: Record<string, any>): Record<string, any>; | ||
export { toLogEntry, formatPinoBrowserLogEvent, pinoBrowserLogEventI, addLogflareTransformDirectives, }; |
@@ -17,4 +17,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.formatPinoBrowserLogEvent = exports.toLogEntry = void 0; | ||
exports.addLogflareTransformDirectives = exports.formatPinoBrowserLogEvent = exports.toLogEntry = void 0; | ||
var lodash_1 = __importDefault(require("lodash")); | ||
var lodash_2 = require("lodash"); | ||
function levelToStatus(level) { | ||
@@ -39,9 +40,12 @@ if (level === 10 || level === 20) { | ||
var timestamp = ts; | ||
var logEntry = messages.join(" "); | ||
var objMessages = lodash_1.default.filter(messages, lodash_2.isObject); | ||
var strMessages = lodash_1.default.filter(messages, lodash_2.isString); | ||
var logEntry = strMessages.join(" "); | ||
var defaultMetadata = { | ||
url: window.document.URL, | ||
level: level, | ||
browser: true | ||
browser: true, | ||
}; | ||
var metadata = lodash_1.default.reduce(bindings, function (acc, el) { | ||
var bindingsAndMessages = bindings.concat(objMessages); | ||
var metadata = lodash_1.default.reduce(bindingsAndMessages, function (acc, el) { | ||
return Object.assign(acc, el); | ||
@@ -56,2 +60,12 @@ }, defaultMetadata); | ||
exports.formatPinoBrowserLogEvent = formatPinoBrowserLogEvent; | ||
function addLogflareTransformDirectives(item, options) { | ||
var _a; | ||
if ((_a = options === null || options === void 0 ? void 0 : options.transforms) === null || _a === void 0 ? void 0 : _a.numbersToFloats) { | ||
return __assign(__assign({}, item), { "@logflareTransformDirectives": { numbersToFloats: true } }); | ||
} | ||
else { | ||
return item; | ||
} | ||
} | ||
exports.addLogflareTransformDirectives = addLogflareTransformDirectives; | ||
function toLogEntry(item) { | ||
@@ -66,3 +80,12 @@ var status = levelToStatus(item.level); | ||
var timestamp = item.time || new Date().getTime(); | ||
var cleanedItem = lodash_1.default.omit(item, ["time", "level", "msg", "hostname", "service", "pid", "stack", "type"]); | ||
var cleanedItem = lodash_1.default.omit(item, [ | ||
"time", | ||
"level", | ||
"msg", | ||
"hostname", | ||
"service", | ||
"pid", | ||
"stack", | ||
"type", | ||
]); | ||
var context = lodash_1.default.pickBy({ host: host, service: service, pid: pid, stack: stack, type: type }, function (x) { return x; }); | ||
@@ -69,0 +92,0 @@ return { |
{ | ||
"name": "pino-logflare", | ||
"version": "0.3.6", | ||
"version": "0.3.7-4f99496c", | ||
"description": "A transport for Pino that sends messages to Logflare", | ||
@@ -47,7 +47,7 @@ "homepage": "https://github.com/logflare/pino-logflare", | ||
"@types/through2": "^2.0.36", | ||
"@typescript-eslint/eslint-plugin": "^3.4.0", | ||
"@typescript-eslint/parser": "^3.4.0", | ||
"@typescript-eslint/eslint-plugin": "^4.16.0", | ||
"@typescript-eslint/parser": "^4.16.0", | ||
"eslint": "^7.3.1", | ||
"eslint-config-airbnb-base": "^14.2.0", | ||
"eslint-config-standard": "^14.1.1", | ||
"eslint-config-standard": "^16.0.0", | ||
"eslint-plugin-import": "^2.22.0", | ||
@@ -58,3 +58,3 @@ "jest": "^26.1.0", | ||
"sinon": "^9.0.1", | ||
"typescript": "^3.9.5" | ||
"typescript": "^4.2.0" | ||
}, | ||
@@ -86,2 +86,2 @@ "dependencies": { | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
26962
361