Git Product home page Git Product logo

Comments (2)

hykilpikonna avatar hykilpikonna commented on June 13, 2024

通过过滤系统输出实现了...
但是这样性能太差了!
毕竟这样每次系统输出的时候都要吧所有想要禁用的ST判断一遍_(:з」∠)_
有没有官方的开关哇...

private static SystemOutFilter systemOutFilter = null;
public static void enableSystemOutFilter()
{
    if (systemOutFilter != null) return;
    System.setOut(systemOutFilter = new SystemOutFilter(System.out));
}

/**
 * 关闭Jboot的SQL指令信息报告
 */
public static void disableSqlReport()
{
    enableSystemOutFilter();
    systemOutFilter.getDisabledStackTraces().add("com.jfinal.plugin.activerecord.SqlReporter.invoke:56");
}

/**
 * 系统输出过滤,
 * 用来防止Jboot输出Sql指令信息刷屏什么的_(:з」∠)_
 */
public static class SystemOutFilter extends PrintStream
{
    @Getter
    private ArrayList<String> disabledStackTraces = new ArrayList<>();

    private SystemOutFilter(OutputStream out)
    {
        super(out);
    }

    /**
     * 过滤StackTrace
     * @return 是否通过过滤
     */
    private boolean verify()
    {
        StackTraceElement stackTrace = Thread.currentThread().getStackTrace()[3];

        String stClass = stackTrace.getClassName();
        String stMethod = stackTrace.getMethodName();
        String stLine = stackTrace.getLineNumber() + "";
        String stFull = stClass + "." + stMethod + ":" + stLine;

        for (String disabledStackTrace : disabledStackTraces)
            if (disabledStackTrace.equals(stFull)) return false;
        return true;
    }

    @Override
    public void println(String s)
    {
        if (verify()) super.println(s);
    }
}

from jboot.

yangfuhai avatar yangfuhai commented on June 13, 2024

配置 jboot.mode = product 就自动关闭了,这个输出只是在debug模式下才会输出。默认情况下是debug

from jboot.

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.