8000 docs(fileSync): sync file appender docs, mostly copied from file · commontime/log4js-node@183992a · GitHub
[go: up one dir, main page]

Skip to content

Commit 183992a

Browse files
author
Gareth Jones
committed
docs(fileSync): sync file appender docs, mostly copied from file
1 parent a78a093 commit 183992a

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/fileSync.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Synchronous File Appender
2+
3+
The sync file appender writes log events to a file, the only difference to the normal file appender is that all the writes are synchronous. This can make writing tests easier, or in situations where you need an absolute guarantee that a log message has been written to the file. Making synchronous I/O calls does mean you lose a lot of the benefits of using node.js though. It supports an optional maximum file size, and will keep a configurable number of backups. Note that the synchronous file appender, unlike the asynchronous version, does not support compressing the backup files.
4+
5+
## Configuration
6+
7+
* `type` - `"file"`
8+
* `filename` - `string` - the path of the file where you want your logs written.
9+
* `maxLogSize` - `integer` (optional) - the maximum size (in bytes) for the log file. If not specified, then no log rolling will happen.
10+
* `backups` - `integer` (optional, default value = 5) - the number of old log files to keep during log rolling.
11+
* `layout` - (optional, defaults to basic layout) - see [layouts](layouts.md)
12+
13+
Any other configuration parameters will be passed to the underlying node.js core stream implementation:
14+
* `encoding` - `string` (default "utf-8")
15+
* `mode`- `integer` (default 0644)
16+
* `flags` - `string` (default 'a')
17+
18+
## Example
19+
20+
```javascript
21+
log4js.configure({
22+
appenders: {
23+
everything: { type: 'fileSync', filename: 'all-the-logs.log' }
24+
},
25+
categories: {
26+
default: { appenders: [ 'everything' ], level: 'debug' }
27+
}
28+
});
29+
30+
const logger = log4js.getLogger();
31+
logger.debug('I will be logged in all-the-logs.log');
32+
```
33+
34+
This example will result in a single log file (`all-the-logs.log`) containing the log messages.
35+
36+
## Example with log rolling
37+
```javascript
38+
log4js.configure({
39+
appenders: {
40+
everything: { type: 'file', filename: 'all-the-logs.log', maxLogSize: 10458760, backups: 3 }
41+
},
42+
categories: {
43+
default: { appenders: [ 'everything' ], level: 'debug'}
44+
}
45+
});
46+
```
47+
This will result in one current log file (`all-the-logs.log`). When that reaches 10Mb in size, it will be renamed and compressed to `all-the-logs.log.1.gz` and a new file opened called `all-the-logs.log`. When `all-the-logs.log` reaches 10Mb again, then `all-the-logs.log.1.gz` will be renamed to `all-the-logs.log.2.gz`, and so on.

0 commit comments

Comments
 (0)
0