-
Notifications
You must be signed in to change notification settings - Fork 0
/
loggStrings.js
50 lines (45 loc) · 1.21 KB
/
loggStrings.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const rfs = require('rotating-file-stream');
const path = require('path');
// Logg String for printing response body
const bodyString = (req) => ` {
CompanyName: ${req.body.companyName}
ContactPerson: ${req.body.contactPerson}
ContactEmail: ${req.body.contactEmail}
ContactTlf: ${req.body.contactTlf}
Day: ${req.body.day}
Marathon: ${req.body.marathon}
Message: ${req.body.message}
}`;
// Logg-String for printing immediate request
const tinyLoggString = `
============:date[web]===========
> Request
ID:\t:id
Addr\t::remote-addr
User\t:remote-user
Method\t:method
`;
// Logg-String for printing full response
const loggString = `
> Response
ID:\t:id
Date\t:date[web]
Addr\t::remote-addr
User\t:remote-user
Method\t:method
Url\t":url"
Ref\t":referrer HTTP/:http-version"
Status\t:status
Time\t:response-time ms
Body\t:body
====================================================
`;
// Create a rotating write stream
const accessLogStream = rfs.createStream('access.log', {
interval: '1d', // rotate daily
path: path.join(__dirname, 'log'),
});
module.exports.bodyString = bodyString;
module.exports.tinyLoggString = tinyLoggString;
module.exports.loggString = loggString;
module.exports.accessLogStream = accessLogStream;