[![Gem Version](https://badge.fury.io/rb/delogger.svg)](https://badge.fury.io/rb/delogger) # Delogger This gem is a simple wrapper for the browser's console. It can be turned off both globally (e.x. production environment) and locally. It also supports CSS formatting. ![Demo](/images/demo.png?raw=true) ## Getting Started ### Rails: Add the gem to your Gemfile: ```ruby gem 'delogger', '~> 0.3.0' ``` Add this to your `application.js`: ``` //= require delogger ``` And `application.css`: ``` *= require delogger ``` ### Without Rails: Include `vendor/assets/javascripts/delogger.js` and `vendor/assets/stylesheets/delogger.css` into your application. ## Usage First, DeLogger has to be initialized: ```js logger = new DeLogger ``` See also: [options](#options). By default, DeLogger is **disabled on the client side**. To enable it, use `logger.enable()` in your console. You can disable it again using `logger.disable()`. DeLogger is using browser's `localStorage`, so you only have to enable/disable it once on your website. DeLogger supports same output methods as console: ![debug](/images/debug.png?raw=true) ![info](/images/info.png?raw=true) ![warn](/images/warn.png?raw=true) ![error](/images/error.png?raw=true) Also supported: `log`, `assert`, `count`, `dir`, `dirxml`, `group`, `groupCollapsed`, `groupEnd`, `profile`, `time`, `timeEnd`, `trace`. ### Options You can pass options to DeLogger upon initialization: ```js logger = DeLogger.new({ disabled: false, formatStrings: true }) ``` - `disabled`: You can disable the logger globally if you want to. Normally, though, `logger.disable()` should be enough. - `formatStrings`: Controls whether string [formatting](#formatting) should be enabled. ### Focus mode If you want to debug a certain block of code, but your console is flooded with messages, you can enter the Focus mode with `logger.focus()`. In this mode, you will only see "focused" output. To produce "focused" output, use `logger.focus('my text')`. To leave Focus mode, use `logger.unfocus()`. ## Formatting DeLogger supports string formatting. Syntax: `"(my text).class1.class2"`. Supported classes: `badge`, `bold`, `italic`. See also: [color classes](#color-classes). Example: ![Example output](/images/formatting.png?raw=true) ### Color classes DeLogger supports following color classes (both for badges and normal text): - `.blue` - `.orange` - `.red` - `.green` - `.cyan` - `.yellow` - `.gray` - `.brown` - `.purple` - `.pink` ## Adding custom / overriding existing styles All styles are declared in a stylesheet and thus are easily extensible. See [`assets/stylesheets/delogger.scss`](assets/stylesheets/delogger.scss). At the moment, only these attributes are supported: `margin-left`, `color`, `background-color`, `border-radius`, `padding`, `font-weight`, `font-style`. ## Development Modify files in the `assets` folder, compile them afterwards using `./bin/compile`. ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/akxcv/delogger. ## License The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).