Skip to content

Commit

Permalink
V1.5.3 - Logging fixes
Browse files Browse the repository at this point in the history
fix #34 - No log files generated
* ensure logging path is created before log initialisation
* use consistent file numbering pattern AndrOBD.log.x.txt
* use .txt file extension to allow opening/viewing
* close file logging handler on app close
  * to eliminate stray lock files
  • Loading branch information
fr3ts0n committed Oct 30, 2017
1 parent 8d9dfdf commit 5525902
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
6 changes: 3 additions & 3 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
<manifest
package="com.fr3ts0n.ecu.gui.androbd"
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="10502"
android:versionCode="10503"
android:versionName="@string/app_version">

<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="25"/>
android:minSdkVersion="14"
android:targetSdkVersion="26"/>

<!-- start/stop bluetooth adapter -->
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
Expand Down
2 changes: 1 addition & 1 deletion res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<resources>
<!-- AndrOBD -->
<string name="app_name" translatable="false">AndrOBD</string>
<string name="app_version" translatable="false">V1.5.2</string>
<string name="app_version" translatable="false">V1.5.3</string>
<string name="copyright_fr3ts0n" translatable="false">&#169; 2015-2017 fr3ts0n</string>
<string name="translation_credits">Translation by fr3ts0n</string>
<string name="app_description">Android OBD vehicle diagnostics app for ELM327 bluetooth adapter</string>
Expand Down
4 changes: 2 additions & 2 deletions res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<!-- Application theme. -->
<style name="AppTheme" parent="@android:style/Theme.Holo.Light" />
<style name="AppTheme.Dark" parent="@android:style/Theme.Holo" />
<style name="AppTheme" parent="@android:style/Theme.DeviceDefault.Light.DarkActionBar" />
<style name="AppTheme.Dark" parent="@android:style/Theme.DeviceDefault" />
</resources>
23 changes: 17 additions & 6 deletions src/com/fr3ts0n/ecu/gui/androbd/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ public enum PRESELECT
private DATA_VIEW_MODE dataViewMode = DATA_VIEW_MODE.LIST;
/** AutoHider for the toolbar */
private AutoHider toolbarAutoHider;
/** log file handler */
private FileHandler logFileHandler;


/** handler for freeze frame selection */
Expand Down Expand Up @@ -676,13 +678,18 @@ protected void onCreate(Bundle savedInstanceState)
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);

// set up logging ...
String logFileName = FileHelper.getPath(this).concat(File.separator).concat("log/AndrOBD.log");
String logFileName = FileHelper.getPath(this).concat(File.separator).concat("log");
try
{
// Create new log file handler (max. 250 MB, 5 files rotated, non appending)
FileHandler hdlr = new FileHandler(logFileName, 250*1024*1024, 5, false);
// ensure log directory is available
new File(logFileName).mkdirs();
// Create new log file handler (max. 250 MB, 5 files rotated, non appending)
logFileHandler = new FileHandler( logFileName.concat("/AndrOBD.log.%g.txt"),
250*1024*1024,
5,
false);
// Set log message formatter
hdlr.setFormatter(new SimpleFormatter() {
logFileHandler.setFormatter(new SimpleFormatter() {
String format = "%1$tF\t%1$tT.%1$tL\t%4$s\t%3$s\t%5$s%n";

@Override
Expand All @@ -697,7 +704,7 @@ public synchronized String format(LogRecord lr) {
}
});
// add file logging ...
Logger.getLogger("").addHandler(hdlr);
Logger.getLogger("").addHandler(logFileHandler);
// set
setLogLevels();
}
Expand Down Expand Up @@ -1683,7 +1690,11 @@ protected void onDestroy()
getString(R.string.app_name),
getString(R.string.app_version)));

super.onDestroy();
/* remove log file handler */
Logger.getLogger("").removeHandler(logFileHandler);
logFileHandler.close();

super.onDestroy();
}

/**
Expand Down

0 comments on commit 5525902

Please sign in to comment.