Reputation: 420
For building File name i'm constructing name like below mentioned way
public static final String JSON_LOG_FILE_NAME = "JSON"
+getUserName() + System.currentTimeMillis()
+ ".txt";
this is working till yesterday and now it is giving exceptioninintializationerror. And my doubt is can use dynamic values like android device time and database values as a part of static final variable.
Upvotes: 0
Views: 1413
Reputation: 410
It doesn't make any sense to use final when you want it to be modified based on time.
You can create a final variable like "JSON" and you can use concatenation to name the file.
FOR YOUR CASE: The above logic is valid i.e The file name changes only when the class is loaded and not every time you use the variable. The value is constant and you wont find the value of time changing dynamically when ever you use it.
Upvotes: 2
Reputation:
I would suggest to use ch.qos.logback.classic.Logger
to generate file on time bases.
Here is the complete example. Hope this helps you
Logback - set log file name programmatically
Upvotes: 0