Skip to content

Latest commit

 

History

History
49 lines (38 loc) · 1.15 KB

faq.md

File metadata and controls

49 lines (38 loc) · 1.15 KB

FAQ

Disabling one method on an instance at runtime

// To disable a given method, just pass a no-op to it
logger.warn = function() {}

// To reenable, attach it again to the prototype
logger.warn = logdown.prototype.warn

Align prefixes

If you want to align the output of each instance, like the example below:

[ipsum]   lorem
[sitamet] lorem
[dolor]   lorem

Use the the following function

function alignPrefixes(Logdown) {
  var longest = logdown._instances.sort(function (a, b) {
    return b.opts.prefix.length - a.opts.prefix.length
  })[0]

  logdown._instances
    .forEach(function (instance) {
      var padding = new Array(Math.max(longest.opts.prefix.length - instance.opts.prefix.length + 1, 0)).join(' ')
      instance.opts.prefix = instance.opts.prefix + padding
    })
}

Enable/disable instance at runtime

Set the instance state isEnabled to false to prevent it to log.

logger.state.isEnabled = false

If you don't have direct access to the instance, use logdown.getInstanceByPrefix to get an instance reference.

const logger = logdown.getInstanceByPrefix('foo')
logger.state.isEnabled = false