我用一个logger类构建了一个sdk jar项目,该类通知系统日志。
例如:
logger.log(“请检查123行错误”,logger.sdk_debug);
目前我可以使用的日志级别很少。
我将在发布build时在jar构建过程之前删除代码中logger.sdk_debug中的所有日志消息。有可能和格雷德一起做吗?

最佳答案

我写了一个gradle脚本来处理项目中所有日志行的删除。您需要在任何gradle build命令之前运行此命令。

task deleteJavaDebugLogs << {
    description("This function will delete all SDK DEBUG log level from the project, be careful with it!")
    //Put your project full path for exmple 'src/main/java/myproject' , the path must be with quotes
    FileTree  javaFiles = fileTree('[your_project_path]') {
        // if you have more files that are not .java include them also.
        include '**/*.java'
    }
    String regex = "Logger.log[^,]+[^L]+(.*)Logger.SDK_DEBUG[^;];"
    javaFiles.each { File javaFile ->
        println "Start replacing regex on $javaFile.name"
        String content = javaFile.getText()
        content = content.replaceAll(regex, "")
        javaFile.setText(content)
    }
}

祝你好运!:)

08-06 07:39