Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / log4js / README.md
1 # log4js-node [![Build Status](https://secure.travis-ci.org/nomiddlename/log4js-node.png?branch=master)](http://travis-ci.org/nomiddlename/log4js-node)
2
3 [![NPM](https://nodei.co/npm/log4js.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/log4js/)
4  
5 This is a conversion of the [log4js](https://github.com/stritti/log4js)
6 framework to work with [node](http://nodejs.org). I've mainly stripped out the browser-specific code and tidied up some of the javascript. 
7
8 Out of the box it supports the following features:
9
10 * coloured console logging to stdout or stderr
11 * replacement of node's console.log functions (optional)
12 * file appender, with log rolling based on file size
13 * SMTP appender
14 * GELF appender
15 * hook.io appender
16 * Loggly appender
17 * Logstash UDP appender
18 * logFaces appender
19 * multiprocess appender (useful when you've got worker processes)
20 * a logger for connect/express servers
21 * configurable log message layout/patterns
22 * different log levels for different log categories (make some parts of your app log as DEBUG, others only ERRORS, etc.)
23
24 NOTE: from log4js 0.5 onwards you'll need to explicitly enable replacement of node's console.log functions. Do this either by calling `log4js.replaceConsole()` or configuring with an object or json file like this:
25
26 ```javascript
27 {
28   appenders: [
29     { type: "console" }
30   ],
31   replaceConsole: true
32 }
33 ```
34
35 ## installation
36
37 npm install log4js
38
39
40 ## usage
41
42 Minimalist version:
43 ```javascript
44 var log4js = require('log4js');
45 var logger = log4js.getLogger();
46 logger.debug("Some debug messages");
47 ```
48 By default, log4js outputs to stdout with the coloured layout (thanks to [masylum](http://github.com/masylum)), so for the above you would see:
49 ```bash
50 [2010-01-17 11:43:37.987] [DEBUG] [default] - Some debug messages
51 ```
52 See example.js for a full example, but here's a snippet (also in fromreadme.js):
53 ```javascript
54 var log4js = require('log4js'); 
55 //console log is loaded by default, so you won't normally need to do this
56 //log4js.loadAppender('console');
57 log4js.loadAppender('file');
58 //log4js.addAppender(log4js.appenders.console());
59 log4js.addAppender(log4js.appenders.file('logs/cheese.log'), 'cheese');
60
61 var logger = log4js.getLogger('cheese');
62 logger.setLevel('ERROR');
63
64 logger.trace('Entering cheese testing');
65 logger.debug('Got cheese.');
66 logger.info('Cheese is Gouda.');
67 logger.warn('Cheese is quite smelly.');
68 logger.error('Cheese is too ripe!');
69 logger.fatal('Cheese was breeding ground for listeria.');
70 ```
71 Output:
72 ```bash
73 [2010-01-17 11:43:37.987] [ERROR] cheese - Cheese is too ripe!
74 [2010-01-17 11:43:37.990] [FATAL] cheese - Cheese was breeding ground for listeria.
75 ```    
76 The first 5 lines of the code above could also be written as:
77 ```javascript
78 var log4js = require('log4js');
79 log4js.configure({
80   appenders: [
81     { type: 'console' },
82     { type: 'file', filename: 'logs/cheese.log', category: 'cheese' }
83   ]
84 });
85 ```
86
87 ## configuration
88
89 You can configure the appenders and log levels manually (as above), or provide a
90 configuration file (`log4js.configure('path/to/file.json')`), or a configuration object. The 
91 configuration file location may also be specified via the environment variable 
92 LOG4JS_CONFIG (`export LOG4JS_CONFIG=path/to/file.json`). 
93 An example file can be found in `test/log4js.json`. An example config file with log rolling is in `test/with-log-rolling.json`.
94 You can configure log4js to check for configuration file changes at regular intervals, and if changed, reload. This allows changes to logging levels to occur without restarting the application.
95
96 To turn it on and specify a period:
97
98 ```javascript
99 log4js.configure('file.json', { reloadSecs: 300 });
100 ```
101 For FileAppender you can also pass the path to the log directory as an option where all your log files would be stored.
102
103 ```javascript
104 log4js.configure('my_log4js_configuration.json', { cwd: '/absolute/path/to/log/dir' });
105 ```
106 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:
107
108 #### my_log4js_configuration.json ####
109 ```json
110 {
111   "appenders": [
112     {
113       "type": "file",
114       "filename": "relative/path/to/log_file.log",
115       "maxLogSize": 20480,
116       "backups": 3,
117       "category": "relative-logger"
118     },
119     {
120       "type": "file",
121       "absolute": true,
122       "filename": "/absolute/path/to/log_file.log",
123       "maxLogSize": 20480,
124       "backups": 10,
125       "category": "absolute-logger"          
126     }
127   ]
128 }
129 ```    
130 Documentation for most of the core appenders can be found on the [wiki](https://github.com/nomiddlename/log4js-node/wiki/Appenders), otherwise take a look at the tests and the examples.
131
132 ## Documentation
133 See the [wiki](https://github.com/nomiddlename/log4js-node/wiki). Improve the [wiki](https://github.com/nomiddlename/log4js-node/wiki), please.
134
135 There's also [an example application](https://github.com/nomiddlename/log4js-example).
136
137 ## Contributing
138 Contributions welcome, but take a look at the [rules](https://github.com/nomiddlename/log4js-node/wiki/Contributing) first.
139
140 ## License
141
142 The original log4js was distributed under the Apache 2.0 License, and so is this. I've tried to
143 keep the original copyright and author credits in place, except in sections that I have rewritten
144 extensively.