Name: js-handler/node_modules/restify/node_modules/bunyan/examples/handle-fs-error.js 
1:
// Example handling an fs error for a Bunyan-created
2:
// stream: we create a logger to a file that is read-only.
3:
 
4:
var fs = require('fs');
5:
var path = require('path');
6:
var Logger = require('../lib/bunyan');
7:
 
8:
var FILENAME = 'handle-fs-error.log';
9:
var S_IWUSR = 00200; // mask for owner write permission in stat mode
10:
 
11:
console.warn('- Log file is "%s".', FILENAME);
12:
if (!path.existsSync(FILENAME)) {
13:
        console.warn('- Touch log file.');
14:
        fs.writeFileSync(FILENAME, 'touch\n');
15:
}
16:
if (fs.statSync(FILENAME).mode & S_IWUSR) {
17:
        console.warn('- Make log file read-only.');
18:
        fs.chmodSync(FILENAME, 0444);
19:
}
20:
 
21:
console.warn('- Create logger.')
22:
var log = new Logger({name: 'handle-fs-error', streams: [{path: FILENAME}]});
23:
 
24:
log.on('error', function (err) {
25:
        console.warn('- The logger emitted an error:', err);
26:
});
27:
 
28:
console.warn('- Call log.info(...).')
29:
log.info('info log message');
30:
console.warn('- Called log.info(...).')
31:
 
32:
setTimeout(function () {
33:
        console.warn('- Call log.warn(...).')
34:
        log.warn('warn log message');
35:
        console.warn('- Called log.warn(...).')
36:
}, 1000);