Skip to content

Commit

Permalink
Process all arguments debug.js style (#134)
Browse files Browse the repository at this point in the history
* Process all arguments debug.js style

* add test for Process all arguments debug.js style

* removed comment line

---------

Co-authored-by: Andrey Kan <andrey.kan@dowjones.com>
  • Loading branch information
tevch and kana-dowjones authored Oct 15, 2024
1 parent 6a7268e commit c917562
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
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)
})

0 comments on commit c917562

Please sign in to comment.