Added syntax highlighting to JS code in README.md

release-0.5.7-fixup
Uli Köhler 12 years ago
parent 3e1a27e522
commit 0167c84ea5

@ -36,49 +36,49 @@ npm install log4js
## usage ## usage
Minimalist version: Minimalist version:
```javascript
var log4js = require('log4js'); var log4js = require('log4js');
var logger = log4js.getLogger(); var logger = log4js.getLogger();
logger.debug("Some debug messages"); logger.debug("Some debug messages");
```
By default, log4js outputs to stdout with the coloured layout (thanks to [masylum](http://github.com/masylum)), so for the above you would see: By default, log4js outputs to stdout with the coloured layout (thanks to [masylum](http://github.com/masylum)), so for the above you would see:
[2010-01-17 11:43:37.987] [DEBUG] [default] - Some debug messages [2010-01-17 11:43:37.987] [DEBUG] [default] - Some debug messages
See example.js for a full example, but here's a snippet (also in fromreadme.js): See example.js for a full example, but here's a snippet (also in fromreadme.js):
```javascript
var log4js = require('log4js'); var log4js = require('log4js');
//console log is loaded by default, so you won't normally need to do this //console log is loaded by default, so you won't normally need to do this
//log4js.loadAppender('console'); //log4js.loadAppender('console');
log4js.loadAppender('file'); log4js.loadAppender('file');
//log4js.addAppender(log4js.appenders.console()); //log4js.addAppender(log4js.appenders.console());
log4js.addAppender(log4js.appenders.file('logs/cheese.log'), 'cheese'); log4js.addAppender(log4js.appenders.file('logs/cheese.log'), 'cheese');
```javascript
var logger = log4js.getLogger('cheese'); var logger = log4js.getLogger('cheese');
logger.setLevel('ERROR'); logger.setLevel('ERROR');
logger.trace('Entering cheese testing'); logger.trace('Entering cheese testing');
logger.debug('Got cheese.'); logger.debug('Got cheese.');
logger.info('Cheese is Gouda.'); logger.info('Cheese is Gouda.');
logger.warn('Cheese is quite smelly.'); logger.warn('Cheese is quite smelly.');
logger.error('Cheese is too ripe!'); logger.error('Cheese is too ripe!');
logger.fatal('Cheese was breeding ground for listeria.'); logger.fatal('Cheese was breeding ground for listeria.');
```
Output: Output:
[2010-01-17 11:43:37.987] [ERROR] cheese - Cheese is too ripe! [2010-01-17 11:43:37.987] [ERROR] cheese - Cheese is too ripe!
[2010-01-17 11:43:37.990] [FATAL] cheese - Cheese was breeding ground for listeria. [2010-01-17 11:43:37.990] [FATAL] cheese - Cheese was breeding ground for listeria.
The first 5 lines of the code above could also be written as: The first 5 lines of the code above could also be written as:
```javascript
var log4js = require('log4js'); var log4js = require('log4js');
log4js.configure({ log4js.configure({
appenders: [ appenders: [
{ type: 'console' }, { type: 'console' },
{ type: 'file', filename: 'logs/cheese.log', category: 'cheese' } { type: 'file', filename: 'logs/cheese.log', category: 'cheese' }
] ]
}); });
```
## configuration ## configuration
@ -91,17 +91,20 @@ By default, the configuration file is checked for changes every 60 seconds, and
To turn off configuration file change checking, configure with: To turn off configuration file change checking, configure with:
var log4js = require('log4js'); ```javascript
log4js.configure('my_log4js_configuration.json', {}); var log4js = require('log4js');
log4js.configure('my_log4js_configuration.json', {});
```
To specify a different period: To specify a different period:
log4js.configure('file.json', { reloadSecs: 300 }); ```javascript
log4js.configure('file.json', { reloadSecs: 300 });
```
For FileAppender you can also pass the path to the log directory as an option where all your log files would be stored. For FileAppender you can also pass the path to the log directory as an option where all your log files would be stored.
log4js.configure('my_log4js_configuration.json', { cwd: '/absolute/path/to/log/dir' }); ```javascript
log4js.configure('my_log4js_configuration.json', { cwd: '/absolute/path/to/log/dir' });
```
If you have already defined an absolute path for one of the FileAppenders in the configuration file, you could add a "absolute": true to the particular FileAppender to override the cwd option passed. Here is an example configuration file: If you have already defined an absolute path for one of the FileAppenders in the configuration file, you could add a "absolute": true to the particular FileAppender to override the cwd option passed. Here is an example configuration file:
#### my_log4js_configuration.json #### #### my_log4js_configuration.json ####

Loading…
Cancel
Save