mirror of https://github.com/iconify/api.git
Better logging
This commit is contained in:
parent
b6bdcb142b
commit
34873413b1
50
src/log.js
50
src/log.js
|
|
@ -36,12 +36,50 @@ let throttled = null;
|
|||
*
|
||||
* @param app
|
||||
*/
|
||||
const sendQueue = app => {
|
||||
const sendQueue = (app) => {
|
||||
let text = throttled.join('\n\n- - - - - - - - - - -\n\n');
|
||||
throttled = null;
|
||||
app.mail(text);
|
||||
};
|
||||
|
||||
const months = {
|
||||
0: 'Jan',
|
||||
1: 'Feb',
|
||||
2: 'Mar',
|
||||
3: 'Apr',
|
||||
4: 'May',
|
||||
5: 'June',
|
||||
6: 'July',
|
||||
7: 'Aug',
|
||||
8: 'Sep',
|
||||
9: 'Oct',
|
||||
10: 'Nov',
|
||||
11: 'Dec',
|
||||
};
|
||||
|
||||
const logTime = () => {
|
||||
let time = new Date();
|
||||
|
||||
let result = '[';
|
||||
// Add date
|
||||
result +=
|
||||
time.getUTCDate() +
|
||||
' ' +
|
||||
months[time.getUTCMonth()] +
|
||||
' ' +
|
||||
time.getUTCFullYear();
|
||||
// Add time
|
||||
result +=
|
||||
(time.getUTCHours() > 9 ? ' ' : ' 0') +
|
||||
time.getUTCHours() +
|
||||
(time.getUTCMinutes() > 9 ? ':' : ':0') +
|
||||
time.getUTCMinutes() +
|
||||
(time.getUTCSeconds() > 9 ? ':' : ':0') +
|
||||
time.getUTCSeconds();
|
||||
result += '] ';
|
||||
return result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Log message. This function combines multiple logging methods, so it can be called only once instead of calling
|
||||
* multiple log() functions.
|
||||
|
|
@ -72,15 +110,7 @@ module.exports = (app, error, message, options) => {
|
|||
}
|
||||
|
||||
// Get time stamp
|
||||
let time = new Date();
|
||||
time =
|
||||
(time.getUTCHours() > 9 ? '[' : '[0') +
|
||||
time.getUTCHours() +
|
||||
(time.getUTCMinutes() > 9 ? ':' : ':0') +
|
||||
time.getUTCMinutes() +
|
||||
(time.getUTCSeconds() > 9 ? ':' : ':0') +
|
||||
time.getUTCSeconds() +
|
||||
'] ';
|
||||
let time = logTime();
|
||||
|
||||
// Copy message to console
|
||||
if (options.log || !app.mail) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue