How to use the debug.formatArgs function in debug

To help you get started, we’ve selected a few debug examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thumbsup / thumbsup / test / log.js View on Github external
const debug = require('debug')
const util = require('util')

debug.recorded = []

// enable all logs while running the tests
debug.enable('thumbsup:*')

// don't format the logs to avoid any extra ANSI codes
debug.formatArgs = function (args) {
}

// capture the logs instead of displaying them
debug.log = function () {
  const message = util.format.apply(null, arguments)
  debug.recorded.push(`${this.namespace} ${message}`)
}

debug.reset = function () {
  debug.recorded = []
}

debug.assertContains = function (expected) {
  const matches = debug.recorded.filter(message => {
    return message.includes(expected)
  })
github silklabs / silk / log / index.js View on Github external
}
  } else {
    try {
      alog = require('./build/Release/silk-alog.node');
    } catch (err) {
      // Fall back to using console.*
    }
  }

  // If DEBUG environment variable is not set, select a sensible default.
  if (!process.env.DEBUG) {
    debug.enable('silk-*,-silk-*:debug,-silk-*:verbose');
  }
}

debug.formatArgs = function(args) {
  const diff = debug.humanize(this.diff);

  // Mimic console.* functions by treating additional arguments as
  // printf-style arguments.
  let msg = util.format.apply(util, args);
  args.length = 1;

  const format = `(+${diff}) ${msg}`;
  if (this.useColors) {
    msg = `\u001b[3${this.color}m${format}\u001b[0m`;
  } else {
    msg = format;
  }

  args[0] = msg;
};
github silklabs / silk / log / device.js View on Github external
* This is the device version of ./index.js
 *
 * TODO: Unify with index.js
 */

'use strict';

const debug = require('debug');
const os = require('os');
const util = require('util');

const isAndroid = os.platform() === 'android';

const alog = isAndroid ? require('silk-alog') : undefined;

debug.formatArgs = function() {
  const args = Array.prototype.slice.call(arguments);
  const diff = debug.humanize(this.diff);

  // Mimic console.* functions by treating additional arguments as
  // printf-style arguments.
  let msg = util.format.apply(this, args);

  const format = `(+${diff}) ${msg}`;
  if (this.useColors) {
    msg = `\u001b[3${this.color}m${format}\u001b[0m`;
  } else {
    msg = format;
  }

  return [ msg ];
};
github thumbsup / thumbsup / bin / log.js View on Github external
function overrideDebugFormat () {
  debug.formatArgs = function (args) {
    const prefix = new Date().toISOString() + ' ' + this.namespace + ' '
    args[0] = prefix + args[0].split('\n').join('\n' + prefix)
  }
}
github liquality / chainabstractionlayer / packages / debug / lib / index.js View on Github external
import debug from 'debug'
import { version } from '../package.json'

const FORMAT_ARGS_BACKUP_KEY = '__formatArgs'

if (!debug[FORMAT_ARGS_BACKUP_KEY]) {
  debug[FORMAT_ARGS_BACKUP_KEY] = debug.formatArgs
}

debug.formatArgs = function (args) {
  const log = {
    args: args.concat([]),
    namespace: this.namespace,
    diff: debug.humanize(this.diff),
    time: new Date().toISOString()
  }

  try {
    throw Error('')
  } catch (error) {
    log.stack = error.stack.split('\n')

    log.stack.shift()
github liquality / chainabstractionlayer / packages / debug / lib / index.js View on Github external
import debug from 'debug'
import { version } from '../package.json'

const FORMAT_ARGS_BACKUP_KEY = '__formatArgs'

if (!debug[FORMAT_ARGS_BACKUP_KEY]) {
  debug[FORMAT_ARGS_BACKUP_KEY] = debug.formatArgs
}

debug.formatArgs = function (args) {
  const log = {
    args: args.concat([]),
    namespace: this.namespace,
    diff: debug.humanize(this.diff),
    time: new Date().toISOString()
  }

  try {
    throw Error('')
  } catch (error) {
    log.stack = error.stack.split('\n')

    log.stack.shift()
    log.stack.shift()
    log.stack.shift()
github derwish-pro / singlehub / modules / debug / configure.js View on Github external
/**
 * Created by Derwish (derwish.pro@gmail.com) on 04.07.2016.
 * License: http://www.gnu.org/licenses/gpl-3.0.txt
 */
//set DEBUG environment variable if nod defined
if (!process.env.DEBUG)
    process.env.DEBUG = "server:*,gateway:*,-gateway:mys:log*,nodes:*,container:*";
process.env.DEBUG_DIFF = 0;
//set debug format (added time stamp)
var deb = require('debug');
deb.formatArgs = function formatArgs() {
    var args = arguments;
    var useColors = this.useColors;
    var name = this.namespace;
    var c = this.color;
    args[0] = (new Date()).toLocaleString() +
        '  \u001b[3' + c + 'm' + name + ' '
        + '\u001b[0m'
        + args[0] + '\u001b[3' + c + 'm'
        + ' +' + deb.humanize(this.diff) + '\u001b[0m';
    return args;
};
//# sourceMappingURL=configure.js.map
github brave / vault / src / sdebug.js View on Github external
sdata += '[' + (name.indexOf('@') !== -1 ? name : sdname(name)) + '@' + options.pen
      keys.forEach(function (pname) {
        if ((typeof value[pname] !== 'string') &&
            (typeof value[pname] !== 'number') &&
            (typeof value[pname] !== 'boolean')) { return }

        sdata += ' ' + sdname(pname) + '="' + sdvalue(value[pname]) + '"'
      })
      sdata += ']'
    })

    return sdata
  }

  debug.formatArgs = function () {
    var args = [ '' ]
    var name = this.namespace
    var prefix = initial

    if (this.useColors) { name = '\u001b[3' + this.color + ';1m' + name + '\u001b[0m' }

    underscore.rest(arguments).forEach(function (arg) {
      var truths, value
      var keys = underscore.keys(arg)

      if (keys[0] === 'sdebug') {
        prefix = sdelement(arg.sdebug)
      } else if (keys[0] !== 'tags') {
        args.push(arg)
      } else {
        value = arg.tags