Skip to content

Commit

Permalink
mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmarkclements committed Jun 11, 2018
1 parent d29fa7e commit 80cd6d0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
17 changes: 14 additions & 3 deletions lib/levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,28 @@ function isLevelEnabled (logLevel) {
return logLevelVal && (logLevelVal >= this[levelValSym])
}

function mappings () {
const labels = Object.assign(
Object.create(Object.prototype, {Infinity: {value: 'silent'}}),
nums
)
const values = Object.assign(
Object.create(Object.prototype, {silent: {value: Infinity}}),
levels
)
return { labels, values }
}

module.exports = {
isStandardLevelVal,
isStandardLevel,
lsCache,
levels,
nums,
levelMethods,
getLevelVal,
setLevelVal,
getLevel,
setLevel,
addLevel,
isLevelEnabled
isLevelEnabled,
mappings
}
13 changes: 0 additions & 13 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,6 @@ function asMetaWrapper (pretty, dest) {
}
}

function defineLevelsProperty (onObject, levels) {
Object.defineProperty(onObject, 'levels', {
value: {
values: copy({}, levels.levels),
labels: copy({}, levels.nums)
},
enumerable: true
})
Object.defineProperty(onObject.levels.values, 'silent', {value: Infinity})
Object.defineProperty(onObject.levels.labels, Infinity, {value: 'silent'})
}

function countInterp (s, i) {
var n = 0
var pos = 0
Expand Down Expand Up @@ -212,7 +200,6 @@ function asChindings (instance, bindings) {

module.exports = {
copy,
defineLevelsProperty,
noop,
getPrettyStream,
asChindings,
Expand Down
11 changes: 4 additions & 7 deletions pino.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ const {
isStandardLevelVal,
isStandardLevel,
lsCache,
levels,
nums,
levelMethods,
setLevelVal,
getLevelVal,
getLevel,
setLevel,
addLevel,
mappings,
isLevelEnabled
} = require('./lib/levels')
const {
copy,
defineLevelsProperty,
noop,
getPrettyStream,
asChindings,
Expand Down Expand Up @@ -91,11 +89,9 @@ Object.assign(prototype, levelMethods)

module.exports = pino

defineLevelsProperty(pino, {levels, nums})

pino.extreme = (dest = process.stdout.fd) => new SonicBoom(dest, 4096)
pino.destination = (dest = process.stdout.fd) => new SonicBoom(dest)

pino.levels = mappings()
pino.stdSerializers = Object.assign({}, serializers)
pino.stdTimeFunctions = Object.assign({}, timeFmt)

Expand All @@ -106,7 +102,6 @@ function pino (opts, stream) {
const { base, name, serializers, chindings, level, levelVal } = state

Object.setPrototypeOf(core, prototype)
defineLevelsProperty(core, {levels, nums})
events(core)
configure(core, {serializers, chindings, level, levelVal})

Expand Down Expand Up @@ -224,7 +219,9 @@ function create (opts, stream) {
const time = (timestamp && timestamp instanceof Function)
? timestamp
: (timestamp ? epochTime : nullTime)
const levels = mappings()
const core = {
levels,
time,
stream,
stringify,
Expand Down

0 comments on commit 80cd6d0

Please sign in to comment.