So I have a post function that I do a lot of logging in when on my dev environment (mostly just to debug stuff as I make changes)
example:
log.warn("The file ${jurFile.absolutePath} has ${jurFile.length()} bytes")
When I move the code to production I do not want these logs, I used to just comment them out as I moved to production but some scripts have a lot of logging and need to be edited more than I like. It has become a hassle to comment then un-comment.
Had a great idea to wrap them in a bool and I could just change that but then the code looks sloppier
ex:
If(LogBool)
{log.warn("The file ${jurFile.absolutePath} has ${jurFile.length()} bytes")}
next great idea was to create a function that I pass in "The file ${jurFile.absolutePath} has ${jurFile.length()} bytes" and the function checks the bool and logs as needed. I have never made a function in groovy and I am not even sure if I can do that in a post function. I have tried a few things but nothing seems to work.
class Log2
{
public warn2(str)
{
if(true)
{
log.warn(str)
}
}
}
gives me this error
groovy.lang.MissingMethodException: No signature of method: static Log2.warn2() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [The file E:\EDrive\jira-home\scripts\data\TEST.txt has 2354 bytes]
Possible solutions: warn2(java.lang.String), wait(), any(), wait(long), any(groovy.lang.Closure), grep()
I have tried to qualify "str" as String and I get the same thing. What am I doing wrong?