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 |
|
11 | Logdown is a debug utility for the browser and the server with Markdown support.
|
12 | It does not have any dependencies and is only 2K gzipped.
|
13 |
|
14 | You can see it in action in the [example page](//caiogondim.github.io/logdown.js)
|
15 | or 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 |
|
29 | The simplest use of the library in both platforms could be done as follows:
|
30 |
|
31 | ### Node.js
|
32 |
|
33 | If on the server, install it through [npm](https://www.npmjs.com/):
|
34 |
|
35 | ```bash
|
36 | npm install --save logdown
|
37 | ```
|
38 |
|
39 | ```js
|
40 | var Logdown = require('logdown')
|
41 | var logger = new Logdown({prefix: 'foo'})
|
42 | ```
|
43 |
|
44 | ### Browser
|
45 |
|
46 | In the browser you can install it through [Bower](http://bower.io):
|
47 |
|
48 | ```bash
|
49 | bower install logdown
|
50 | ```
|
51 |
|
52 | ```js
|
53 | var logger = new Logdown({prefix: 'foo'})
|
54 | ```
|
55 |
|
56 | ### SystemJS
|
57 |
|
58 | Using the dynamic module loader [SystemJS](https://github.com/systemjs/systemjs), Logdown can be loaded as a CommonJS module:
|
59 |
|
60 | ```js
|
61 | SystemJS.config({
|
62 | map: {
|
63 | 'logdown': 'bower_components/logdown/dist/index.js'
|
64 | },
|
65 | packages: {
|
66 | 'logdown': {format: 'cjs'}
|
67 | }
|
68 | });
|
69 | ```
|
70 |
|
71 | ```js
|
72 | System.import('logdown').then(function(Logdown) {
|
73 | var logger = new Logdown({prefix: 'foo'}
|
74 | });
|
75 | ```
|
76 |
|
77 | ### TypeScript
|
78 |
|
79 | ```ts
|
80 | import Logdown = require("logdown");
|
81 | let logger: Logdown = new Logdown({prefix: 'foo'};
|
82 | ```
|
83 |
|
84 | ### Other
|
85 |
|
86 | You can also use the lib in the browser in the same way as in the server if you
|
87 | use [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 |
|
93 | It 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 |
|
95 | 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.
|
96 |
|
97 | ```js
|
98 | logger.log('lorem *ipsum*')
|
99 | logger.info('dolor _sit_ amet')
|
100 | logger.warn('consectetur `adipiscing` elit')
|
101 | ```
|
102 |
|
103 | You can pass multiple arguments
|
104 |
|
105 | ```js
|
106 | logger.log('lorem', '*ipsum*')
|
107 | logger.info('dolor _sit_', 'amet')
|
108 | logger.warn('consectetur', '`adipiscing` elit')
|
109 | ```
|
110 |
|
111 | ### New objects
|
112 |
|
113 | The constructor accepts one object for configuration on instantiation time.
|
114 |
|
115 | #### `opts.prefix`
|
116 |
|
117 | Type: 'String'
|
118 |
|
119 | Default: `''`
|
120 |
|
121 | ```js
|
122 | var logger = new Logdown({prefix: 'foo'})
|
123 | logger.log('Lorem ipsum') // Will use console.log with a prefix
|
124 | ```
|
125 |
|
126 | You should use the name of your module.
|
127 | You can, also, use `:` to separate modules inside one big module.
|
128 |
|
129 | ```js
|
130 | var fooBarLogger = new Logdown({prefix: 'foo:bar'})
|
131 | fooBarLogger.log('Lorem ipsum')
|
132 |
|
133 | var fooQuzLogger = new Logdown({prefix: 'foo:quz'})
|
134 | fooQuzLogger.log('Lorem Ipsum')
|
135 | ```
|
136 |
|
137 | #### `opts.markdown`
|
138 |
|
139 | Type: 'Boolean'
|
140 |
|
141 | Default: `true`
|
142 |
|
143 | If setted to `false`, markdown will not be parsed.
|
144 |
|
145 | ```js
|
146 | var logger = new Logdown({markdown: false})
|
147 | logger.log('Lorem *ipsum*') // Will not parse the markdown
|
148 | ```
|
149 |
|
150 | For Markdown, the following mark-up is supported:
|
151 |
|
152 | ```js
|
153 | // Bold with "*"" between words
|
154 | logger.log('lorem *ipsum*')
|
155 |
|
156 | // Italic with "_" between words
|
157 | logger.log('lorem _ipsum_')
|
158 |
|
159 | // Code with ` (backtick) between words
|
160 | logger.log('lorem `ipsum`')
|
161 | ```
|
162 |
|
163 | #### `opts.alignOutput`
|
164 |
|
165 | Type: 'Boolean'
|
166 |
|
167 | Default: `false`
|
168 |
|
169 | If 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 |
|
173 | It is possible to enable/disable the output of instances using the
|
174 | `Logdown.disable` or `Logdown.enable` methods.
|
175 |
|
176 | ```js
|
177 | Logdown.disable('foo') // will disable the instance with *foo* prefix
|
178 | Logdown.enable('bar') // will enable the instance with *bar* prefix
|
179 | ```
|
180 |
|
181 | You can also use wildcards.
|
182 |
|
183 | ```js
|
184 | Logdown.enable('*') // enables all instances
|
185 | Logdown.disable('*') // disables all instances
|
186 | Logdown.enable('foo*') // enables all instances with a prefix starting with *foo*
|
187 | ```
|
188 |
|
189 | Use `-` to do a negation.
|
190 |
|
191 | ```js
|
192 | // enables all instances but the one with *foo* prefix
|
193 | Logdown.enable('*', '-foo')
|
194 | // disables all intances with foo in the prefix, but don't disable *foobar*
|
195 | Logdown.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 | ```
|
206 | 203 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 |
|
219 | If you found this library useful and are willing to donate, transfer some
|
220 | bitcoins to `1BqqKiZA8Tq43CdukdBEwCdDD42jxuX9UY` or through the
|
221 | [URL](https://www.coinbase.com/caiogondim) https://www.coinbase.com/caiogondim
|
222 |
|
223 | Or via [PayPal.me](https://www.paypal.me/caiogondim) https://www.paypal.me/caiogondim.
|
224 |
|
225 | ---
|
226 |
|
227 | [caiogondim.com](https://caiogondim.com) ·
|
228 | GitHub [@caiogondim](https://github.com/caiogondim) ·
|
229 | Twitter [@caio_gondim](https://twitter.com/caio_gondim)
|