pino-logflare
Advanced tools
Comparing version 0.3.12 to 0.4.0-56730c20
import { LogflareUserOptionsI } from "logflare-transport-core"; | ||
declare const createConsoleWriteStream: (options: LogflareUserOptionsI) => any; | ||
declare const createConsoleWriteStream: (options: LogflareUserOptionsI) => { | ||
write: (chunk: any) => void; | ||
}; | ||
export default createConsoleWriteStream; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var utils_1 = require("./utils"); | ||
var lodash_1 = __importDefault(require("lodash")); | ||
var stream_browserify_1 = __importDefault(require("stream-browserify")); | ||
var utils_2 = require("./utils"); | ||
var createConsoleWriteStream = function (options) { | ||
var writeStream = new stream_browserify_1.default.Writable({ | ||
objectMode: true, | ||
highWaterMark: 1, | ||
}); | ||
writeStream._write = function (chunk, encoding, callback) { | ||
var batch = Array.isArray(chunk) ? chunk : [chunk]; | ||
lodash_1.default(batch) | ||
.map(JSON.parse) | ||
.map(utils_1.toLogEntry) | ||
.map(function (logEntry) { | ||
return utils_2.addLogflareTransformDirectives(logEntry, options); | ||
}) | ||
.map(JSON.stringify) | ||
.forEach(function (x) { | ||
process.stdout.write(x + "\n"); | ||
}); | ||
callback(); | ||
return { | ||
write: function (chunk) { | ||
var batch = Array.isArray(chunk) ? chunk : [chunk]; | ||
batch | ||
.map(function (chunkItem) { return JSON.parse(chunkItem); }) | ||
.map(utils_1.toLogEntry) | ||
.map(function (logEntry) { | ||
return utils_2.addLogflareTransformDirectives(logEntry, options); | ||
}) | ||
.map(function (chunkItem) { return JSON.stringify(chunkItem); }) | ||
.forEach(function (x) { | ||
process.stdout.write(x + "\n"); | ||
}); | ||
}, | ||
}; | ||
return writeStream; | ||
}; | ||
exports.default = createConsoleWriteStream; | ||
//# sourceMappingURL=consoleStream.js.map |
@@ -17,9 +17,13 @@ "use strict"; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (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); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var logflare_transport_core_1 = require("logflare-transport-core"); | ||
var streams = __importStar(require("./streams")); | ||
var stream_1 = __importDefault(require("stream")); | ||
var pumpify = require("pumpify"); | ||
@@ -31,6 +35,27 @@ function createWriteStream(options) { | ||
var batchStream = streams.batchStream(size); | ||
var writeStream = new logflare_transport_core_1.LogflareHttpClient(options).insertStream(); | ||
var writeStream = createClientStream(new logflare_transport_core_1.LogflareHttpClient(options)); | ||
return pumpify(parseJsonStream, toLogEntryStream, batchStream, writeStream); | ||
} | ||
/** | ||
* create write stream around the http client | ||
* Logic moved from logflare transport core js | ||
* - https://github.com/atdrago/logflare-transport-core-js/commit/4aad9030aca1c9ea6c241d4e6ebfc0da76eaea8f | ||
* - https://github.com/Logflare/pino-logflare/issues/41 | ||
*/ | ||
function createClientStream(client) { | ||
var writeStream = new stream_1.default.Writable({ | ||
objectMode: true, | ||
highWaterMark: 1, | ||
}); | ||
writeStream._write = function (chunk, _encoding, callback) { | ||
client | ||
.addLogEvent(chunk) | ||
.then(function () { | ||
callback(null); | ||
}) | ||
.catch(callback); | ||
}; | ||
return writeStream; | ||
} | ||
exports.default = createWriteStream; | ||
//# sourceMappingURL=httpStream.js.map |
@@ -5,8 +5,10 @@ import createHttpWriteStream from "./httpStream"; | ||
import { LogflareUserOptionsI } from "logflare-transport-core"; | ||
declare const createPinoBrowserSend: (options: LogflareUserOptionsI) => (level: Level, logEvent: LogEvent) => void; | ||
declare const createPinoBrowserSend: (options: LogflareUserOptionsI) => (level: Level | number, logEvent: LogEvent) => void; | ||
declare const logflarePinoVercel: (options: LogflareUserOptionsI) => { | ||
stream: any; | ||
send: (level: Level, logEvent: LogEvent) => void; | ||
stream: { | ||
write: (chunk: any) => void; | ||
}; | ||
send: (level: Level | number, logEvent: LogEvent) => void; | ||
}; | ||
declare const createWriteStream: typeof createHttpWriteStream; | ||
export { createWriteStream, logflarePinoVercel, createPinoBrowserSend, createConsoleWriteStream, createHttpWriteStream, }; |
@@ -22,3 +22,3 @@ import { LogflareUserOptionsI } from "logflare-transport-core"; | ||
metadata: { | ||
url: string; | ||
url: string | undefined; | ||
level: string; | ||
@@ -25,0 +25,0 @@ browser: boolean; |
@@ -13,9 +13,45 @@ "use strict"; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addLogflareTransformDirectives = exports.formatPinoBrowserLogEvent = exports.toLogEntry = void 0; | ||
var lodash_1 = __importDefault(require("lodash")); | ||
var lodash_2 = require("lodash"); | ||
function isObject(value) { | ||
return typeof value === "object" && value !== null; | ||
} | ||
function isString(value) { | ||
return typeof value === "string"; | ||
} | ||
/** | ||
* Takes an object and removes all falsy properties | ||
*/ | ||
function removeFalsy(input) { | ||
if (input === null || input === undefined) { | ||
return input; | ||
} | ||
if (typeof input === "object" && input !== null) { | ||
var key = void 0; | ||
for (key in input) { | ||
var value = input[key]; | ||
if (!value) { | ||
delete input[key]; | ||
} | ||
else if (typeof value === "object") { | ||
removeFalsy(value); | ||
if (!Object.keys(value).length) { | ||
delete input[key]; | ||
} | ||
} | ||
} | ||
} | ||
return input; | ||
} | ||
function levelToStatus(level) { | ||
@@ -40,7 +76,7 @@ if (level === 10 || level === 20) { | ||
var timestamp = ts; | ||
var objMessages = lodash_1.default.filter(messages, lodash_2.isObject); | ||
var strMessages = lodash_1.default.filter(messages, lodash_2.isString); | ||
var objMessages = messages.filter(isObject); | ||
var strMessages = messages.filter(isString); | ||
var logEntry = strMessages.join(" "); | ||
var defaultMetadata = { | ||
url: window.document.URL, | ||
url: getDocumentUrl(), | ||
level: level, | ||
@@ -50,3 +86,3 @@ browser: true, | ||
var bindingsAndMessages = bindings.concat(objMessages); | ||
var metadata = lodash_1.default.reduce(bindingsAndMessages, function (acc, el) { | ||
var metadata = bindingsAndMessages.reduce(function (acc, el) { | ||
return Object.assign(acc, el); | ||
@@ -61,2 +97,7 @@ }, defaultMetadata); | ||
exports.formatPinoBrowserLogEvent = formatPinoBrowserLogEvent; | ||
function getDocumentUrl() { | ||
if (typeof window !== 'undefined' && typeof window.document !== 'undefined') { | ||
return window.document.URL; | ||
} | ||
} | ||
function addLogflareTransformDirectives(item, options) { | ||
@@ -81,13 +122,4 @@ var _a; | ||
var timestamp = item.time || new Date().getTime(); | ||
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; }); | ||
var _time = item.time, _level = item.level, _msg = item.msg, _hostname = item.hostname, _service = item.service, _pid = item.pid, _stack = item.stack, _type = item.type, cleanedItem = __rest(item, ["time", "level", "msg", "hostname", "service", "pid", "stack", "type"]); | ||
var context = removeFalsy({ host: host, service: service, pid: pid, stack: stack, type: type }); | ||
return { | ||
@@ -94,0 +126,0 @@ metadata: __assign(__assign({}, cleanedItem), { context: context, level: status }), |
{ | ||
"name": "pino-logflare", | ||
"version": "0.3.12", | ||
"version": "0.4.0-56730c20", | ||
"description": "A transport for Pino that sends messages to Logflare", | ||
@@ -11,3 +11,4 @@ "homepage": "https://github.com/logflare/pino-logflare", | ||
"test": "jest", | ||
"test.watch": "jest --watch" | ||
"test.watch": "jest --watch", | ||
"vsn": "node -e \"console.log(require('./package.json').version);\"" | ||
}, | ||
@@ -43,3 +44,2 @@ "bin": { | ||
"@babel/preset-typescript": "^7.10.1", | ||
"@types/lodash": "^4.14.157", | ||
"@types/node": "^14.0.14", | ||
@@ -62,12 +62,9 @@ "@types/pumpify": "^1.4.1", | ||
"dependencies": { | ||
"axios": "^0.21.1", | ||
"batch2": "^1.0.6", | ||
"commander": "^5.0.0", | ||
"fast-json-parse": "^1.0.3", | ||
"lodash": "^4.17.15", | ||
"logflare-transport-core": "^0.2.5", | ||
"logflare-transport-core": "^0.3.0", | ||
"pino": "^6.3.2", | ||
"pumpify": "^2.0.1", | ||
"split2": "^3.1.1", | ||
"stream-browserify": "^3.0.0", | ||
"through2": "^3.0.1" | ||
@@ -87,2 +84,2 @@ }, | ||
} | ||
} | ||
} |
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
30063
8
18
420
+ Addedlogflare-transport-core@0.3.3(transitive)
- Removedaxios@^0.21.1
- Removedlodash@^4.17.15
- Removedstream-browserify@^3.0.0
- Removed@types/lodash@4.17.14(transitive)
- Removedaxios@0.21.4(transitive)
- Removedbig-integer@1.6.52(transitive)
- Removedbignumber.js@9.1.2(transitive)
- Removeddecimal.js@10.4.3(transitive)
- Removedfollow-redirects@1.15.9(transitive)
- Removedlodash@4.17.21(transitive)
- Removedlogflare-transport-core@0.2.5(transitive)
- Removedstream-browserify@3.0.0(transitive)