slf4j

Log4j2/Slf4j and Java 11

自作多情 提交于 2020-12-05 06:59:22
问题 I'm currently trying to build an app with log4j/slf4j and java 11 but I'm facing this problem at runtime: 2018-12-10 22:09:27,225 main INFO Cannot initialize scripting support because this JRE does not support it. java.lang.NoClassDefFoundError: javax/script/ScriptEngineManager at org.apache.logging.log4j.core@2.11.1/org.apache.logging.log4j.core.script.ScriptManager.<init>(ScriptManager.java:69) at org.apache.logging.log4j.core@2.11.1/org.apache.logging.log4j.core.config

Tushare-SDK

泄露秘密 提交于 2020-12-04 10:12:39
tushare一直没有出java的sdk,好在出了http协议的api.本项目根据http的api封装而成 gitee地址 https://gitee.com/ichiva/tushare-sdk.git 项目目录 定义实体类 @Getter @Setter public class TuTable implements Serializable { private String[] fields; private String[][] items; } 定义获取数据的接口 /** * tu 数据 */ public interface TuData { /** * 获取数据 * @return */ Optional<TuTable> get(); } 定义api请求和应答 请求 @Data public class TuRequest implements Serializable { /** * 接口名 */ private String api; private String token; /** * 输入参数 */ private Map<String,String> params; /** * 输出参数 */ private String[] fields; /** * 输出参数描述 */ private String[] fieldsName; /** * 接口描述

配置 mybatis 打印出执行的 sql 及返回的结果集

此生再无相见时 提交于 2020-12-03 01:25:01
在开发过程中, 经常会遇到想要看到应用所执行的 sql 这样的需求. 比如你写了一个查询的功能, 但查询出来的结果与你预期的不符合, 你想搞清楚到底哪里出了问题, 你自然需要看看所执行的 sql 语句, 必要的话甚至还要亲自拷贝到数据库里去查查. 自然, 这就要求应用要能把执行的 sql 输出出来. 以常用的 mybatis 框架为例, 来看一个最终的效果: 14:48 ==> Preparing: select * from user where id = ? 14:48 ==> Parameters: 1(Integer) 14:48 <== Total: 1 另注: 这里的日志布局我启用了一种极简的风格, 只有"分钟:秒数", 具体见 配置简化开发阶段日志输出布局 的介绍. 那么, 在 mybatis 里, 这个要怎么做到呢? 配置 sql 输出 具体来说, 是要增加一个日志级别的配置, 将 dao(或 mapper) 包级别调整到 DEBUG . 示例: # log sql statement logging.level.net.xiaogd.sample.mybatis.dao=DEBUG 注: 上述配置建议放在你的本地开发环境配置文件中, 通常为 application-dev.properties, 关于 spring-boot 的 分环境配置 的 profile

How to handle disk full errors while logging in logback?

自作多情 提交于 2020-12-01 06:25:06
问题 I am using slf4j+logback for logging in our application. Earlier we were using jcl+log4j and moved recently. Due to the high amount of logging in our application, there is a chance of disk being full in production environment. In such cases we need to stop logging and application should work fine. What I found from the web is that we need to poll logback StatusManager for such errors. But this will add a dependency with logback for the application. For log4j, I found that we can create an

How to handle disk full errors while logging in logback?

强颜欢笑 提交于 2020-12-01 06:23:58
问题 I am using slf4j+logback for logging in our application. Earlier we were using jcl+log4j and moved recently. Due to the high amount of logging in our application, there is a chance of disk being full in production environment. In such cases we need to stop logging and application should work fine. What I found from the web is that we need to poll logback StatusManager for such errors. But this will add a dependency with logback for the application. For log4j, I found that we can create an

Spring boot - number of backup log files restricted to 7

主宰稳场 提交于 2020-11-30 10:17:23
问题 In our spring-boot project we are using slf4j for logging purpose. Below are configuration which we have added in application.properties file logging.file=/opt/logs/my_log.log logging.level.org.springframework.web=INFO logging.level.org.hibernate=INFO logging.level.nl.yestelecom.boss=DEBUG logging.level.com.github.isrsal.logging.LoggingFilter=DEBUG It generates only 7 backup files (my_log.log.1, my_log.log.2 ..., my_log.log.7) with each file of size 10.5MB and after that logging is not

