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