logback

springboot-日志框架

旧街凉风 提交于 2020-01-01 03:14:27
1、日志框架简介   对于一个应用程序来说,日志的记录是必不可少的一部分。线上的问题追踪,基于日志业务逻辑统计分析等都离不开日志。java领域存在许多已经写好成熟的日志框架,经常使用的有JCL(jakarta Commons logging), SLF4J(simple Logging facade java), jboss-logging, log4j, JUL(java.util.logging), log4j2, logback等。   从实现来说,java框架分为两种,一种是日志门面(日志的抽象层)和日志实现,所以我们在选日志框架的时候,一般都是选一个日志门面,然后再选一个日志实现。其中,日志门面包括JCL(jakarta Commons logging), SLF4J(simple Logging facade java), jboss-logging等,而日志实现则包括 log4j, JUL(java.util.logging), log4j2, logback。    Spring框架默认使用的就是JCL, 实现层可以选log4j或者log4j2,而Spring boot选用的是 SLF4J和logback 2、日志框架之间的关系    因为日志框架之间没用形成统一的接口,所我们在选日志门面和日志实现的时候不能选错。而日志抽象接口也基本分为两大阵营了,一个是JCL

SpringBoot基础系列-使用日志

て烟熏妆下的殇ゞ 提交于 2020-01-01 03:12:58
原创作品,可以转载,但是请标注出处地址: https://www.cnblogs.com/V1haoge/p/9996897.html SpringBoot基础系列-使用日志 概述 SpringBoot使用Common Logging进行日志操作,Common Logging是一个日志功能框架,没有具体的实现,具体的日志操作需要具体的日志框架来实现。 常用的日志框架包括:JUL(Java Util Logging)、Log4J2、Logback。 默认情况下,使用的是Logback作为底层实现。 日志格式 SpringBoot的默认的日志格式如下: 2018-11-21 10:23:34.966 INFO 12588 --- [ restartedMain] c.e.s.SpringbootdemoApplication : Starting SpringbootdemoApplication on PC-20170621WOWM with PID 12588 (F:\Code\etongdai\etongdai-reactor\springbootdemo\target\classes started by Administrator in F:\Code\etongdai\etongdai-reactor\springbootdemo) 2018-11-21 10:23:34

docker部署elk日志采集系统(kafka方式)

你说的曾经没有我的故事 提交于 2020-01-01 03:11:23
一、logback + elk,tcp方式发送 环境搭建参考上一篇博客: https://www.cnblogs.com/alan6/p/11667758.html tcp方式存在的问题:tcp方式在日志量比较大,并发量较高的情况下,可能导致日志丢失。可以考虑采用 kafka 保存日志消息,做一个流量削峰。 二、logback + kafka + elk 1、docker安装 zookeeper + kafka 拉镜像: docker pull wurstmeister/zookeeper docker pull wurstmeister/kafka 运行zookeeper: docker run -d --name zookeeper --restart always --publish 2181:2181 --volume /etc/localtime:/etc/localtime wurstmeister/zookeeper:latest 运行kafka: docker run -d --name kafka --restart always --publish 9092:9092 --link zookeeper --env KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181 \ --env KAFKA_ADVERTISED_HOST_NAME

springboot向elk写日志

只谈情不闲聊 提交于 2020-01-01 03:09:28
springboot里连接elk里的logstash,然后写指定index索引的日志,而之后使用kibana去查询和分析日志,使用elasticsearch去保存日志。 添加引用 implementation 'net.logstash.logback:logstash-logback-encoder:5.3' 添加配置 <?xml version="1.0" encoding="UTF-8"?> <configuration debug="false"> <!--定义日志文件的存储地址 勿在 LogBack 的配置中使用相对路径--> <property name="LOG_HOME" value="./logs" /> <!-- 控制台输出 --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符--> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level

Springboot 包冲突处理办法

人走茶凉 提交于 2020-01-01 01:03:28
有一次配置好springboot项目启动后,忽然发现有下边的警告: SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/E:/mavenJarOnline/ch/qos/logback/logback-classic/1.1.9/logback-classic-1.1.9.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/E:/mavenJarOnline/org/slf4j/slf4j-log4j12/1.7.22/slf4j-log4j12-1.7.22.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder] 原因分析:   上边的大概意思是说logback-classic

springboot整合elasticsearch时,slf4j版本冲突

99封情书 提交于 2020-01-01 01:03:15
使用springboot整合elasticsearch时,自带的logback和其他jar自身引入的slf4j-simple产生了冲突 SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/D:/Program%20Files/maven/repository/org/slf4j/slf4j-simple/1.7.25/slf4j-simple-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/D:/Program%20Files/maven/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl

Mask Passwords with Logback?

我与影子孤独终老i 提交于 2019-12-31 17:54:30
问题 We currently generically log all XML documents coming in and going out of our system, and some of them contain passwords in the clear. We would like to be able to configure the logback logger/appender that is doing this to do some pattern matching or similar and if it detects a password is present to replace it (with asterisks most likely). Note we don't want to filter out the log entry, we want to mask a portion of it. I would appreciate advice on how this would be done with logback. Thanks.

Configuring Grails 3 for Log4j2

♀尐吖头ヾ 提交于 2019-12-31 14:55:19
问题 We would like to use Log4j2 as the log binding with grails 3. From what I can figure out so far. We have many subordinate dependencies that use a variety of loggers, so we need to use the SLF4J API. Then, instead of letting grails / groovy / spring re-direct the SLF4J API to the Logback binding, we need to re-direct each to the Log4j2 binding. Since grails 3 uses the Logback binding, I am planning to go through each dependency in the build.gradle, exclude the Logback binding, and include the

Configuring Grails 3 for Log4j2

梦想与她 提交于 2019-12-31 14:55:17
问题 We would like to use Log4j2 as the log binding with grails 3. From what I can figure out so far. We have many subordinate dependencies that use a variety of loggers, so we need to use the SLF4J API. Then, instead of letting grails / groovy / spring re-direct the SLF4J API to the Logback binding, we need to re-direct each to the Log4j2 binding. Since grails 3 uses the Logback binding, I am planning to go through each dependency in the build.gradle, exclude the Logback binding, and include the

transmittable-thread-local在slf4j中解决MDC线程池中上下文传递

别说谁变了你拦得住时间么 提交于 2019-12-30 11:08:04
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> transmittable-thread-local以下简称:TTL 根据InheritableThreadLocal在线程池中上下文传递的问题可以知道这个threadLocal的值传递,在父子线程之间若使用了线程池的技术,会导致子线程的threadLocal信息错乱。 根据分布式追踪系统场景下,如何使用TTL 知道ttl的实现原理,通过线程池的封装,threadLocal的继承实现了traceId的传递,采用weakHashMap取代引用计数的方法实现了GC的回收防止内存泄漏。 以下具体问题具体分析,给出的是以agent方式代码无侵入接入 TTL描述了四种场景 分布式跟踪系统 日志收集记录系统上下文 Session级Cache 应用容器或上层框架跨应用代码给下层SDK传递信息 分布式跟踪系统 snowball-common里的traceId是不是TTL推荐的分布式追踪系统场景下,如何使用TTL ,根据issue的描述,文章讲的是分布式追踪相关的设计和ttl在其中的应用,而在snowball-common的问题里,是关于slf4j的MDC问题,若继续探究请进入:APM 模块 日志收集记录系统 根据InheritableThreadLocal在线程池中上下文传递的问题