-
Notifications
You must be signed in to change notification settings - Fork 1
/
botlog.js
42 lines (40 loc) · 889 Bytes
/
botlog.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
/** @format */
const { appendFileSync } = require( 'fs' );
class Logger
{
/**
* Logs given data in /logs/primarylog.log
* @param data The data to log
*/
static log ( data )
{
if ( data instanceof Buffer )
{
console.log( data.toString().trim() );
} else console.log( data.trim() );
Logger.#_appendLog( data, "primary" );
}
/**
* Logs given errors in /logs/errorlog.log
* @param error The error to log
*/
static error ( error )
{
if ( error instanceof Buffer )
{
console.trace( error.toString().trim() );
} else console.trace( error.trim() );
Logger.#_appendLog( error, "error" );
}
static #_appendLog ( data, type )
{
appendFileSync(
`${ process.cwd() }/logs/${ type }log.log`,
`${ new Date() } ||> ${ data }`,
{
encoding: "utf8",
}
);
}
}
module.exports = Logger