aboutsummaryrefslogtreecommitdiff
path: root/logger.js
blob: 9c27a939dd5c1d3c1a1d63dbf1ccdda52bab2a16 (plain)
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
/// <reference types="../CTAutocomplete" />
/// <reference lib="es2015" />

class Logger{
    constructor(){
        this.isDev = isDev()
        this.loglevel = this.isDev?4:2 //0=none, 1=error, 2=warn, 3=info, 4=debug
        this.logToMcChat = false
        this.logPrefixes = [
            "[SOOPYADDONS]       ",
            "[SOOPYADDONS:ERROR] ",
            "[SOOPYADDONS:WARN]  ",
            "[SOOPYADDONS:INFO]  ",
            "[SOOPYADDONS:DEBUG] "
        ]
        this.logMessage("Logger initialised", 3)
    }

    logMessage(message, level){
        if(level <= this.loglevel){
            console.log(this.logPrefixes[level] + message)
            if(this.logToMcChat){
                ChatLib.chat(this.logPrefixes[level] + message)
            }
        }
    }
}
let devs = ["dc8c39647b294e03ae9ed13ebd65dd29"]

function isDev(){
    return devs.includes(Player.getUUID().toString().replace(/-/g, ""))
}


if(!global.soopyv2loggerthing){
    global.soopyv2loggerthing = new Logger()

    register("command", ()=>{
        devs.push(Player.getUUID().toString().replace(/-/g, ""))
    }).setName("pleasegivemeaccesstosoopyv2devconsolelogs") //yep

    register("gameUnload", ()=>{
        global.soopyv2loggerthing = undefined
    })
}
export default global.soopyv2loggerthing