Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Timber for Error objects #45

Merged
merged 3 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*v2.1.0*
> Internal: Serialize error objects

*v2.0.0*
> Internal: Remove unused Loggly and Bugsnag
> Internal: Remove unecessary patch
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@invisible/logger",
"version": "2.0.0",
"version": "2.1.0",
"description": "Invisible Logging Wrapper",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -31,7 +31,7 @@
"dependencies": {
"@invisible/changelog-update": "^1.1.0",
"moment": "^2.18.1",
"postinstall-prepare": "^1.0.1",
"serialize-error": "^2.1.0",
"timber": "^3.1.1",
"winston": "^2.4.0"
},
Expand Down
7 changes: 6 additions & 1 deletion transports/timber.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
'use strict'

const winston = require('winston')
const serializeError = require('serialize-error')
const timber = require('timber')

const assertLevel = require('./helpers/assertLevel')

const {
Expand All @@ -22,7 +24,10 @@ module.exports = new (winston.transports.Console)({
formatter: options => {
// When we log errors, options.message comes as blank and it causes errors
const message = options.message || options.meta.message || 'No message'
const formatted = timber.formatters.Winston({ ...options, message })
// Serialize eventual error objecs
// https://github.com/timberio/timber-node/issues/87
const sanitized = serializeError(options)
const formatted = timber.formatters.Winston({ ...sanitized, message })
return dropLineBreak(formatted)
},
})
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1714,10 +1714,6 @@ pluralize@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-7.0.0.tgz#298b89df8b93b0221dbf421ad2b1b1ea23fc6777"

postinstall-prepare@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/postinstall-prepare/-/postinstall-prepare-1.0.1.tgz#dac9b5d91b054389141b13c0192eb68a0aa002b5"

prelude-ls@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
Expand Down Expand Up @@ -1935,6 +1931,10 @@ semver@~5.0.1:
version "5.0.3"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.0.3.tgz#77466de589cd5d3c95f138aa78bc569a3cb5d27a"

serialize-error@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/serialize-error/-/serialize-error-2.1.0.tgz#50b679d5635cdf84667bdc8e59af4e5b81d5f60a"

set-blocking@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
Expand Down