Java Code Examples for ch.qos.logback.classic.spi.LoggingEvent#getLevel()
The following examples show how to use
ch.qos.logback.classic.spi.LoggingEvent#getLevel() .
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: StringUtil.java From xmfcn-spring-cloud with Apache License 2.0 | 5 votes |
/** * 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 2
Source File: StringUtil.java From xmfcn-spring-cloud with Apache License 2.0 | 4 votes |
/** * 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; }