UNPKG

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