-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlogs.js
28 lines (19 loc) · 860 Bytes
/
logs.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
'use strict';
const fs = require('fs');
const path = require('path');
const config = require('./config.json');
const { analyzeLogs } = require('./analyzer.js');
const { summaryHtml } = require('./formatter.js');
const date = process.argv[2] || ''; // YYYYMMDD
const logs = fs.readdirSync(config.LOGSDIR)
.filter( fname => path.extname(fname) === '.log' && (!date || fname.indexOf(date) > 0) )
.map( fname => path.join( config.LOGSDIR, fname ) );
const errors = analyzeLogs(logs);
const topErrors = Object.keys(errors)
.filter( key => errors[key].total > config.MAXERRORS )
.sort( (a,b) => errors[b].total - errors[a].total )
.map( key => errors[key] );
const summary = path.join( config.LOGSDIR, `${config.SUMMARY}${date}.html` );
console.log(`output: ${summary}`);
fs.writeFileSync( summary, summaryHtml(topErrors) );
console.log('done.');