mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-04 20:46:28 +01:00
make logging respect force-on preference
This commit is contained in:
parent
788113ee28
commit
73a469a428
4 changed files with 39 additions and 62 deletions
|
@ -39,49 +39,9 @@ import org.eehouse.android.xw4.loc.LocUtils;
|
|||
|
||||
public class DbgUtils {
|
||||
private static final String TAG = DbgUtils.class.getSimpleName();
|
||||
private static boolean s_doLog = BuildConfig.DEBUG;
|
||||
|
||||
private enum LogType { ERROR, WARN, DEBUG, INFO };
|
||||
|
||||
private static Time s_time = new Time();
|
||||
|
||||
public static void logEnable( boolean enable )
|
||||
{
|
||||
s_doLog = enable;
|
||||
}
|
||||
|
||||
public static void logEnable( Context context )
|
||||
{
|
||||
boolean on = BuildConfig.DEBUG ||
|
||||
XWPrefs.getPrefsBoolean( context, R.string.key_logging_on, false );
|
||||
logEnable( on );
|
||||
}
|
||||
|
||||
private static void callLog( LogType lt, String tag, String fmt,
|
||||
Object... args )
|
||||
{
|
||||
if ( s_doLog ) {
|
||||
String msg = new Formatter().format( fmt, args ).toString();
|
||||
switch( lt ) {
|
||||
case DEBUG:
|
||||
Log.d( tag, msg );
|
||||
break;
|
||||
case WARN:
|
||||
Log.w( tag, msg );
|
||||
break;
|
||||
case INFO:
|
||||
Log.i( tag, msg );
|
||||
break;
|
||||
case ERROR:
|
||||
Log.e( tag, msg );
|
||||
break;
|
||||
default:
|
||||
Assert.fail();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void showf( String format, Object... args )
|
||||
{
|
||||
showf( XWApp.getContext(), format, args );
|
||||
|
@ -121,7 +81,7 @@ public class DbgUtils {
|
|||
|
||||
public static void printStack( String tag, StackTraceElement[] trace )
|
||||
{
|
||||
if ( s_doLog && null != trace ) {
|
||||
if ( null != trace ) {
|
||||
// 1: skip printStack etc.
|
||||
for ( int ii = 1; ii < trace.length; ++ii ) {
|
||||
Log.d( tag, "ste %d: %s", ii, trace[ii].toString() );
|
||||
|
@ -131,9 +91,7 @@ public class DbgUtils {
|
|||
|
||||
public static void printStack( String tag )
|
||||
{
|
||||
if ( s_doLog ) {
|
||||
printStack( tag, Thread.currentThread().getStackTrace() );
|
||||
}
|
||||
printStack( tag, Thread.currentThread().getStackTrace() );
|
||||
}
|
||||
|
||||
public static void printStack( String tag, Exception ex )
|
||||
|
@ -156,10 +114,8 @@ public class DbgUtils {
|
|||
|
||||
public static void dumpCursor( Cursor cursor )
|
||||
{
|
||||
if ( s_doLog ) {
|
||||
String dump = DatabaseUtils.dumpCursorToString( cursor );
|
||||
Log.i( TAG, "cursor: %s", dump );
|
||||
}
|
||||
String dump = DatabaseUtils.dumpCursorToString( cursor );
|
||||
Log.i( TAG, "cursor: %s", dump );
|
||||
}
|
||||
|
||||
// public static String secondsToDateStr( long seconds )
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
package org.eehouse.android.xw4;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.Formatter;
|
||||
|
||||
public class Log {
|
||||
|
@ -27,27 +29,48 @@ public class Log {
|
|||
private static final boolean LOGGING_ENABLED
|
||||
= BuildConfig.DEBUG || !BuildConfig.IS_TAGGED_BUILD;
|
||||
private static final boolean ERROR_LOGGING_ENABLED = true;
|
||||
private static boolean sEnabled = BuildConfig.DEBUG;
|
||||
|
||||
public static void d( String tag, String fmt, Object... args ) {
|
||||
if ( LOGGING_ENABLED ) {
|
||||
public static void enable( boolean newVal )
|
||||
{
|
||||
sEnabled = newVal;
|
||||
}
|
||||
|
||||
public static void enable( Context context )
|
||||
{
|
||||
boolean on = LOGGING_ENABLED ||
|
||||
XWPrefs.getPrefsBoolean( context, R.string.key_logging_on,
|
||||
LOGGING_ENABLED );
|
||||
enable( on );
|
||||
}
|
||||
|
||||
public static void d( String tag, String fmt, Object... args )
|
||||
{
|
||||
if ( sEnabled ) {
|
||||
String str = new Formatter().format( fmt, args ).toString();
|
||||
android.util.Log.d( PRE_TAG + tag, str );
|
||||
}
|
||||
}
|
||||
public static void w( String tag, String fmt, Object... args ) {
|
||||
if ( LOGGING_ENABLED ) {
|
||||
|
||||
public static void w( String tag, String fmt, Object... args )
|
||||
{
|
||||
if ( sEnabled ) {
|
||||
String str = new Formatter().format( fmt, args ).toString();
|
||||
android.util.Log.w( PRE_TAG + tag, str );
|
||||
}
|
||||
}
|
||||
public static void e( String tag, String fmt, Object... args ) {
|
||||
|
||||
public static void e( String tag, String fmt, Object... args )
|
||||
{
|
||||
if ( ERROR_LOGGING_ENABLED ) {
|
||||
String str = new Formatter().format( fmt, args ).toString();
|
||||
android.util.Log.e( PRE_TAG + tag, str );
|
||||
}
|
||||
}
|
||||
public static void i( String tag, String fmt, Object... args ) {
|
||||
if ( LOGGING_ENABLED ) {
|
||||
|
||||
public static void i( String tag, String fmt, Object... args )
|
||||
{
|
||||
if ( sEnabled ) {
|
||||
String str = new Formatter().format( fmt, args ).toString();
|
||||
android.util.Log.i( PRE_TAG + tag, str );
|
||||
}
|
||||
|
@ -55,7 +78,7 @@ public class Log {
|
|||
|
||||
public static void ex( String tag, Exception exception )
|
||||
{
|
||||
if ( LOGGING_ENABLED ) {
|
||||
if ( sEnabled ) {
|
||||
w( tag, "Exception: %s", exception.toString() );
|
||||
DbgUtils.printStack( tag, exception.getStackTrace() );
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ public class PrefsDelegate extends DelegateBase
|
|||
if ( s_keysHash.containsKey( key ) ) {
|
||||
switch( s_keysHash.get( key ) ) {
|
||||
case R.string.key_logging_on:
|
||||
DbgUtils.logEnable( sp.getBoolean( key, false ) );
|
||||
Log.enable( sp.getBoolean( key, false ) );
|
||||
break;
|
||||
case R.string.key_show_sms:
|
||||
SMSService.smsToastEnable( sp.getBoolean( key, false ) );
|
||||
|
|
|
@ -71,11 +71,9 @@ public class XWApp extends Application implements LifecycleObserver {
|
|||
|
||||
ProcessLifecycleOwner.get().getLifecycle().addObserver(this);
|
||||
|
||||
// This one line should always get logged even if logging is
|
||||
// off -- because logging is on by default until logEnable is
|
||||
// called.
|
||||
Log.i( TAG, "onCreate(); git_rev=%s", getString( R.string.git_rev ) );
|
||||
DbgUtils.logEnable( this );
|
||||
android.util.Log.i( TAG, "onCreate(); git_rev="
|
||||
+ getString( R.string.git_rev ) );
|
||||
Log.enable( this );
|
||||
|
||||
OnBootReceiver.startTimers( this );
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue