Java Code Examples for ch.qos.logback.classic.Level#ERROR

The following examples show how to use ch.qos.logback.classic.Level#ERROR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LogLevelConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Level toLogbackLevel(LogLevel level) {
    switch (level) {
        case DEBUG:
            return Level.DEBUG;
        case INFO:
        case LIFECYCLE:
        case QUIET:
            return Level.INFO;
        case WARN:
            return Level.WARN;
        case ERROR:
            return Level.ERROR;
        default:
            throw new IllegalArgumentException("Don't know how to map Gradle log level '" + level + "' to a Logback log level");
    }
}
 
Example 2
Source File: LogLevelConverter.java    From pushfish-android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Level toLogbackLevel(LogLevel level) {
    switch (level) {
        case DEBUG:
            return Level.DEBUG;
        case INFO:
        case LIFECYCLE:
        case QUIET:
            return Level.INFO;
        case WARN:
            return Level.WARN;
        case ERROR:
            return Level.ERROR;
        default:
            throw new IllegalArgumentException("Don't know how to map Gradle log level '" + level + "' to a Logback log level");
    }
}
 
Example 3
Source File: LogbackLoggerSpaceFactory.java    From sofa-common-tools with Apache License 2.0 6 votes vote down vote up
private Level toLogbackLevel(AdapterLevel adapterLevel) {
    if (adapterLevel == null) {
        throw new IllegalStateException("AdapterLevel is NULL when adapter to logback.");
    }
    switch (adapterLevel) {
        case TRACE:
            return Level.TRACE;
        case DEBUG:
            return Level.DEBUG;
        case INFO:
            return Level.INFO;
        case WARN:
            return Level.WARN;
        case ERROR:
            return Level.ERROR;
        default:
            throw new IllegalStateException(adapterLevel
                                            + " is unknown when adapter to logback.");
    }
}
 
Example 4
Source File: LogLevelConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Level toLogbackLevel(LogLevel level) {
    switch (level) {
        case DEBUG:
            return Level.DEBUG;
        case INFO:
        case LIFECYCLE:
        case QUIET:
            return Level.INFO;
        case WARN:
            return Level.WARN;
        case ERROR:
            return Level.ERROR;
        default:
            throw new IllegalArgumentException("Don't know how to map Gradle log level '" + level + "' to a Logback log level");
    }
}
 
Example 5
Source File: LoggerOutputStream.java    From NationStatesPlusPlus with MIT License 6 votes vote down vote up
@Override
public synchronized void flush() throws IOException {
	super.flush();
	String record = this.toString();
	super.reset();

	if (record.length() > 0 && !record.equals(separator) && level != Level.OFF) {
		if (level == Level.TRACE)
			log.trace(record);
		else if (level == Level.DEBUG)
			log.debug(record);
		else if (level == Level.INFO)
			log.info(record);
		else if (level == Level.WARN)
			log.warn(record);
		else if (level == Level.ERROR)
			log.error(record);
	}
}
 
Example 6
Source File: LogLevelConverter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Level toLogbackLevel(LogLevel level) {
    switch (level) {
        case DEBUG:
            return Level.DEBUG;
        case INFO:
        case LIFECYCLE:
        case QUIET:
            return Level.INFO;
        case WARN:
            return Level.WARN;
        case ERROR:
            return Level.ERROR;
        default:
            throw new IllegalArgumentException("Don't know how to map Gradle log level '" + level + "' to a Logback log level");
    }
}
 
Example 7
Source File: ErrorStatisticsAppender.java    From cachecloud with Apache License 2.0 6 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {
    if (event == null) {
        return;
    }
    if (event.getLevel() == Level.ERROR || event.getLevel() == Level.WARN) {
        IThrowableProxy throwableProxy = event.getThrowableProxy();
        if (throwableProxy != null) {
        	//接口名
            String errorClassName = throwableProxy.getClassName();
            if (errorClassName != null && !"".equals(errorClassName.trim())) {
            	//写入AtomicLongMap并计数
                ERROR_NAME_VALUE_MAP.getAndIncrement(errorClassName);
            }
        }
    }
}
 
Example 8
Source File: LoggingUtil.java    From fredbet with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
private Level toLevel(LogLevel logLevel) {
    switch (logLevel) {
        case DEBUG:
            return Level.DEBUG;
        case INFO:
            return Level.INFO;
        case WARN:
            return Level.WARN;
        default:
            return Level.ERROR;
    }
}
 
Example 9
Source File: DingTalkAppender.java    From jframework with Apache License 2.0 5 votes vote down vote up
@Override
public void append(ILoggingEvent event) {
    if (event.getLevel() != Level.ERROR) {
        return;
    }

    String msg = transformStackTrace(event);
    DingTalkUtil.send(msg, event.getLoggerName(), Stream.of(to).collect(Collectors.toSet()));
}
 
Example 10
Source File: GtfsLoggingAppender.java    From core with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Logs WARN and ERROR level messages
 * @see ch.qos.logback.core.AppenderBase#append(java.lang.Object)
 */
@Override
protected void append(ILoggingEvent event) {
	Level level = event.getLevel();
	if (level == Level.WARN) {
		warnings.add(event.getFormattedMessage());
	} else if (level == Level.ERROR) {
		errors.add(event.getFormattedMessage());
	}
}
 
Example 11
Source File: MetricsLogAppender.java    From pravega with Apache License 2.0 5 votes vote down vote up
@Override
public void doAppend(ILoggingEvent event) throws LogbackException {
    if (event.getLevel() == Level.ERROR) {
        recordEvent(MetricsNames.LOG_ERRORS, event);
    } else if (event.getLevel() == Level.WARN) {
        recordEvent(MetricsNames.LOG_WARNINGS, event);
    }
}
 
Example 12
Source File: LogUtil.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Decode a string as a Level value.
 *
 * @param str the input string
 * @return the decoded Level value
 */
public static Level toLevel (final String str)
{
    switch (str.toUpperCase()) {
    case "ALL":
        return Level.ALL;

    case "TRACE":
        return Level.TRACE;

    case "DEBUG":
        return Level.DEBUG;

    case "INFO":
        return Level.INFO;

    case "WARN":
        return Level.WARN;

    case "ERROR":
        return Level.ERROR;

    default:
    case "OFF":
        return Level.OFF;
    }
}
 
Example 13
Source File: LoggingUtils.java    From heat with Apache License 2.0 5 votes vote down vote up
/**
 * This method sets the log level (logback).
 */
public void setLogLevel() {
    logLevel = System.getProperty("logLevel", LOG_LEVEL_INFO);
    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    Level logLevelSetting;
    switch (logLevel.toLowerCase()) {
    case LOG_LEVEL_ERROR:
        logLevelSetting = Level.ERROR;
        break;
    case LOG_LEVEL_WARN:
        logLevelSetting = Level.WARN;
        break;
    case LOG_LEVEL_ALL:
        logLevelSetting = Level.ALL;
        break;
    case LOG_LEVEL_TRACE_LOG:
        logLevelSetting = Level.TRACE;
        break;
    case LOG_LEVEL_INFO:
        logLevelSetting = Level.INFO;
        break;
    case LOG_LEVEL_DEBUG:
        logLevelSetting = Level.DEBUG;
        break;
    default:
        logLevelSetting = Level.INFO;
        break;
    }
    root.setLevel(logLevelSetting);
}
 
Example 14
Source File: ErrorCatcher.java    From FlareBot with MIT License 5 votes vote down vote up
@Override
public FilterReply decide(ILoggingEvent event) {
    String msg = event.getFormattedMessage();
    if (msg == null)
        msg = "null";
    if (event.getMarker() != Markers.NO_ANNOUNCE
            && FlareBot.instance() != null
            && event.getLevel() == Level.ERROR || event.getLevel() == Level.WARN) {
        String finalMsg = msg;
        if (event.getThreadName().startsWith("lava-daemon-pool")) {
            return FilterReply.NEUTRAL;
        }
        EXECUTOR.submit(() -> {
            Throwable throwable = null;
            if (event.getThrowableProxy() != null && event.getThrowableProxy() instanceof ThrowableProxy) {
                throwable = ((ThrowableProxy) event.getThrowableProxy()).getThrowable();
            }
            if (event.getLevel() == Level.WARN) {
                // Warnings should not have a throwable!
                MessageUtils.sendWarningMessage(finalMsg, Constants.getErrorLogChannel());
                return;
            }
            if (throwable != null) {
                if (event.getMarker() == Markers.TAG_DEVELOPER)
                    MessageUtils.sendFatalException(finalMsg, throwable, Constants.getErrorLogChannel());
                else
                    MessageUtils.sendException(finalMsg, throwable, Constants.getErrorLogChannel());
            } else {
                if (event.getMarker() == Markers.TAG_DEVELOPER)
                    MessageUtils.sendFatalErrorMessage(finalMsg, Constants.getErrorLogChannel());
                else
                    MessageUtils.sendErrorMessage(finalMsg, Constants.getErrorLogChannel());
            }
        });
    }
    return FilterReply.NEUTRAL;
}
 
