All Projects → caiogondim → Logdown.js

caiogondim / Logdown.js

Licence: mit
✏️ Debug utility with markdown support that runs on browser and server

Programming Languages

javascript
184084 projects - #8 most used programming language
js
455 projects

Projects that are alternatives of or similar to Logdown.js

React Native Logs
Performance-aware simple logger for React-Native with namespaces, custom levels and custom transports (colored console, file writing, etc.)
Stars: ✭ 84 (-91.71%)
Mutual labels:  logging, debug
Investigator
Interactive and asynchronous logging tool for Node.js. An easier way to log & debug complex requests directly from the command line (experimental).
Stars: ✭ 155 (-84.7%)
Mutual labels:  logging, debug
Debug
A tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers
Stars: ✭ 9,912 (+878.48%)
Mutual labels:  logging, debug
Ios Sdk
AppSpector is a debugging service for mobile apps
Stars: ✭ 56 (-94.47%)
Mutual labels:  logging, debug
Cocoadebug
iOS Debugging Tool 🚀
Stars: ✭ 3,769 (+272.06%)
Mutual labels:  logging, debug
Vlog
An in-display logging library for Android 📲
Stars: ✭ 86 (-91.51%)
Mutual labels:  logging, debug
Ololog
A better console.log for the log-driven debugging junkies
Stars: ✭ 141 (-86.08%)
Mutual labels:  logging, debug
Diary
📑 Zero-dependency, fast logging library for both Node and Browser.
Stars: ✭ 79 (-92.2%)
Mutual labels:  logging, debug
Pysnooper
Never use print for debugging again
Stars: ✭ 14,815 (+1362.49%)
Mutual labels:  logging, debug
Logcat
Android 日志打印框架,在手机上可以直接看到 Logcat 日志啦
Stars: ✭ 189 (-81.34%)
Mutual labels:  logging, debug
Android Remote Debugger
A library for remote logging, database debugging, shared preferences and network requests
Stars: ✭ 132 (-86.97%)
Mutual labels:  logging, debug
Cabin
🌲 Cabin is the best JavaScript and Node.js logging service and logging npm package
Stars: ✭ 622 (-38.6%)
Mutual labels:  logging, debug
Acho
The Hackable Log
Stars: ✭ 189 (-81.34%)
Mutual labels:  logging, debug
Xcglogger
A debug log framework for use in Swift projects. Allows you to log details to the console (and optionally a file), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.
Stars: ✭ 3,710 (+266.24%)
Mutual labels:  logging, debug
Fliplog
fluent logging with verbose insight, colors, tables, emoji, filtering, spinners, progress bars, timestamps, capturing, stack traces, tracking, presets, & more...
Stars: ✭ 41 (-95.95%)
Mutual labels:  logging, debug
Dotlog
Simple and easy go log framework
Stars: ✭ 30 (-97.04%)
Mutual labels:  logging
Logzero
Robust and effective logging for Python 2 and 3.
Stars: ✭ 977 (-3.55%)
Mutual labels:  logging
Lme
An npm package to simply and beautifully log to console.
Stars: ✭ 29 (-97.14%)
Mutual labels:  logging
Nim Morelogging
Logging library for Nim
Stars: ✭ 29 (-97.14%)
Mutual labels:  logging
Tron
R package for easy logging
Stars: ✭ 38 (-96.25%)
Mutual labels:  logging

logdown.js

Travis CI Lib Size Codecov npm

logdown is a debug utility for the browser and the server with Markdown support, providing a single interface and a similar behavior between the browser and the server.

It doesn't have any dependencies for the browser version and it's only 2K gzipped.

You can see it in action in the example page or in the preview below.

Installation

$ npm install --save logdown

Preview

Out-of-the box colors work well on both light and dark themes.

Browser DevTools dark

Browser DevTools light

Node

Usage

logdown exports a function. For the simplest use case, pass the name of your module and it will return a decorated console.

const logdown = require('logdown')
const logger = logdown('foo')

Or in a more idiomatic way:

const logger = require('logdown')('foo')

Just like debug.js and node core's debuglog, the enviroment variable NODE_DEBUG is used to decide which module will print debug information.

$ NODE_DEBUG=foo node example/node.js

The corresponding command for browsers is:

window.localStorage.debug = 'foo'

Multiple comma-separated logger names and wildcards can be specified as well.

With the isEnabled state a specific logger instance can always be enabled, independent of the NODE_DEBUG setting:

const logger = require('logdown')('foo')
logger.state.isEnabled = true
logger.log('I will always log.')

Logging

After creating your object, you can use the regular log, warn, info and error methods as we have on console, but now with Markdown support. If a method is not provided by logdown, it will just delegate to the original console object or opts.logger if passed.

logger.log('lorem *ipsum*')
logger.info('dolor _sit_ amet')
logger.warn('consectetur `adipiscing` elit')

As the native APIs, multiple arguments are supported.

logger.log('lorem', '*ipsum*')
logger.info('dolor _sit_', 'amet')
logger.warn('consectetur', '`adipiscing` elit')

