package com.peacemiki.android.util;

import android.util.Log;

import com.peacemiki.android.core.Global;

public class Trace {
	private final static String TAG = Global.instance.getApplicationName();
	private final static int TRACE_LEVEL_ERROR = 0;
	private final static int TRACE_LEVEL_WARNING = 1;
	private final static int TRACE_LEVEL_INFORMATION = 2;
	private final static int TRACE_LEVEL_DEBUG = 3;
	private final static int TRACE_LEVEL_VERBOSE = 4;
	
	private final static int TRACE_LEVEL = TRACE_LEVEL_VERBOSE;

	public static void e( String str )
	{
		if(TRACE_LEVEL >= TRACE_LEVEL_ERROR) {
			Exception e = new Exception();
			StackTraceElement element = e.getStackTrace()[1];
			Log.e( TAG, String.format("[%s %s] %s", element.getFileName(), element.getLineNumber(), str));
		}
	}

	public static void w( String str )
	{
		if(TRACE_LEVEL >= TRACE_LEVEL_WARNING) {
			Exception e = new Exception();
			StackTraceElement element = e.getStackTrace()[1];
			Log.w( TAG, String.format("[%s %s] %s", element.getFileName(), element.getLineNumber(), str));
		}
	}
	
	public static void w( Exception e )
	{
		if(TRACE_LEVEL >= TRACE_LEVEL_WARNING) {
			StackTraceElement element = e.getStackTrace()[1];
			Log.w( TAG, String.format("[%s %s %s]", element.getFileName(), element.getMethodName(), element.getLineNumber()));
		}
	}
	
	public static void i( String str )
	{
		if(TRACE_LEVEL >= TRACE_LEVEL_INFORMATION) {
			Exception e = new Exception();
			StackTraceElement element = e.getStackTrace()[1];
			Log.i( TAG, String.format("[%s %s] %s", element.getFileName(), element.getLineNumber(), str));
		}
	}

	public static void d( String str )
	{
		
		if(TRACE_LEVEL >= TRACE_LEVEL_DEBUG) {
			Exception e = new Exception();
			StackTraceElement element = e.getStackTrace()[1];
			Log.d( TAG, String.format("[%s %s] %s", element.getFileName(), element.getLineNumber(), str));
		}
	}

	public static void v( String str )
	{
		if(TRACE_LEVEL >= TRACE_LEVEL_VERBOSE) {
			Exception e = new Exception();
			StackTraceElement element = e.getStackTrace()[1];
			Log.v( TAG, String.format("[%s %s] %s", element.getFileName(), element.getLineNumber(), str));
		}
	}
	
	public static void dev( String str )
	{
		if(TRACE_LEVEL >= TRACE_LEVEL_WARNING) {
			Exception e = new Exception();
			StackTraceElement element = e.getStackTrace()[1];
			Log.e( TAG, String.format("[%s %s] %s", element.getFileName(), element.getLineNumber(), str));
		}
	}
}

@@ -201,25 +201,30 @@
 ame();%0D%0A
-%09
+%0D%0A    
 private 
 final st
@@ -219,58 +219,177 @@
 ate 
-final 
 static 
-int TRACE_LEVEL_ERROR = 0;%0D%0A%09
+enum Level %7B%0D%0A        ERROR(0),%0D%0A        WARNING(1),%0D%0A        INFORMATION(2),%0D%0A        DEBUG(3),%0D%0A        VERBOSE(4),%0D%0A        DEVELOPMENT(5);%0D%0A%0D%0A        
 private 
 fina
@@ -388,105 +388,294 @@
 ate 
-f
 in
-al static int TRACE_LEVEL_WARNING = 1;%0D%0A%09private final static int TRACE_LEVEL_INFORMATION = 2;
+t identity;%0D%0A%0D%0A        Level(int identity) %7B%0D%0A            this.identity = identity;%0D%0A        %7D%0D%0A%0D%0A        public boolean isAllow(Level filterLevel) %7B%0D%0A            if(filterLevel.identity %3C= this.identity)%0D%0A                return true;%0D%0A%0D%0A            return false;%0D%0A        %7D%0D%0A    %7D%0D%0A%09
 %0D%0A%09p
@@ -685,164 +685,231 @@
 ate 
-final 
 static 
-int TRACE_LEVEL_DEBUG = 3;%0D%0A%09private final static int TRACE_LEVEL_VERBOSE = 4;%0D%0A%09%0D%0A%09private final static int TRACE_LEVEL = TRACE_LEVEL_VERBOSE;
+Level mFilterLevel = Level.DEVELOPMENT;%0D%0A%0D%0A    public static void setFilterLevel(Level level) %7B%0D%0A        mFilterLevel = level;%0D%0A    %7D%0D%0A%0D%0A    public static Level getFilterLevel() %7B%0D%0A        return mFilterLevel;%0D%0A    %7D
 %0D%0A%0D%0A
@@ -958,40 +958,41 @@
 %09if(
-TRACE_LEVEL %3E= TRACE_LEVEL_ERROR
+Level.ERROR.isAllow(mFilterLevel)
 ) %7B%0D
@@ -1241,42 +1241,41 @@
 %09if(
-TRACE_LEVEL %3E= TRACE_LEVEL_WARNING
+Level.ERROR.isAllow(mFilterLevel)
 ) %7B%0D
@@ -1521,47 +1521,54 @@
 %09%7B%0D%0A
-%09%09if(TRACE_LEVEL %3E= TRACE_LEVEL_WARNING
+        if(Level.WARNING.isAllow(mFilterLevel)
 ) %7B%0D
@@ -1798,51 +1798,58 @@
 %09%7B%0D%0A
-%09%09if(TRACE_LEVEL %3E= TRACE_LEVEL_INFORMATION
+        if(Level.INFORMATION.isAllow(mFilterLevel)
 ) %7B%0D
@@ -2093,49 +2093,54 @@
 %09%7B%0D%0A
-%09%09%0D%0A%09%09if(TRACE_LEVEL %3E= TRACE_LEVEL_DEBUG
+%0D%0A        if(Level.DEBUG.isAllow(mFilterLevel)
 ) %7B%0D
@@ -2384,47 +2384,54 @@
 %09%7B%0D%0A
-%09%09if(TRACE_LEVEL %3E= TRACE_LEVEL_VERBOSE
+        if(Level.VERBOSE.isAllow(mFilterLevel)
 ) %7B%0D
@@ -2678,47 +2678,58 @@
 %09%7B%0D%0A
-%09%09if(TRACE_LEVEL %3E= TRACE_LEVEL_WARNING
+        if(Level.DEVELOPMENT.isAllow(mFilterLevel)
 ) %7B%0D

change variable type of Trace filter level to enum class from int