-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.js
67 lines (59 loc) · 1.11 KB
/
Utils.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
Log file name
@type {string}
*/
import * as fs from "fs";
import {doLog} from "./index.js";
const logFile = "log.txt";
/*
Prints a message
@param {string} header - The header of the message (typically the bot name)
@param {function} headerColour - A chalk function of the colour to use for the header
@param {string} txt - The text of the message to send
@param {Object} [obj] - An optional object to print along with the message
@returns {void}
*/
export function doPrint(header, headerColour, txt, obj)
{
let output = "[";
if(headerColour)
{
output += headerColour(header);
}
else
{
output += header;
}
output += "] ";
output += txt;
if(obj)
{
console.log(output, obj);
}
else
{
console.log(output);
}
}
/*
Logs text to file
@param {string} txt - The text to log
@returns {void}
*/
export function log(txt)
{
if( !doLog )
{
return;
}
const timestamp = getTimestamp();
fs.appendFileSync(logFile, `[${timestamp}] ${txt}\n`);
}
/*
Get a formatted timestamp
@returns {string}
*/
function getTimestamp()
{
return new Date().toISOString().replace(/T/, " ").replace(/\..+/, "");
}