Example 15
Source File: ConsoleLogAppender.java    From xJavaFxTool-spring with Apache License 2.0 5 votes vote down vote up
@Override
protected void append(ILoggingEvent eventObject) {
    if (eventObject.getLevel() == Level.ERROR) {
        try {
            TooltipUtil.showToast("发生错误:\n" + eventObject.getFormattedMessage());
        } catch (Exception e) {

        }
    }
    super.append(eventObject);
}
 
Example 16
Source File: LogbackLogConfigurator.java    From butterfly with MIT License 5 votes vote down vote up
private Level getLogbackLogLevel(org.slf4j.event.Level slf4jLevel) {
    if(slf4jLevel.equals(org.slf4j.event.Level.INFO)) return Level.INFO;
    if(slf4jLevel.equals(org.slf4j.event.Level.DEBUG)) return Level.DEBUG;
    if(slf4jLevel.equals(org.slf4j.event.Level.WARN)) return Level.WARN;
    if(slf4jLevel.equals(org.slf4j.event.Level.ERROR)) return Level.ERROR;

    throw new IllegalArgumentException("Unknown log level");
}
 
Example 17
Source File: StringUtil.java    From xmfcn-spring-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * getEsLogData(组织日志信息)
 * @param loggingEvent 日志信息
 * @param subSysName 子系统名称
 * @author rufei.cn
 * @date 2018/2/27 11:21
 */
public static String getEsLogData(LoggingEvent loggingEvent, String subSysName) {
    String message = loggingEvent.getMessage();
    Level level = loggingEvent.getLevel();
    String loggerName = loggingEvent.getLoggerName();
    StackTraceElement[] callerData = loggingEvent.getCallerData();
    StringBuilder stackMessage = null;//堆栈信息
    String methodName = "";
    if (callerData != null && callerData.length > 0) {
        methodName = callerData[0].getMethodName();
        if (level != null && level == Level.ERROR) {
            stackMessage = new StringBuilder();//堆栈信息
            for (int i = 0; i < callerData.length; i++) {
                if (i > 10) {
                    break;
                }
                stackMessage.append(callerData[i] + "\n");
            }
        }
    }
    EsLogMessage esLog = new EsLogMessage();
    esLog.setSubSysName(subSysName);
    esLog.setModuleName(loggerName);
    esLog.setLevel(level.toString());
    esLog.setMethodName(methodName);
    esLog.setMessage(message);
    if (stackMessage != null && stackMessage.toString().length() > 0) {
        esLog.setStackMessage(stackMessage.toString());
    }
    String jsonString = JSON.toJSONString(esLog);
    return jsonString;
}
 
Example 18
Source File: TableViewLogAppender.java    From AsciidocFX with Apache License 2.0 4 votes vote down vote up
@Override
protected void append(ILoggingEvent event) {

    if (Objects.isNull(logViewer))
        return;

    String message = event.getFormattedMessage();
    String level = event.getLevel().toString();

    if (Objects.isNull(message)) {
        return;
    }

    if (event.getLevel() == Level.ERROR) {
        ObservableList<String> styleClass = logShowHider.getStyleClass();
        if (!styleClass.contains("red-label")) {
            styleClass.add("red-label");
        }
    }

    final String finalMessage = message;
    threadService.buff("logMessager").schedule(() -> {
        threadService.runActionLater(() -> {
            logShortMessage.setText(finalMessage);
        });
    }, 1, TimeUnit.SECONDS);


    IThrowableProxy tp = event.getThrowableProxy();
    if (Objects.nonNull(tp) && event.getLevel() == Level.ERROR) {
        String tpMessage = ThrowableProxyUtil.asString(tp);
        message += "\n" + tpMessage;
    }

    if (!message.isEmpty()) {
        MyLog myLog = new MyLog(level, message);
        buffer.add(myLog);
    }

    threadService.buff("logAppender").schedule(() -> {
        final List<MyLog> clone = new LinkedList<>(buffer);
        buffer.clear();
        threadService.runActionLater(() -> {
            logList.addAll(clone);
        });
    }, 2, TimeUnit.SECONDS);
}
 
