
function Logger(options) {
    //默认日志是关闭的
    this.level = options.level||Logger.LOG_OFF;
    this.appendix = options.appendix||"Lighting";
}

Logger.LEVEL_DEBUG=1;
Logger.LEVEL_INFO=2;
Logger.LEVEL_WARN=3;
Logger.LEVEL_ERROR=4;
Logger.LOG_OFF=5;

/**
 * 错误信息
 * @param msg
 */
Logger.prototype.error = function (msg) {
    if(this.level<=Logger.LEVEL_ERROR){
        console.error("["+this.appendix+"]"+msg);
        if(Logger.websocket) Logger.websocket.send(JSON.stringify({
            type:"log",
            level:"error",
            message:msg,
            userAgent:navigator.userAgent
        }));
    }
};

/**
 * 警告信息
 * @param msg
 */
Logger.prototype.warn = function (msg) {
    if(this.level<=Logger.LEVEL_WARN){
        console.warn("["+this.appendix+"]"+msg);
        if(Logger.websocket) Logger.websocket.send(JSON.stringify({
            type:"log",
            level:"warn",
            message:msg,
            userAgent:navigator.userAgent
        }));
    }
};

/**
 * 一般信息
 * @param msg
 */
Logger.prototype.info = function (msg) {
    if(this.level<=Logger.LEVEL_INFO){
        console.info("["+this.appendix+"]"+msg);
        if(Logger.websocket) Logger.websocket.send(JSON.stringify({
            type:"log",
            level:"info",
            message:msg,
            userAgent:navigator.userAgent
        }));
    }
};

/**
 * 调试信息
 * @param msg
 */
Logger.prototype.debug = function (msg) {
    if(this.level<=Logger.LEVEL_DEBUG){
        console.log("["+this.appendix+"]"+msg);
        if(Logger.websocket) Logger.websocket.send(JSON.stringify({
            type:"log",
            level:"debug",
            message:msg,
            userAgent:navigator.userAgent
        }));
    }
};

export default Logger