Merge pull request #105 from ulikoehler/readme-syntax-highlighting
Added syntax highlighting to JS code in README.md
This commit is contained in:
commit
ec2f8fec3b
71
README.md
71
README.md
@ -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');
|
||||||
|
//console log is loaded by default, so you won't normally need to do this
|
||||||
|
//log4js.loadAppender('console');
|
||||||
|
log4js.loadAppender('file');
|
||||||
|
//log4js.addAppender(log4js.appenders.console());
|
||||||
|
log4js.addAppender(log4js.appenders.file('logs/cheese.log'), 'cheese');
|
||||||
|
```javascript
|
||||||
|
var logger = log4js.getLogger('cheese');
|
||||||
|
logger.setLevel('ERROR');
|
||||||
|
|
||||||
var log4js = require('log4js');
|
logger.trace('Entering cheese testing');
|
||||||
//console log is loaded by default, so you won't normally need to do this
|
logger.debug('Got cheese.');
|
||||||
//log4js.loadAppender('console');
|
logger.info('Cheese is Gouda.');
|
||||||
log4js.loadAppender('file');
|
logger.warn('Cheese is quite smelly.');
|
||||||
//log4js.addAppender(log4js.appenders.console());
|
logger.error('Cheese is too ripe!');
|
||||||
log4js.addAppender(log4js.appenders.file('logs/cheese.log'), 'cheese');
|
logger.fatal('Cheese was breeding ground for listeria.');
|
||||||
|
```
|
||||||
var logger = log4js.getLogger('cheese');
|
|
||||||
logger.setLevel('ERROR');
|
|
||||||
|
|
||||||
logger.trace('Entering cheese testing');
|
|
||||||
logger.debug('Got cheese.');
|
|
||||||
logger.info('Cheese is Gouda.');
|
|
||||||
logger.warn('Cheese is quite smelly.');
|
|
||||||
logger.error('Cheese is too ripe!');
|
|
||||||
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…
Reference in New Issue
Block a user