You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having problems? Jump on the [slack](https://join.slack.com/t/log4js-node/shared_invite/enQtODkzMDQ3MzExMDczLWUzZmY0MmI0YWI1ZjFhODY0YjI0YmU1N2U5ZTRkOTYyYzg3MjY5NWI4M2FjZThjYjdiOGM0NjU2NzBmYTJjOGI) channel, or create an issue. If you want to help out with the development, the slack channel is a good place to go as well.
38
39
39
40
## installation
@@ -45,33 +46,40 @@ npm install log4js
45
46
## usage
46
47
47
48
Minimalist version:
49
+
48
50
```javascript
49
-
var log4js =require('log4js');
51
+
var log4js =require("log4js");
50
52
var logger =log4js.getLogger();
51
-
logger.level='debug';
53
+
logger.level="debug";
52
54
logger.debug("Some debug messages");
53
55
```
56
+
54
57
By default, log4js will not output any logs (so that it can safely be used in libraries). The `level` for the `default` category is set to `OFF`. To enable logs, set the level (as in the example). This will then output to stdout with the coloured layout (thanks to [masylum](http://github.com/masylum)), so for the above you would see:
58
+
55
59
```bash
56
60
[2010-01-17 11:43:37.987] [DEBUG] [default] - Some debug messages
57
61
```
62
+
58
63
See example.js for a full example, but here's a snippet (also in `examples/fromreadme.js`):
logger.fatal('Cheese was breeding ground for listeria.');
72
+
constlogger=log4js.getLogger("cheese");
73
+
logger.trace("Entering cheese testing");
74
+
logger.debug("Got cheese.");
75
+
logger.info("Cheese is Comté.");
76
+
logger.warn("Cheese is quite smelly.");
77
+
logger.error("Cheese is too ripe!");
78
+
logger.fatal("Cheese was breeding ground for listeria.");
73
79
```
80
+
74
81
Output (in `cheese.log`):
82
+
75
83
```bash
76
84
[2010-01-17 11:43:37.987] [ERROR] cheese - Cheese is too ripe!
77
85
[2010-01-17 11:43:37.990] [FATAL] cheese - Cheese was breeding ground for listeria.
@@ -82,21 +90,23 @@ Output (in `cheese.log`):
82
90
If you're writing a library and would like to include support for log4js, without introducing a dependency headache for your users, take a look at [log4js-api](https://github.com/log4js-node/log4js-api).
83
91
84
92
## Documentation
93
+
85
94
Available [here](https://log4js-node.github.io/log4js-node/).
86
95
87
96
There's also [an example application](https://github.com/log4js-node/log4js-example).
0 commit comments