logalize

Logalize is a Javascript wrapper for browser's developer console.


Keywords
console, wrapper, browser, web, formatting, colors, logging, production, debug, developer-tools, disable-logging
License
MIT
Install
gem install logalize -v 0.0.7

Documentation

Logalize

Logalize is a JavaScript wrapper for browser's developer console.

Rails gem

Main features

Usage

Enable or disable logging:

// Disable logalize
logalize.configure({ enabled: false })
// Enable logalize only for yourself (writes to localStorage)
logalize.enable()

Methods that work exactly like their console's counterparts:

Also:

logalize.group('group1')
myVar = myFunction()
logalize.groupEnd()

/* is the same as */

myVar = logalize.group('group1', myFunction)

Also:

logalize('my output')
// is the same as:
logalize.log('my output')

Configuration options

logalize.configure({
  enabled: true,
  enableFormatting: true,
  collapseNamespaces: false
})
  • enabled: Defines whether to enable or disable Logalize. When Logalize is disabled, it will not produce any output. However, lambda versions of profile, time, group and namespace will still execute given functions. Default: true.
  • enableFormatting: Defines whether formatting should be enabled. Default: true.
  • collapseNamespaces: Defines whether namespaces should use group or groupCollapsed method. Defaults to false (group).

Namespaces

Namespaces are like groups but more convenient:

/* method 1 */
logalize.namespace('namespace one').log('inside namespace 1')

/* method 2 */
val = logalize.namespace('namespace one', function () {
  logalize.log('inside namespace 1')
  return 'veryImportantValue'
})

You can easily mix methods together and nest namespaces however you want:

logalize.namespace('user login', function () {
  logalize.info('user login started')
  logalize.namespace('credentials').log('credentials are {correct}.green')
  /* code */
  logalize.info('[success].green')
})

logalize.namespace('namespace 1').log('some more output')
logalize.namespace('namespace 1', 'another namespace!').log('still nested correctly')

Output:

Namespace output

Formatting

Logalize supports Markdown-like string formatting. Here's the options:

  • **bold**
  • *italic*
  • ~strikethrough~
  • _underline_
  • [badge text].classOne.classTwo... (classes are optional)
  • {custom text}.classOne.classTwo... (classes are required). This syntax allows you to apply CSS classes to text in curly braces. Available classes are: badge, bold, italic, strikethrough, underline and color classes.

At the moment, you cannot nest formatting options into each other. Objects and functions are not formattable, but they likely will be in the future.

Color classes

Logalize supports following color classes (both for badges and normal text):

  • .blue
  • .orange
  • .red
  • .green
  • .cyan
  • .purple

Adding custom / overriding existing styles

All styles are declared in a stylesheet and thus are easily extensible. See index.scss. At the moment, only these attributes are supported: margin, color, background-color, border-radius, padding, font-weight, font-style, text-decoration.

Known issues

  • There's no way to detect when console output happens. Development tools are separate from window and document, and there is no way to know if the output is happening. So, some output will inevitably get stuck in a group it doesn't belong.

  • Stack traces from logalize.error and logalize.trace contain unneeded information. Since logalize.error and logalize.trace call some functions under the hood, the stack trace produced by those functions will contain several unneeded calls.

All of this is according to the author's research. If you know a solution to any of these problems, you're highly encouraged to open an issue and/or a pull request at akxcv/logalize.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/akxcv/logalize.

License

The package is available as open source under the terms of the MIT License.

TODO

  • Support nested formatting
  • Log history
  • Focus mode (see only the logs you need right now)
  • Object and function formatting