Options

The following options can be used for configuration.

prefix

  • Type: String
const logger = logdown('foo')
logger.log('Lorem ipsum')
var fooBarLogger = logdown('foo:bar')
fooBarLogger.log('Lorem ipsum')

var fooQuzLogger = logdown('foo:quz')
fooQuzLogger.log('Lorem Ipsum')

markdown

  • Type: Boolean
  • Default: true

If setted to false, markdown will not be parsed.

var logger = logdown({ markdown: false })
logger.log('Lorem *ipsum*') // Will not parse the markdown

For Markdown, the following mark-up is supported:

// Bold with "*"" between words
logger.log('lorem *ipsum*')

// Italic with "_" between words
logger.log('lorem _ipsum_')

// Code with "`" (backtick) between words
logger.log('lorem `ipsum`')

prefixColor

  • type: String
  • default: next value after last used on the logdown.prefixColors array.

Hex value for a custom color.

const logger1 = logdown('foo', { prefixColor: '#FF0000' }) // Red prefix
const logger2 = logdown('bar', { prefixColor: '#00FF00' }) // Green prefix
const logger3 = logdown('quz', { prefixColor: '#0000FF' }) // Blue prefix

logger

  • type: 'Object'
  • default: console

Custom logger. On Node it's possible to instantiate a new console setting it's output to a different stream other than stdout and stderr.

const output = fs.createWriteStream('./stdout.log');
const errorOutput = fs.createWriteStream('./stderr.log');
const fileLogger =  new console.Console(output, errorOutput)

const logger = logdown('foo', {
  logger: fileLogger
})

plaintext (Node.js only)

  • type: 'Boolean'
  • default: false

This will enable plaintext logging, that means, all objects will be stringified and the logging function will use only one argument (i.e. console.log('[my project] my message') instead of console.log('[my project]', 'my message').).

const logger = logdown('foo', { plaintext: 'true' })

State

isEnabled

  • type: 'Boolean'
  • default: default value is derived from localStorage.debug on browser and from env var NODE_DEBUG on node.

Used to enable/disable a given instance at runtime.

// Prevents `logger` to output debug info
logger.state.isEnabled = false

Enabling/disabling instances

logdown is compatible with Node.js util.debuglog and debug.js as it uses the NODE_DEBUG enviroment variable to control which instances are enabled to output debug info.

For the browser use localStorage.debug.

# Will enable instances with *foo* prefix
NODE_DEBUG=foo node foo.js
// Will enable instances with *foo* prefix
localStorage.debug = 'foo'

Multiple instances should be separated by comma

# Will enable instance with *foo* or *bar* prefix
NODE_DEBUG=foo,bar node foo.js
// Will enable instance with *foo* or *bar* prefix
localStorage.debug = 'foo,bar'

Wildcards

Wildcard * is supported.

# Enables all instances
NODE_DEBUG=* node foo.js

# Enables all instances with a prefix starting with *foo*
NODE_DEBUG=foo* node foo.js

Use - to do a negation.

# Enables all instances but the ones with *foo* prefix
NODE_DEBUG=*,-foo node foo.js

# Enables all intances with foo in the prefix and disable *foobar*
NODE_DEBUG=*foo*,-foobar node foo.js

Additional transports integration

If you'd like to send some part of logs into e.g. sentry or some file. You can extend logdown by adding a transport functions:

logdown.transports = [ transport, transport2, ... ]

logdown.transports is simply an array of functions. You can modify it at runtime in any way you like.

Each transport function will be called with an Object as an argument. The object has the following fields:

  • state: Object — contains the current state object
  • instance: string — the instance name, you've specified, when created a logger instance
  • level: string — the name of the method, that was called (e.g. 'warn' for logger.warn('foo'))
  • args: Array<any> — an array of arguments passed to logging method
  • msg: string — contains a string with instance name and concatenated args (except objects). For logdown('foo')('bar', {quz: 1}, 'baz') it will produce [foo] bar baz

Please note, that transport functions will be called even if the logger.state.isEnabled === false. You must decide inside your transport function whether you want to consider the global isEnabled state.

Example of transport implementation:

function transport({ msg, level, args, state }) {
  if (!state.isEnabled) {
    // We dont care, but we can use this if we want
  }

  const levelMap = {
    warn: 'warning',
    error: 'error'
  }

  if (levelMap[level] && process.env.NODE_ENV === 'production') {
    Raven.captureException(msg, {
      level: levelMap[level],
      extra: args[1]
    })
  }
}

logdown.transports = [ transport ]

Conventions

If you're using this in one or more of your libraries, you should use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you should prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser".

Plugins

FAQ

Link

Sponsor

If you found this library useful and are willing to donate, transfer some bitcoins to 1BqqKiZA8Tq43CdukdBEwCdDD42jxuX9UY.

Credits


caiogondim.com  ·  GitHub @caiogondim  ·  Twitter @caio_gondim

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].