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

Process all arguments debug.js style #134

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion debug.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

var util = require('util');

module.exports = debug

function debug (namespace) {
Expand All @@ -16,7 +18,8 @@ function debug (namespace) {
function disabled () {}
disabled.enabled = false
function enabled () {
return log.apply(logger, arguments)
let message = util.format.apply(util, arguments) // this is how debug.js formats argeuments
return log.apply(logger, [message])
}
enabled.enabled = true

Expand Down
19 changes: 19 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
var execSync = require('child_process').execSync
var tap = require('tap')
var through = require('through2')
const pinoDebug = require("../index");
const debug = require("debug");
var test = tap.test

const debugModules = [
Expand Down Expand Up @@ -342,3 +344,20 @@ test('does not invalidate strict mode', (t) => {
t.is(require('./fixtures/strict-mode'), true)
t.end()
})

test('Process all arguments debug.js style', (t) => {
var testOptions={"option1":"value1"};
process.env.DEBUG = 'ns1'
var pinoDebug = require('../')
var stream = through((line, _, cb) => {
var obj = JSON.parse(line)
var expectedMsg = "test { option1: 'value1' }";
t.is(obj.msg, expectedMsg)
t.is(obj.ns, 'ns1')
t.end()
})
pinoDebug(require('pino')({level: 'debug'}, stream))
var debug = require('debug')

debug('ns1')('test', testOptions)
})