(转)Java 日志框架解析(上)

青春壹個敷衍的年華 提交于 2020-11-29 11:52:26
作为Java程序员,幸运的是,Java 拥有功能和性能都非常强大的日志库;不幸的是,这样的日志库有不止一个——相信每个人都曾经迷失在JUL(Java Util Log), JCL(Commons Logging), Log4j, SLF4J, Logback,Log4j2 等等的迷宫中。在我见过的绝大多数项目中,都没有能够良好的配置和使用日志库。 这篇文章先讲述Java常见日志库的历史和关系,后续会讲日志使用的最佳实践。让我们从头(Java Util Log)开始说起吧。 Java Util Log 简称JUL,是JDK 中自带的log功能。虽然是官方自带的log lib,JUL的使用确不广泛。主要原因: JUL从JDK1.4 才开始加入(2002年),当时各种第三方log lib已经被广泛使用了 JUL早期存在性能问题,到JDK1.5上才有了不错的进步,但现在和Logback/Log4j2相比还是有所不如 JUL的功能不如Logback/Log4j2等完善,比如Output Handler就没有Logback/Log4j2的丰富,有时候需要自己来继承定制,又比如默认没有从ClassPath里加载配置文件的功能 Log4j 1.x Log4j 是在 Logback 出现之前被广泛使用的 Log Lib, 由 Gülcü 于2001年发布,后来成为Apache 基金会的顶级项目

Jvm启动,关闭及对应钩子

荒凉一梦 提交于 2020-11-27 02:25:42
很多时候应用服务启动或关闭会做一些预加载(比如缓存,定时任务启动等)或收尾处理工作(比如程序失败记录等) 1. 首先看下Spring框架服务启动加载操作实现,直接上代码 继承实现接口ApplicationListener就可以实现: import com.today.service.financereport.action.ExportReportRecordFailureAction import com.today.service.financereport.common.ReportThreadManager import com.today.service.financereport.dto.ExportReportFailureInput import org.slf4j.LoggerFactory import org.springframework.context.ApplicationListener import org.springframework.context.event.ContextRefreshedEvent import org.springframework.stereotype.Service /** * 类功能描述:容器启动监听器 * * @author WangXueXing create at 18-11-20 上午9:35 *

使用 log 占位符便利日志输出

∥☆過路亽.° 提交于 2020-11-26 09:51:56
在开发活动中, 记日志是一个很常见的操作. 记日志经常涉及到拼接字符串, 因为我们常常需要把参数的值输出出来, 同时拼上字样的提示, 这样后续查看时才好知道发生了什么. 比如这样: package net.xiaogd.sample.mybatis.controller; import lombok.extern.slf4j.Slf4j; import net.xiaogd.sample.mybatis.entity.User; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RestController; @Slf4j @RestController public class LogController { @GetMapping("/hello") public String hello(@ModelAttribute User user) { log.info("username: " + user.getUsername() + " , age: " + user.getAge());

redis读写分离之lettuce

吃可爱长大的小学妹 提交于 2020-11-23 01:57:05
问题 redis使用过程中,很多情况都是读多写少,而不管是主从、哨兵、集群,从节点都只是用来备份,为了最大化节约用户成本,我们需要利用从节点来进行读,分担主节点压力,这里我们继续上一章的jedis的读写分离,由于springboot现在redis集群默认用的是lettuce,所以介绍下lettuce读写分离 读写分离 主从读写分离 这里先建一个主从集群,1主3从,一般情况下只需要进行相关配置如下: spring: redis: host: redisMastHost port: 6379 lettuce: pool: max-active: 512 max-idle: 256 min-idle: 256 max-wait: -1 这样就可以直接注入redisTemplate,读写数据了,但是这个默认只能读写主,如果需要设置readfrom,则需要自定义factory,下面给出两种方案 方案一(适用于非aws) 只需要配置主节点,从节点会信息会自动从主节点获取 @Configuration class WriteToMasterReadFromReplicaConfiguration { @Bean public LettuceConnectionFactory redisConnectionFactory() { LettuceClientConfiguration