Coder Social home page Coder Social logo

Comments (3)

Hccake avatar Hccake commented on July 29, 2024

考虑后期优化,也欢迎 PR。

目前可以在自己的项目注册一个 AccessLogHandler 类型的 Spring Bean,重写 CustomAccessLogHandler#buildLog 方法,会覆盖默认的行为。

另外还可以通过配置 ballcat.log.access.ignore-url-patterns 对指定 url 规则忽略访问日志记录。

from ballcat.

Hccake avatar Hccake commented on July 29, 2024

先关闭此 issues, 后续讨论在 #237 内进行

from ballcat.

xiongzwen avatar xiongzwen commented on July 29, 2024

通过以下配置确实可以解决二维码被保存至数据库报错的问题

ballcat:
  log:
    access:
      ignore-url-patterns:
        - /captcha/**

感谢!根据
@Hccake
的提示,通过限制报文的长度,可以解决问题。

import com.hccake.ballcat.common.log.access.handler.AccessLogHandler;
import com.hccake.ballcat.log.handler.CustomAccessLogHandler;
import com.hccake.ballcat.log.model.entity.AccessLog;
import com.hccake.ballcat.log.service.AccessLogService;
import com.hccake.ballcat.log.thread.AccessLogSaveThread;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author SHData
 */
@Slf4j
@Configuration
public class MyCustomAccessLogHandler {
    /**
     * 重写 CustomAccessLogHandler#saveLog 方法,覆盖默认的行为。
     * params 和 RequestBody 长度超过2000 则截断
     */
    @Bean
    @ConditionalOnBean(AccessLogService.class)
    protected AccessLogHandler<AccessLog> accessLogHandler(AccessLogService accessLogService)
    {
        return new CustomAccessLogHandler(new AccessLogSaveThread(accessLogService))
        {
            /**
             * 记录日志
             * @param accessLog 访问日志
             */
            @Override
            public void saveLog(AccessLog accessLog) {
                accessLog.setReqParams(StringUtils.substring(accessLog.getReqParams(),0,2000));
                accessLog.setReqBody(StringUtils.substring(accessLog.getReqBody(),0,2000));
                super.saveLog(accessLog);
            }
        };
    }
}

from ballcat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.