LogBack配置
神文学习!!! : https://juejin.im/post/5b51f85c5188251af91a7525#heading-2
巨益log配置参考
monitor.xml
<?xml version="1.0" encoding="UTF-8"?>
<included>
<appender name="monitor_time_out" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>log/time-monitor.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>log/time-monitor.%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n%ex</pattern>
</encoder>
</appender>
<logger name="monitor.time" level="info" additivity="false">
<appender-ref ref="monitor_time_out"/>
</logger>
</included>
base.xml
<?xml version="1.0" encoding="UTF-8"?>
<included>
<include resource="com/greatonce/core/logging/monitor.xml"/>
<property name="es_url_default" value="http://101.37.65.195:40002/_bulk"/>
<property name="log_pattern_default"
value="%d{HH:mm:ss.SSS} %-5level [%thread] %logger{36} - %msg%n%ex"/>
<property name="log_file_default" value="log/oms.log"/>
<property name="log_file_pattern_default" value="log/oms.%d{yyyy-MM-dd}.%i.log"/>
<property name="log_file_max_history_default" value="30"/>
<property name="log_file_max_size_default" value="100MB"/>
<property name="log_file_max_total_size_default" value="50GB"/>
<appender name="oms_biz" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>${es_url:-${es_url_default}}</url>
<index>biz-logs-%date{yyyy-MM-dd}</index>
<type>oms3</type>
<errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
<connectTimeout>60000</connectTimeout>
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
</property>
<property>
<name>type</name>
<value>biz</value>
</property>
<property>
<name>logger</name>
<value>%logger</value>
</property>
<property>
<name>thread</name>
<value>%thread</value>
</property>
<property>
<name>bizid</name>
<value>%X{bizid}</value>
</property>
<property>
<name>bizdtl</name>
<value>%X{bizdtl}</value>
</property>
<property>
<name>act</name>
<value>%X{act}</value>
</property>
<property>
<name>oper</name>
<value>%X{oper}</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
<appender name="oms_product_mall_mapping"
class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>${es_url:-${es_url_default}}</url>
<index>product-mall-mapping-%date{yyyy-MM-dd}</index>
<type>oms3</type>
<errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
<connectTimeout>60000</connectTimeout>
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
</property>
<property>
<name>type</name>
<value>biz.product.mall.mapping</value>
</property>
<property>
<name>oper</name>
<value>%X{oper}</value>
</property>
<property>
<name>storeId</name>
<value>%X{storeId}</value>
</property>
<property>
<name>storeName</name>
<value>%X{storeName}</value>
</property>
<property>
<name>mallProductId</name>
<value>%X{mallProductId}</value>
</property>
<property>
<name>mallSkuId</name>
<value>%X{mallSkuId}</value>
</property>
<property>
<name>mallProductOutCode</name>
<value>%X{mallProductOutCode}</value>
</property>
<property>
<name>mallSkuOutCode</name>
<value>%X{mallSkuOutCode}</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
<appender name="oms_stock_mall_upload"
class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>${es_url:-${es_url_default}}</url>
<index>stock-upload-%date{yyyy-MM-dd}</index>
<type>oms3</type>
<errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
<connectTimeout>60000</connectTimeout>
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
</property>
<property>
<name>type</name>
<value>biz.stock.mall.upload</value>
</property>
<property>
<name>batchId</name>
<value>%X{batchId}</value>
</property>
<property>
<name>oper</name>
<value>%X{oper}</value>
</property>
<property>
<name>storeId</name>
<value>%X{storeId}</value>
</property>
<property>
<name>storeName</name>
<value>%X{storeName}</value>
</property>
<property>
<name>productCode</name>
<value>%X{productCode}</value>
</property>
<property>
<name>skuCode</name>
<value>%X{skuCode}</value>
</property>
<property>
<name>status</name>
<value>%X{status}</value>
</property>
<property>
<name>quantity</name>
<value>%X{quantity}</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
<appender name="oms_stock_sync"
class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>${es_url:-${es_url_default}}</url>
<index>stock-sync-%date{yyyy-MM-dd}</index>
<type>oms3</type>
<errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
<connectTimeout>60000</connectTimeout>
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
</property>
<property>
<name>type</name>
<value>biz.stock.sync</value>
</property>
<property>
<name>level</name>
<value>%level</value>
</property>
<property>
<name>batchId</name>
<value>%X{batchId}</value>
</property>
<property>
<name>warehouseId</name>
<value>%X{warehouseId}</value>
</property>
<property>
<name>warehouseCode</name>
<value>%X{warehouseCode}</value>
</property>
<property>
<name>warehouseName</name>
<value>%X{warehouseName}</value>
</property>
<property>
<name>skuCode</name>
<value>%X{skuCode}</value>
</property>
<property>
<name>quantity</name>
<value>%X{quantity}</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
<appender name="oms_translate_order"
class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>${es_url:-${es_url_default}}</url>
<index>translate-order-%date{yyyy-MM-dd}</index>
<type>oms3</type>
<errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
<connectTimeout>60000</connectTimeout>
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
</property>
<property>
<name>type</name>
<value>biz.translate.order</value>
</property>
<property>
<name>level</name>
<value>%level</value>
</property>
<property>
<name>batchId</name>
<value>%X{batchId}</value>
</property>
<property>
<name>tradeId</name>
<value>%X{tradeId}</value>
</property>
<property>
<name>storeId</name>
<value>%X{storeId}</value>
</property>
<property>
<name>storeName</name>
<value>%X{storeName}</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
<appender name="oms_translate_refund"
class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>${es_url:-${es_url_default}}</url>
<index>translate-refund-%date{yyyy-MM-dd}</index>
<type>oms3</type>
<errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
<connectTimeout>60000</connectTimeout>
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
</property>
<property>
<name>type</name>
<value>biz.translate.refund</value>
</property>
<property>
<name>level</name>
<value>%level</value>
</property>
<property>
<name>batchId</name>
<value>%X{batchId}</value>
</property>
<property>
<name>tradeId</name>
<value>%X{tradeId}</value>
</property>
<property>
<name>refundId</name>
<value>%X{refundId}</value>
</property>
<property>
<name>storeId</name>
<value>%X{storeId}</value>
</property>
<property>
<name>storeName</name>
<value>%X{storeName}</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
<appender name="oms_translate_exchange"
class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>${es_url:-${es_url_default}}</url>
<index>translate-exchange-%date{yyyy-MM-dd}</index>
<type>oms3</type>
<errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
<connectTimeout>60000</connectTimeout>
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
</property>
<property>
<name>type</name>
<value>biz.translate.exchange</value>
</property>
<property>
<name>level</name>
<value>%level</value>
</property>
<property>
<name>batchId</name>
<value>%X{batchId}</value>
</property>
<property>
<name>tradeId</name>
<value>%X{tradeId}</value>
</property>
<property>
<name>exchangeId</name>
<value>%X{exchangeId}</value>
</property>
<property>
<name>storeId</name>
<value>%X{storeId}</value>
</property>
<property>
<name>storeName</name>
<value>%X{storeName}</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
<appender name="oms_dispatch"
class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>${es_url:-${es_url_default}}</url>
<index>dispatch-%date{yyyy-MM-dd}</index>
<type>oms3</type>
<errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
<connectTimeout>60000</connectTimeout>
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
</property>
<property>
<name>type</name>
<value>biz.dispatch</value>
</property>
<property>
<name>level</name>
<value>%level</value>
</property>
<property>
<name>tradeId</name>
<value>%X{tradeId}</value>
</property>
<property>
<name>batchId</name>
<value>%X{batchId}</value>
</property>
<property>
<name>salesOrderCode</name>
<value>%X{salesOrderCode}</value>
</property>
<property>
<name>storeId</name>
<value>%X{storeId}</value>
</property>
<property>
<name>storeName</name>
<value>%X{storeName}</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
<appender name="oms_mall" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>${es_url:-${es_url_default}}</url>
<index>mall-%date{yyyy-MM-dd}</index>
<type>oms3</type>
<errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
<connectTimeout>60000</connectTimeout>
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
</property>
<property>
<name>type</name>
<value>mall</value>
</property>
<property>
<name>level</name>
<value>%level</value>
</property>
<property>
<name>storeId</name>
<value>%X{storeId}</value>
</property>
<property>
<name>storeName</name>
<value>%X{storeName}</value>
</property>
<property>
<name>apiName</name>
<value>%X{apiName}</value>
</property>
<property>
<name>isSuccess</name>
<value>%X{isSuccess}</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
<appender name="oms_sms" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>${es_url:-${es_url_default}}</url>
<index>sms-%date{yyyy-MM-dd}</index>
<type>oms3</type>
<errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
<connectTimeout>60000</connectTimeout>
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
</property>
<property>
<name>type</name>
<value>sms</value>
</property>
<property>
<name>level</name>
<value>%level</value>
</property>
<property>
<name>storeId</name>
<value>%X{storeId}</value>
</property>
<property>
<name>storeName</name>
<value>%X{storeName}</value>
</property>
<property>
<name>mobile</name>
<value>%X{mobile}</value>
</property>
<property>
<name>signName</name>
<value>%X{signName}</value>
</property>
<property>
<name>templateCode</name>
<value>%X{templateCode}</value>
</property>
<property>
<name>apiName</name>
<value>%X{apiName}</value>
</property>
<property>
<name>isSuccess</name>
<value>%X{isSuccess}</value>
</property>
<property>
<name>isSmsSendLog</name>
<value>%X{isSmsSendLog}</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
<appender name="oms_invoice" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>${es_url:-${es_url_default}}</url>
<index>invoice-%date{yyyy-MM-dd}</index>
<type>oms3</type>
<errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
<connectTimeout>60000</connectTimeout>
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
</property>
<property>
<name>type</name>
<value>invoice</value>
</property>
<property>
<name>level</name>
<value>%level</value>
</property>
<property>
<name>storeId</name>
<value>%X{storeId}</value>
</property>
<property>
<name>storeName</name>
<value>%X{storeName}</value>
</property>
<property>
<name>apiName</name>
<value>%X{apiName}</value>
</property>
<property>
<name>isSuccess</name>
<value>%X{isSuccess}</value>
</property>
<property>
<name>templateName</name>
<value>%X{templateName}</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
<appender name="oms_third_part" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>${es_url:-${es_url_default}}</url>
<index>third-part-%date{yyyy-MM-dd}</index>
<type>oms3</type>
<errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
<connectTimeout>60000</connectTimeout>
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
</property>
<property>
<name>type</name>
<value>third-part</value>
</property>
<property>
<name>level</name>
<value>%level</value>
</property>
<property>
<name>systemName</name>
<value>%X{systemName}</value>
</property>
<property>
<name>systemType</name>
<value>%X{systemType}</value>
</property>
<property>
<name>requestCaller</name>
<value>%X{requestCaller}</value>
</property>
<property>
<name>apiName</name>
<value>%X{apiName}</value>
</property>
<property>
<name>isSuccess</name>
<value>%X{isSuccess}</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
<appender name="oms_internal" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>${es_url:-${es_url_default}}</url>
<index>internal-%date{yyyy-MM-dd}</index>
<type>oms3</type>
<errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
<connectTimeout>60000</connectTimeout>
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
</property>
<property>
<name>type</name>
<value>internal</value>
</property>
<property>
<name>level</name>
<value>%level</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>
<appender name="file_out" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${log_file:-${log_file_default}}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${log_file_pattern:-${log_file_pattern_default}}</fileNamePattern>
<maxFileSize>${log_file_max_size:-${log_file_max_size_default}}</maxFileSize>
<maxHistory>${log_file_max_history:-${log_file_max_history_default}}</maxHistory>
<totalSizeCap>${log_file_max_total_size:-${log_file_max_total_size_default}}</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${log_pattern:-${log_pattern_default}}</pattern>
</encoder>
</appender>
<appender name="sql_file_out" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>log/sql.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>log/sql.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxFileSize>${log_file_max_size:-${log_file_max_size_default}}</maxFileSize>
<maxHistory>${log_file_max_history:-${log_file_max_history_default}}</maxHistory>
<totalSizeCap>${log_file_max_total_size:-${log_file_max_total_size_default}}</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>${log_pattern:-${log_pattern_default}}</pattern>
</encoder>
</appender>
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${log_pattern:-${log_pattern_default}}</pattern>
</encoder>
</appender>
<logger name="com.greatonce.oms" level="info" additivity="false">
<appender-ref ref="file_out"/>
</logger>
<logger name="com.greatonce.oms.bridge.mall.impl.taobao.cloudpush.mappers" level="info"
additivity="false">
<appender-ref ref="sql_file_out"/>
</logger>
<logger name="com.greatonce.oms.dao" level="info" additivity="false">
<appender-ref ref="sql_file_out"/>
</logger>
<logger name="oms.biz.logging" level="info" additivity="false">
<appender-ref ref="oms_biz"/>
</logger>
<logger name="oms.service.logging.stock.mall.upload" level="info" additivity="false">
<appender-ref ref="oms_stock_mall_upload"/>
</logger>
<logger name="oms.service.logging.stock.sync" level="info" additivity="false">
<appender-ref ref="oms_stock_sync"/>
</logger>
<logger name="oms.service.logging.product.mall.mapping" level="info" additivity="false">
<appender-ref ref="oms_product_mall_mapping"/>
</logger>
<logger name="oms.service.logging.translate.order" level="debug" additivity="false">
<appender-ref ref="oms_translate_order"/>
</logger>
<logger name="oms.service.logging.translate.refund" level="debug" additivity="false">
<appender-ref ref="oms_translate_refund"/>
</logger>
<logger name="oms.service.logging.translate.exchange" level="debug" additivity="false">
<appender-ref ref="oms_translate_exchange"/>
</logger>
<logger name="oms.service.logging.dispatch" level="debug" additivity="false">
<appender-ref ref="oms_dispatch"/>
</logger>
<logger name="oms.service.logging.mall" level="info" additivity="false">
<appender-ref ref="oms_mall"/>
</logger>
<logger name="oms.service.logging.sms" level="info" additivity="false">
<appender-ref ref="oms_sms"/>
</logger>
<logger name="oms.service.logging.invoice" level="info" additivity="false">
<appender-ref ref="oms_invoice"/>
</logger>
<logger name="oms.service.logging.thirdPart" level="info" additivity="false">
<appender-ref ref="oms_third_part"/>
</logger>
<logger name="oms.service.logging.internal" level="info" additivity="false">
<appender-ref ref="oms_internal"/>
</logger>
<root level="info">
<appender-ref ref="file_out"/>
</root>
</included>
logback-web-prod.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="log_file" value="log/web.log"/>
<property name="log_file_pattern" value="log/web.%d{yyyy-MM-dd}.%i.log"/>
<property name="es_url" value="http://${es.host}:${es.port}/_bulk"/>
<include resource="com/greatonce/oms/util/logging/base.xml"/>
</configuration>
MDC
参考: https://blog.csdn.net/qq_36801710/article/details/79737359
示例代码:
OmsLogger
package com.greatonce.oms.util.logging;
import com.greatonce.core.util.Assert;
import org.slf4j.Logger;
import org.slf4j.MDC;
/**
* OmsLogger
*
* @author Shenzhen Greatonce Co Ltd
* @author ginta
* @version 2018/4/28
*/
public abstract class OmsLogger {
/**
* 获取日志
*/
protected abstract Logger getLogger();
private String preProcessMessage(String message) {
return Assert.isEmpty(message) ? "" : message;
}
protected void putMDCItem(String key, Object value) {
if (!Assert.isNull(key) && !Assert.isNull(value)) {
MDC.put(key, String.valueOf(value));
}
}
protected void doInfo(String message, Object... args) {
getLogger().info(preProcessMessage(message), args);
cleanMDC();
}
protected void doWarn(String message, Object... args) {
getLogger().warn(preProcessMessage(message), args);
cleanMDC();
}
protected void doDebug(String message, Object... args) {
getLogger().debug(preProcessMessage(message), args);
cleanMDC();
}
protected void doError(String message, Object... args) {
getLogger().error(preProcessMessage(message), args);
cleanMDC();
}
protected void doError(String message, Throwable throwable) {
getLogger().error(message, throwable);
cleanMDC();
}
protected void doTrace(String message, Object... args) {
getLogger().trace(preProcessMessage(message), args);
cleanMDC();
}
public boolean isTraceEnabled() {
return getLogger().isTraceEnabled();
}
public boolean isDebugEnabled() {
return getLogger().isDebugEnabled();
}
public boolean isInfoEnabled() {
return getLogger().isInfoEnabled();
}
public boolean isWarnEnabled() {
return getLogger().isWarnEnabled();
}
public boolean isErrorEnabled() {
return getLogger().isErrorEnabled();
}
protected void cleanMDC() {
}
}
BizLogger
package com.greatonce.oms.util.logging;
import com.greatonce.oms.domain.enums.OmsModule;
import com.greatonce.oms.util.BizContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
/**
* 业务日志.
*
* @author buer
*/
public class BizLogger extends OmsLogger {
public static final String ADD = "新增";
public static final String AUDIT = "审核";
public static final String RESET_AUDIT = "重置审核";
public static final String REVIEW = "复核";
public static final String UPDATE = "修改";
public static final String DELETE = "删除";
public static final String CANCEL = "取消";
public static final String DELIVERY = "发货";
public static final String ENTRY = "入库";
public static final String DISPATCH = "配货";
public static final String AUTO_DISPATCH = "自动配货";
public static final String CANCEL_DISPATCH = "取消配货";
public static final String MALL_DELIVERY = "回传发货";
public static final String MALL_RESET_EXPRESS = "回传快递修改";
public static final String ENABLE = "启用";
public static final String DISABLE = "禁用";
public static final String INVALID = "作废";
public static final String INVALID_DETAIL = "作废明细";
public static final String CONFIM = "确认";
public static final String FINISH = "完结";
public static final String BEGIN = "开始";
public static final String END = "结束";
public static final String NOTICE_WMS = "通知WMS";
public static final String SIGN = "签收";
public static final String SCAN = "扫描";
public static final String THIRD_PART_SYNCHRONIZE = "外部同步";
public static final String POST = "过账";
public static final String TRANSFER = "推送";
public static final String RETURN = "退回";
private static final String BIZ_ID = "bizid";
private static final String DETAIL_ID = "bizdtl";
private static final String ACTION = "act";
private static final String OPER = "oper";
private final Logger logger;
private final String module;
public BizLogger(final OmsModule module) {
this.module = module.toString();
this.logger = getLogger(this.module);
}
public BizLogger(String module) {
this.module = module;
this.logger = getLogger(this.module);
}
private Logger getLogger(String type) {
return LoggerFactory.getLogger("oms.biz.logging." + type.toLowerCase().replace("_", "."));
}
public void log(Long id, Long detailId, String action, String message, Object... args) {
putMDC(id, detailId, action);
this.doInfo(message, args);
}
public void log(Long id, Long detailId, String action) {
log(id, detailId, action, null);
}
public void log(Long id, String action, String message, Object... args) {
log(id, null, action, message, args);
}
public void log(Long id, String action) {
log(id, action, null);
}
public void log(String action, String message, Object... args) {
log(null, action, message, args);
}
protected void putMDC(Long id, Long detailId, String action) {
putMDCItem(BIZ_ID, id);
putMDCItem(DETAIL_ID, detailId);
putMDCItem(OPER, BizContext.getNickname());
putMDCItem(ACTION, action);
}
@Override
protected Logger getLogger() {
return this.logger;
}
@Override
protected void cleanMDC() {
super.cleanMDC();
MDC.remove(BIZ_ID);
MDC.remove(DETAIL_ID);
MDC.remove(ACTION);
MDC.remove(OPER);
}
}
base.xml中片段
<appender name="oms_biz" class="com.internetitem.logback.elasticsearch.ElasticsearchAppender">
<url>${es_url:-${es_url_default}}</url>
<index>biz-logs-%date{yyyy-MM-dd}</index>
<type>oms3</type>
<errorLoggerName>com.greatonce.oms.internal.error</errorLoggerName>
<connectTimeout>60000</connectTimeout>
<properties>
<property>
<name>host</name>
<value>${HOSTNAME}</value>
</property>
<property>
<name>type</name>
<value>biz</value>
</property>
<property>
<name>logger</name>
<value>%logger</value>
</property>
<property>
<name>thread</name>
<value>%thread</value>
</property>
<property>
<name>bizid</name>
<value>%X{bizid}</value>
</property>
<property>
<name>bizdtl</name>
<value>%X{bizdtl}</value>
</property>
<property>
<name>act</name>
<value>%X{act}</value>
</property>
<property>
<name>oper</name>
<value>%X{oper}</value>
</property>
</properties>
<headers>
<header>
<name>Content-Type</name>
<value>application/json</value>
</header>
</headers>
</appender>