forked from organicmaps/organicmaps
[android] Added FileLogger class.
This commit is contained in:
parent
da2fe7b1d3
commit
2c307930ed
5 changed files with 76 additions and 6 deletions
|
@ -78,6 +78,8 @@ public class LocationService implements LocationListener, SensorEventListener, W
|
|||
{
|
||||
mApplication = application;
|
||||
|
||||
//mLogger = new FileLogger("LocationService", mApplication.getDataStoragePath());
|
||||
|
||||
mLocationManager = (LocationManager) mApplication.getSystemService(Context.LOCATION_SERVICE);
|
||||
mSensorManager = (SensorManager) mApplication.getSystemService(Context.SENSOR_SERVICE);
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ public class WifiLocation extends BroadcastReceiver
|
|||
|
||||
public WifiLocation()
|
||||
{
|
||||
//mLogger = new FileLogger("WiFiLocation", MWMApplication.get().getDataStoragePath());
|
||||
}
|
||||
|
||||
/// @return true if was started successfully.
|
||||
|
|
66
android/src/com/mapswithme/util/log/FileLogger.java
Normal file
66
android/src/com/mapswithme/util/log/FileLogger.java
Normal file
|
@ -0,0 +1,66 @@
|
|||
package com.mapswithme.util.log;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class FileLogger extends Logger
|
||||
{
|
||||
static private FileWriter m_file = null;
|
||||
static private String m_separator;
|
||||
|
||||
private void write(String str)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_file.write(tag + ": " + str + m_separator);
|
||||
m_file.flush();
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Log.e(tag, ex.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public FileLogger(String tag, String path)
|
||||
{
|
||||
this.tag = tag;
|
||||
if (m_file == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_file = new FileWriter(path + "android-logging.txt");
|
||||
m_separator = System.getProperty("line.separator");
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
Log.e(tag, ex.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void d(String message)
|
||||
{
|
||||
write("Debug: " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void e(String message)
|
||||
{
|
||||
write("Error: " + message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void d(String message, Object... args)
|
||||
{
|
||||
write("Debug: " + message + join(args));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void e(String message, Object... args)
|
||||
{
|
||||
write("Error: " + message + join(args));
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package com.mapswithme.util.log;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
public abstract class Logger
|
||||
{
|
||||
protected String tag = "MAPSWITHME";
|
||||
|
@ -11,6 +13,11 @@ public abstract class Logger
|
|||
this.tag = tag;
|
||||
}
|
||||
|
||||
static protected String join(Object ... args)
|
||||
{
|
||||
return (args != null ? TextUtils.join(", ", args) : "");
|
||||
}
|
||||
|
||||
public abstract void d(String message);
|
||||
public abstract void e(String message);
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.mapswithme.util.log;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
public class SimpleLogger extends Logger
|
||||
|
@ -32,11 +31,6 @@ public class SimpleLogger extends Logger
|
|||
Log.e(tag, message + join(args));
|
||||
}
|
||||
|
||||
private static String join(Object ... args)
|
||||
{
|
||||
return (args != null ? TextUtils.join(", ", args) : "");
|
||||
}
|
||||
|
||||
private SimpleLogger() {}
|
||||
private SimpleLogger(String tag) { super(tag); }
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue