log4j 日志整合ELK
1.pom.xml 添加log4j依赖
log4j
log4j
1.2.14
2.log4j.properties 编写
### set log levels ALL
package com.v2.swcares.logstash;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Component;
import org.apache.log4j.Logger;
import java.util.Date;
/**
* @author wjw
* @Description: 用户行为日志
* @date 2018-11-21
*/
@Component("behaviorRecordLogHandler")
public class BehaviorRecordLogHandler {
private final static Logger logger = Logger.getLogger(BehaviorRecordLogHandler.class);
/**
* 行为记录写入日志
* @Title: log
* @param behaviorRecordVo
* @author: wjw
* @date: 2018年11月21日
*/
public void log(BehaviorRecordDto behaviorRecordVo) {
logger.info(JSON.toJSONString(behaviorRecordVo));
}
/**
* 行为记录写入日志
* @Title: log
* @param record 行为记录
* @param operatorName 操作人名称
* @author: wjw
* @date: 2018年11月21日
*/
public void log(String record,String operatorName) {
BehaviorRecordDto behaviorRecordVo = new BehaviorRecordDto();
behaviorRecordVo.setOperatorName(operatorName);
behaviorRecordVo.setOperatorRecord(record);
behaviorRecordVo.setOperatorTime(new Date());
log(behaviorRecordVo);
}
/**
* 行为记录写入日志
* @Title: log
* @param record 行为记录
* @param operatorName 操作人名称
* @param reassignment 操作备注
* @author: wjw
* @date: 2018年11月21日
*/
public void logRemark(String record,String operatorName,String reassignment) {
BehaviorRecordDto behaviorRecordVo = new BehaviorRecordDto();
behaviorRecordVo.setOperatorName(operatorName);
behaviorRecordVo.setOperatorRecord(record);
behaviorRecordVo.setOperatorTime(new Date());
behaviorRecordVo.setOperatorMask(reassignment);
log(behaviorRecordVo);
}}
【log4j 日志整合ELK】4.logstash配置文件编写
input {
# For detail config for log4j as input,
# See: https://www.elastic.co/guide/en/logstash/current/plugins-inputs-log4j.html
log4j {
host => "0.0.0.0"
port => 4561
}
}
filter {
#Only matched data are send to output.
}
output {
# For detail config for elasticsearch as output,
# See: https://www.elastic.co/guide/en/logstash/current/plugins-outputs-elasticsearch.html
elasticsearch {
action => "index"#The operation on ES
hosts=> "116.196.117.183:9200"#ElasticSearch host, can be array.
index=> "tvpsi"#The index to write data to.
}
}
推荐阅读
- 日志打卡
- Java|规范的打印日志
- 感恩日志20181107
- Java内存泄漏分析系列之二(jstack生成的Thread|Java内存泄漏分析系列之二:jstack生成的Thread Dump日志结构解析)
- 临床统计学学习日志
- Spring|Spring Boot 整合 Activiti6.0.0
- 20180322【w4复盘日志】
- Hadoop|Hadoop MapReduce Job提交后的交互日志
- 晨间日志会给你带来什么()
- 20171130W8英语复盘日志