UNPKG

5.85 kBMarkdownView Raw
1<img src="http://rawgit.com/caiogondim/logdown.js/master/img/icon.svg">
2
3<h1 align="center">logdown.js</h1>
4
5<div align="center">
6<img src="http://travis-ci.org/caiogondim/logdown.js.svg?branch=master" alt="Travis CI"> <img src="http://img.badgesize.io/caiogondim/logdown.js/master/dist/index.js?compression=gzip" alt="lib size"> <img src="http://img.shields.io/npm/dm/logdown.svg" alt="Downloads per month">
7</div>
8
9<br>
10
11Logdown is a debug utility for the browser and the server with Markdown support.
12It does not have any dependencies and is only 2K gzipped.
13
14You can see it in action in the [example page](//caiogondim.github.io/logdown.js)
15or in the preview below.
16
17
18## Preview
19
20### Browser
21<img src="http://rawgit.com/caiogondim/logdown.js/master/img/browser-preview.gif">
22
23### Server
24<img src="http://rawgit.com/caiogondim/logdown.js/master/img/node-preview.gif">
25
26
27## Installation
28
29### npm
30
31If on the server, install it through [npm](https://www.npmjs.com/):
32
33```bash
34npm install --save logdown
35```
36
37```js
38var Logdown = require('logdown')
39var logger = new Logdown({prefix: 'foo'})
40```
41
42### Bower
43
44In the browser you can install it through [Bower](http://bower.io):
45
46```bash
47bower install logdown
48```
49
50```js
51var logger = new Logdown({prefix: 'foo'})
52```
53
54### Other
55
56You can also use the lib in the browser in the same way as in the server if you use [Browserify](http://browserify.org/). Or you can just download it [here](https://github.com/caiogondim/logdown.js/archive/master.zip) and put the `dist/logdown.js` file in your public folder. Another way of retrieving Logdown is [via jsDelivr](http://www.jsdelivr.com/projects/logdown.js), a public Open Source CDN.
57
58## Import
59
60### SystemJS
61
62Using the dynamic module loader [SystemJS](https://github.com/systemjs/systemjs), Logdown can be loaded as a CommonJS module:
63
64```js
65SystemJS.config({
66 map: {
67 'logdown': 'bower_components/logdown/dist/logdown.js'
68 },
69 packages: {
70 'logdown': {format: 'cjs'}
71 }
72});
73```
74
75```js
76System.import('logdown').then(function(Logdown) {
77 var logger = new Logdown({prefix: 'foo'}
78});
79```
80
81### TypeScript
82
83```ts
84import Logdown = require("logdown");
85```
86
87```ts
88let logger: Logdown = new Logdown({prefix: 'foo'};
89```
90
91## Usage
92
93### Logging
94
95It is highly recommended to use a prefix for your instance, this way you get a nice prefixed message on console and it is possible to silence instances based on the prefix name, as we will see after.
96
97After creating your object, you can use the regular `log`, `warn`, `info` and `error` methods as we have on `console`, but now with Markdown support.
98
99```js
100logger.log('lorem *ipsum*')
101logger.info('dolor _sit_ amet')
102logger.warn('consectetur `adipiscing` elit')
103```
104
105You can pass multiple arguments
106
107```js
108logger.log('lorem', '*ipsum*')
109logger.info('dolor _sit_', 'amet')
110logger.warn('consectetur', '`adipiscing` elit')
111```
112
113### Options
114
115The constructor accepts one object for configuration on instantiation time.
116
117**Example**
118
119```js
120var options = {alignOutput: true, prefix: 'foo'}
121var logger = new Logdown(options)
122```
123
124The following options can be used for configuration.
125
126#### `prefix`
127
128- Type: 'String'
129- Default: `''`
130
131```js
132var logger = new Logdown({prefix: 'foo'})
133logger.log('Lorem ipsum') // Will use console.log with a prefix
134```
135
136You should use the name of your module.
137You can, also, use `:` to separate modules inside one big module.
138
139```js
140var fooBarLogger = new Logdown({prefix: 'foo:bar'})
141fooBarLogger.log('Lorem ipsum')
142
143var fooQuzLogger = new Logdown({prefix: 'foo:quz'})
144fooQuzLogger.log('Lorem Ipsum')
145```
146
147#### `markdown`
148
149- Type: 'Boolean'
150- Default: `true`
151
152If setted to `false`, markdown will not be parsed.
153
154```js
155var logger = new Logdown({markdown: false})
156logger.log('Lorem *ipsum*') // Will not parse the markdown
157```
158
159For Markdown, the following mark-up is supported:
160
161```js
162// Bold with "*"" between words
163logger.log('lorem *ipsum*')
164
165// Italic with "_" between words
166logger.log('lorem _ipsum_')
167
168// Code with ` (backtick) between words
169logger.log('lorem `ipsum`')
170```
171
172#### `alignOutput`
173
174- Type: 'Boolean'
175- Default: `false`
176
177If setted to `true`, the name of the logger instance will have the same length as the longest name of any other Logdown instance.
178
179## Enabling/disabling instances
180
181It is possible to enable/disable the output of instances using the
182`Logdown.disable` or `Logdown.enable` methods.
183
184```js
185Logdown.disable('foo') // will disable the instance with *foo* prefix
186Logdown.enable('bar') // will enable the instance with *bar* prefix
187```
188
189You can also use wildcards.
190
191```js
192Logdown.enable('*') // enables all instances
193Logdown.disable('*') // disables all instances
194Logdown.enable('foo*') // enables all instances with a prefix starting with *foo*
195```
196
197Use `-` to do a negation.
198
199```js
200// enables all instances but the one with *foo* prefix
201Logdown.enable('*', '-foo')
202// disables all intances with foo in the prefix, but don't disable *foobar*
203Logdown.disable('*foo*', '-foobar')
204```
205
206## Credits
207- Moleskine icon by [Monika Ciapala](http://thenounproject.com/merdesign/)
208- Markdown icon by [Dustin Curtis](https://github.com/dcurtis/markdown-mark)
209
210
211## Contributors
212
213```
214203 Caio Gondim
215 30 Benny Neugebauer
216 5 David Godfrey
217 2 Sven Anders Robbestad
218 1 Dan Lukinykh
219 1 Bent Cardan
220 1 Gleb Bahmutov
221 1 Panayiotis Lipiridis
222 1 netmml
223```
224
225## Donating
226
227If you found this library useful and are willing to donate, transfer some
228bitcoins to `1BqqKiZA8Tq43CdukdBEwCdDD42jxuX9UY` or through the
229[URL](https://www.coinbase.com/caiogondim) https://www.coinbase.com/caiogondim
230
231Or via [PayPal.me](https://www.paypal.me/caiogondim) https://www.paypal.me/caiogondim.
232
233---
234
235[caiogondim.com](https://caiogondim.com) &nbsp;&middot;&nbsp;
236GitHub [@caiogondim](https://github.com/caiogondim) &nbsp;&middot;&nbsp;
237Twitter [@caio_gondim](https://twitter.com/caio_gondim)