我已经构建了一个带有Logger类的SDK JAR项目,该类通知系统日志.
例如:
Logger.log(“error on line 123 please check”, Logger.SDK_DEBUG);
目前我可以使用的日志级别很少.
我会在发布版本中删除JAR构建过程之前我的代码中的Logger.SDK_DEBUG的所有日志消息.是否可以使用Gradle做到这一点?
最佳答案 我写了一个gradle脚本来处理项目中所有Logger行的删除.您需要在任何Gradle构建命令之前运行此命令.
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)
}
}
祝好运! 🙂