Added Log4J for logging to a file
This commit is contained in:
parent
e5ca4aea34
commit
fa69c367e5
18 changed files with 127 additions and 26 deletions
|
|
@ -62,7 +62,9 @@
|
|||
<orderEntry type="jdk" jdkName="Android API 15 Platform" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" exported="" name="GraphView-3.1.2" level="project" />
|
||||
<orderEntry type="library" exported="" name="android-logging-log4j-1.0.3" level="project" />
|
||||
<orderEntry type="library" exported="" name="support-v4-19.1.0" level="project" />
|
||||
<orderEntry type="library" exported="" name="log4j-1.2.17" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
|
|
|||
|
|
@ -24,5 +24,4 @@ dependencies {
|
|||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
// You must install or update the Support Repository through the SDK manager to use this dependency.
|
||||
compile 'com.android.support:support-v4:19.1.+'
|
||||
compile files('libs/GraphView-3.1.2.jar')
|
||||
}
|
||||
BIN
app/libs/android-logging-log4j-1.0.3.jar
Normal file
BIN
app/libs/android-logging-log4j-1.0.3.jar
Normal file
Binary file not shown.
BIN
app/libs/log4j-1.2.17.jar
Normal file
BIN
app/libs/log4j-1.2.17.jar
Normal file
Binary file not shown.
|
|
@ -10,6 +10,8 @@
|
|||
<li>SweetiePlus Icons (<a href="http://sublink.ca/">http://sublink.ca/</a>)</li>
|
||||
<li>DynamicListView (<a href="https://android.googlesource.com">https://android.googlesource.com</a>)</li>
|
||||
<li>App icon by <a href="http://icons8.com/android-icons">Icons8.com</a></li>
|
||||
<li>Android-logging-log4j (<a href="https://code.google.com/p/android-logging-log4j/">https://code.google.com/p/android-logging-log4j/</a>)</li>
|
||||
<li>Log4j (<a href="http://logging.apache.org/log4j">http://logging.apache.org/log4j</a>)</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,11 +1,15 @@
|
|||
package com.ericsson.uecontrol.core;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Base class for Ue behaviours that can be used by the executor
|
||||
*
|
||||
* Created by ezivkoc on 2014-07-15.
|
||||
*/
|
||||
public abstract class UeBehaviour {
|
||||
private static final Logger log = Logger.getLogger(UeBehaviour.class);
|
||||
|
||||
private boolean running;
|
||||
private BehaviourExecutionListener execListener;
|
||||
private DataHandledListener datahandledListener;
|
||||
|
|
@ -22,7 +26,7 @@ public abstract class UeBehaviour {
|
|||
execute();
|
||||
} catch(Exception e){
|
||||
if(execListener != null) execListener.exception(e);
|
||||
e.printStackTrace();
|
||||
log.warn(null, e);
|
||||
}
|
||||
if(execListener != null) execListener.executionStopped();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package com.ericsson.uecontrol.core;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.ericsson.uecontrol.core.util.ThroughputCalculator;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -11,7 +11,7 @@ import java.util.List;
|
|||
* Created by ezivkoc on 2014-07-15.
|
||||
*/
|
||||
public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListener {
|
||||
private static final String TAG = "UeControlExecutor";
|
||||
private static final Logger log = Logger.getLogger(UeControlExecutor.class);
|
||||
|
||||
private List<UeBehaviour> behaviours;
|
||||
private UeBehaviour currentlyActive;
|
||||
|
|
@ -64,7 +64,7 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
|||
else if (currentlyActive == null)
|
||||
currentlyActive = behaviours.get(0);
|
||||
|
||||
Log.v(TAG, "Running behaviour: " + currentlyActive.getName());
|
||||
log.info("Running behaviour: " + currentlyActive.getName());
|
||||
currentlyActive.run();
|
||||
|
||||
int index = behaviours.indexOf(currentlyActive) +1;
|
||||
|
|
@ -73,7 +73,7 @@ public class UeControlExecutor implements Runnable, UeBehaviour.DataHandledListe
|
|||
else
|
||||
currentlyActive = null;
|
||||
}
|
||||
Log.v(TAG, "Execution completed");
|
||||
log.info("Execution completed");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import android.util.Log;
|
|||
import com.ericsson.uecontrol.core.UeBehaviour;
|
||||
import com.ericsson.uecontrol.gui.util.Configurator.Configurable;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
|
|
@ -16,6 +18,7 @@ import java.net.URLConnection;
|
|||
* Created by ezivkoc on 2014-07-15.
|
||||
*/
|
||||
public class UeBehaviourFtp extends UeBehaviour {
|
||||
private static final Logger log = Logger.getLogger(UeBehaviourFtp.class);
|
||||
|
||||
@Configurable("Host")
|
||||
private String host;
|
||||
|
|
@ -30,7 +33,7 @@ public class UeBehaviourFtp extends UeBehaviour {
|
|||
@Override
|
||||
protected void execute() throws IOException {
|
||||
URL url = new URL(getFtpUrl());
|
||||
Log.v(getClass().getSimpleName(), "Downloading from FTP: " + url);
|
||||
log.debug("Downloading from FTP: " + url);
|
||||
|
||||
byte[] data = new byte[100];
|
||||
URLConnection connection = url.openConnection();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import android.util.Log;
|
|||
import com.ericsson.uecontrol.core.UeBehaviour;
|
||||
import com.ericsson.uecontrol.gui.util.Configurator.Configurable;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
|
|
@ -23,6 +25,7 @@ import java.util.regex.Pattern;
|
|||
* Created by ezivkoc on 2014-07-15.
|
||||
*/
|
||||
public class UeBehaviourSurfing extends UeBehaviour {
|
||||
private static final Logger log = Logger.getLogger(UeBehaviourSurfing.class);
|
||||
|
||||
@Configurable("Web Address")
|
||||
private String rootUrl;
|
||||
|
|
@ -50,7 +53,7 @@ public class UeBehaviourSurfing extends UeBehaviour {
|
|||
for(int i=0; i<urlList.size(); i++) {
|
||||
try {
|
||||
URL url = urlList.get(i);
|
||||
Log.v(getClass().getSimpleName(), "Downloading: " + url);
|
||||
log.debug("Downloading: " + url);
|
||||
|
||||
URLConnection connection = url.openConnection();
|
||||
connection.setUseCaches(false);
|
||||
|
|
@ -72,7 +75,7 @@ public class UeBehaviourSurfing extends UeBehaviour {
|
|||
}
|
||||
getAdditionalContent(url, content.toString(), urlList);
|
||||
}catch(IOException e){
|
||||
e.printStackTrace();
|
||||
log.warn(null, e);
|
||||
if(retException == null) retException = e;
|
||||
}
|
||||
}
|
||||
|
|
@ -100,11 +103,12 @@ public class UeBehaviourSurfing extends UeBehaviour {
|
|||
while(m.find()){
|
||||
try {
|
||||
String strUrl = m.group(1);
|
||||
log.debug("Parsing(Regex: "+pattern.pattern()+"): " + strUrl);
|
||||
URL url = new URL(baseUrl, strUrl);
|
||||
if(!urlList.contains(url))
|
||||
urlList.add(url);
|
||||
}catch(MalformedURLException e){
|
||||
e.printStackTrace();
|
||||
log.warn(null, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,10 +17,14 @@ import com.ericsson.uecontrol.gui.util.BehaviourListAdapter;
|
|||
import com.ericsson.uecontrol.gui.util.Configurator;
|
||||
import com.ericsson.uecontrol.gui.util.DynamicListView;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EditActivity extends ListActivity implements AdapterView.OnItemClickListener {
|
||||
private static final Logger log = Logger.getLogger(EditActivity.class);
|
||||
|
||||
private UeControlExecutor executor;
|
||||
private BehaviourListAdapter adapter;
|
||||
|
||||
|
|
@ -66,7 +70,7 @@ public class EditActivity extends ListActivity implements AdapterView.OnItemClic
|
|||
adapter.generateIds();
|
||||
adapter.notifyDataSetChanged();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.warn(null, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
package com.ericsson.uecontrol.gui;
|
||||
|
||||
import android.app.ActionBar;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.Handler;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.Toast;
|
||||
|
|
@ -20,8 +24,16 @@ import com.ericsson.uecontrol.gui.fragments.NavigationDrawerFragment;
|
|||
import com.ericsson.uecontrol.gui.fragments.StatusFragment;
|
||||
import com.ericsson.uecontrol.gui.util.CSVWriter;
|
||||
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public class MainActivity extends FragmentActivity {
|
||||
import java.io.File;
|
||||
|
||||
import de.mindpipe.android.logging.log4j.LogConfigurator;
|
||||
|
||||
|
||||
public class MainActivity extends FragmentActivity implements OnSharedPreferenceChangeListener{
|
||||
private static final Logger log = Logger.getLogger(MainActivity.class);
|
||||
|
||||
/**
|
||||
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
|
||||
|
|
@ -31,14 +43,18 @@ public class MainActivity extends FragmentActivity {
|
|||
private boolean backButtonPressed = false;
|
||||
|
||||
private static UeControlExecutor currentExecutor;
|
||||
private static CSVWriter logger;
|
||||
private static CSVWriter csvLogger;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
// Setup Debugging
|
||||
setupDebugLogging();
|
||||
|
||||
// Setup Main GUI
|
||||
setContentView(R.layout.activity_main);
|
||||
//navigationDrawerFragment = (NavigationDrawerFragment)
|
||||
// getFragmentManager().findFragmentById(R.id.navigation_drawer);
|
||||
statusFragment = (StatusFragment)
|
||||
|
|
@ -58,6 +74,37 @@ public class MainActivity extends FragmentActivity {
|
|||
currentExecutor.setThroughputListener(statusFragment.getThroughputListener());
|
||||
}
|
||||
|
||||
public void setupDebugLogging(){
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String path = prefs.getString("logging_path", "/sdcard/uecontrol/");
|
||||
if(!path.endsWith("/")) path += File.separator;
|
||||
|
||||
LogConfigurator logConfigurator = new LogConfigurator();
|
||||
logConfigurator.setFileName(path + "uecontrol.log");
|
||||
if(prefs.getBoolean("debug", false))
|
||||
logConfigurator.setRootLevel(Level.DEBUG);
|
||||
else
|
||||
logConfigurator.setRootLevel(Level.WARN);
|
||||
// Set log level of a specific logger
|
||||
logConfigurator.setLevel("org.apache", Level.ERROR);
|
||||
logConfigurator.configure();
|
||||
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
log.debug("Preference changed: "+key);
|
||||
if(key.equals("debug")) {
|
||||
if (sharedPreferences.getBoolean("debug", false)) {
|
||||
Logger.getRootLogger().setLevel(Level.DEBUG);
|
||||
log.info("Enabling debug logging.");
|
||||
} else {
|
||||
log.info("Disabling debug logging.");
|
||||
Logger.getRootLogger().setLevel(Level.WARN);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
|
@ -87,14 +134,14 @@ public class MainActivity extends FragmentActivity {
|
|||
if(currentExecutor.isRunning()){
|
||||
currentExecutor.terminate();
|
||||
item.setTitle(R.string.action_run);
|
||||
logger = null;
|
||||
csvLogger = null;
|
||||
}
|
||||
else {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
if(prefs.getBoolean("logging", false))
|
||||
logger = new CSVWriter(this);
|
||||
csvLogger = new CSVWriter(this);
|
||||
else
|
||||
logger = null;
|
||||
csvLogger = null;
|
||||
currentExecutor.execute();
|
||||
item.setTitle(R.string.action_stop);
|
||||
}
|
||||
|
|
@ -117,12 +164,13 @@ public class MainActivity extends FragmentActivity {
|
|||
}
|
||||
|
||||
public static void logThroughput(double downThroughput, double upThroughput) {
|
||||
if(logger == null || currentExecutor == null || currentExecutor.getRunningBehaviour() == null)
|
||||
if(csvLogger == null || currentExecutor == null || currentExecutor.getRunningBehaviour() == null)
|
||||
return;
|
||||
|
||||
logger.write(currentExecutor.getRunningBehaviour().getName(), downThroughput, upThroughput);
|
||||
csvLogger.write(currentExecutor.getRunningBehaviour().getName(), downThroughput, upThroughput);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (backButtonPressed) {
|
||||
|
|
|
|||
|
|
@ -9,10 +9,13 @@ import android.os.Bundle;
|
|||
import com.ericsson.uecontrol.R;
|
||||
import com.ericsson.uecontrol.core.UeBehaviour;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class SelectBehaviourDialog extends DialogFragment {
|
||||
private static final Logger log = Logger.getLogger(SelectBehaviourDialog.class);
|
||||
public static String[] behaviourClasses;
|
||||
public static String[] behaviourNames;
|
||||
|
||||
|
|
@ -31,7 +34,7 @@ public class SelectBehaviourDialog extends DialogFragment {
|
|||
UeBehaviour obj = (UeBehaviour) Class.forName(behaviourClasses[i]).newInstance();
|
||||
behaviourNames[i] = obj.getName();
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
log.warn(null, e);
|
||||
behaviourNames[i] = behaviourClasses[i];
|
||||
}
|
||||
}
|
||||
|
|
@ -48,7 +51,7 @@ public class SelectBehaviourDialog extends DialogFragment {
|
|||
callback.behaviourSelected(behaviourNames[which], objClass);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.warn(null, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import android.net.wifi.WifiManager;
|
|||
import android.preference.PreferenceManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
|
@ -19,6 +21,7 @@ import java.text.SimpleDateFormat;
|
|||
* Created by ezivkoc on 2014-07-30.
|
||||
*/
|
||||
public class CSVWriter {
|
||||
private static final Logger log = Logger.getLogger(CSVWriter.class);
|
||||
public static final String[] HEADINGS = new String[]{
|
||||
"Timestamp", "Behaviour", "RX Throughput(b/s)", "TX Throughput(b/s)", "RAT"
|
||||
};
|
||||
|
|
@ -36,7 +39,7 @@ public class CSVWriter {
|
|||
public CSVWriter(Context context){
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String path = prefs.getString("logging_path", "/sdcard/uecontrol/");
|
||||
if(!path.endsWith("/")) path += "/";
|
||||
if(!path.endsWith(File.separator)) path += File.separator;
|
||||
file = new File(
|
||||
path,
|
||||
"log_"+fileDateFormater.format(System.currentTimeMillis())+".log");
|
||||
|
|
@ -77,7 +80,7 @@ public class CSVWriter {
|
|||
out.println(line);
|
||||
out.close();
|
||||
} catch(IOException e){
|
||||
e.printStackTrace();
|
||||
log.warn(null, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.ericsson.uecontrol.gui.util;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
|
@ -12,6 +14,7 @@ import java.util.ArrayList;
|
|||
* Created by ezivkoc on 2014-07-24.
|
||||
*/
|
||||
public class Configurator {
|
||||
private static final Logger log = Logger.getLogger(Configurator.class);
|
||||
/**
|
||||
* Sets a field in a class as externally configurable.
|
||||
*/
|
||||
|
|
@ -48,7 +51,7 @@ public class Configurator {
|
|||
try {
|
||||
conf.add(new ConfigurationParam(f));
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
log.warn(null, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -61,7 +64,7 @@ public class Configurator {
|
|||
try {
|
||||
param.set();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
log.warn(null, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,5 +26,7 @@
|
|||
<string name="pref_logging_path">Log Path</string>
|
||||
<string name="pref_logging_path_summ">Folder where log file will be stored</string>
|
||||
<string name="title_activity_about">About</string>
|
||||
<string name="pref_debug">Debug Logging</string>
|
||||
<string name="pref_debug_summ">Enable application debug logging</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,12 @@
|
|||
android:title="@string/pref_other_title"
|
||||
android:key="pref_key_storage_settings">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="debug"
|
||||
android:title="@string/pref_debug"
|
||||
android:summary="@string/pref_debug_summ"
|
||||
android:defaultValue="false">
|
||||
</CheckBoxPreference>
|
||||
<Preference
|
||||
android:key="about"
|
||||
android:title="@string/pref_about"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue