I have an app for android that has a customized log format that I prefix with the Date for better searching. Currently I'm using SimpleDateFormat but the results are inconsistent.
A few examples of this inconsistency, it is giving me:
2018/10/11 10:40:21.229 ____Verbose:
2018/0010/0011 0010:40:21.230 ____Verbose:
2018/10/11 10:40:21.232 ____Verbose:
...
2018/10/11 10:40:42.784 ____Verbose:
2018/10/11 010:040:042.786 ____Verbose:
2018/10/11 10:40:42.786 ____Verbose:
The code I'm using is:
private static final DateFormat LOGDATEFULL = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
private static String strErrorLevel(int errorLevel){
if (errorLevel == VERBOSE ) return " ____ VERBOSE: ";
if (errorLevel == DEBUG ) return " ____ DEBUG : ";
if (errorLevel == INFO ) return " _.._ INFO : ";
if (errorLevel == WARN ) return " _--_ WARN : ";
if (errorLevel == ERROR ) return " _!!_ ERROR : ";
if (errorLevel == ANALYTICS) return " _++_ ANALYTC: ";
return " _**_ ASSERT : ";
}
public static void customLog(String message, int level){
Date currDate = Calendar.getInstance().getTime();
Log.d(LOGDATEFULL.format(currDate) + " " + strErrorLevel(level) + message);
}
My system Locale is Portuguese Brazilian (pt-BR), and this occurs both when called from the main thread and calling from other threads.
Is there any other solution besides creating a function to manually make the string?
By the way, it occurs even in generating names for files like 'Output_2018-010-11.txt.
Answer: It was really what Tom G and lelloman pointed, in all the places that I used SimpleDateFormat, this one was the only that I had, which might be accessed by more than one thread at a time. I chose Tom G answer for the practicality of implementing in the existing code.
Thanks