Example 19
Source File: InMemoryLoggingBuilder.java    From baleen with Apache License 2.0 4 votes vote down vote up
public InMemoryLoggingBuilder() {
  this(BaleenLogging.DEFAULT_PATTERN, Level.INFO, Level.ERROR);
}
 
Example 20
Source File: StringUtil.java    From xmfcn-spring-cloud with Apache License 2.0 4 votes vote down vote up
/**
 * getLogData(组织日志信息)
 * @param loggingEvent 日志信息
 * @param subSysName 子系统名称
 * @author rufei.cn
 * @date 2018/2/27 11:21
 */
public static String getLogData(LoggingEvent loggingEvent, String subSysName) {
    InetAddress addr = null;
    try {
        addr = InetAddress.getLocalHost();
    } catch (UnknownHostException e) {

    }
    Map<String, String> mdcPropertyMap = loggingEvent.getMDCPropertyMap();
    String ip = addr.getHostAddress().toString(); //获取本机ip
    String hostName = addr.getHostName().toString(); //获取本机计算机名称
    String formattedMessage = loggingEvent.getFormattedMessage();
    Level level = loggingEvent.getLevel();
    String loggerName = loggingEvent.getLoggerName();
    String threadName = loggingEvent.getThreadName();
    Map<String, String> mdcMap = loggingEvent.getMDCPropertyMap();
    StackTraceElement[] callerData = loggingEvent.getCallerData();
    if (isBlank(loggerName)) {
        return null;
    }
    String message = loggerName.replace("\\\\", "\\").replace("\\\\\\", "\\");
    StringBuilder stackMessage = null;//堆栈信息
    String methodName = "";
    String traceId = "";
    String tranceMessage = "";
    if (mdcMap != null) {
        traceId = mdcMap.get("traceId");
        tranceMessage = JSON.toJSONString(mdcMap);//trace 详细数据
    }
    int len = 0;
    if (callerData != null && callerData.length > 0) {
        methodName = callerData[0].getMethodName();
        len = callerData.length;
    }
    stackMessage = new StringBuilder();//堆栈信息
    for (int i = 0; i < len; i++) {
        if (level != null && level != Level.ERROR) {
            continue;
        }
        if (i > 50) {
            break;
        }
        stackMessage.append(callerData[i] + "\n\n");
    }
    if (StringUtil.isBlank(traceId) && mdcMap != null) {
        traceId = mdcMap.get("X-B3-TraceId");
    }
    if (StringUtil.isBlank(traceId)) {
        traceId = "";
    }
    if (StringUtil.isBlank(tranceMessage)) {
        tranceMessage = "";
    }
    if (StringUtil.isBlank(methodName)) {
        methodName = "";
    }
    LogMessage logMessage = new LogMessage();
    logMessage.setSubSysName(subSysName);
    logMessage.setModuleName(loggerName);
    logMessage.setLevel(level.toString());
    logMessage.setMethodName(methodName);
    logMessage.setMessage(message);
    logMessage.setThreadName(threadName);
    logMessage.setSysIp(ip);
    logMessage.setTraceId(traceId);
    logMessage.setTraceMap(tranceMessage);
    if (stackMessage != null && stackMessage.toString().length() > 0) {
        logMessage.setStackMessage(stackMessage.toString());
    }
    String jsonString = JSON.toJSONString(logMessage);
    jsonString = jsonString.replace("\\\\", "\\").replace("\\\\\\", "\\");
    return jsonString;
}