Skip to content

Instantly share code, notes, and snippets.

@dotrinh-DM
Created September 14, 2022 11:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotrinh-DM/e36ac532ad766a7e6ffe7b5883391d0a to your computer and use it in GitHub Desktop.
Save dotrinh-DM/e36ac532ad766a7e6ffe7b5883391d0a to your computer and use it in GitHub Desktop.
writing log to file
public static void log_to_internal_file(String data, Context context) {
try {
// /data/data/jp.co.xxx.G3ProRemote/files
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput("debug_log.txt", Context.MODE_APPEND));
String timeStamp = new SimpleDateFormat("yyyy:MM:dd_HH:mm:ss").format(Calendar.getInstance().getTime());
outputStreamWriter.append(timeStamp + " " + data + "\n");
outputStreamWriter.close();
} catch (IOException e) {
Log.e("Exception", "File write failed: " + e);
}
}
@dotrinh-DM
Copy link
Author

usage:
log_to_internal_file("abc", getContext());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment