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
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue