WittyGitty247 / auto-update-apk-client

Automatically exported from code.google.com/p/auto-update-apk-client
0 stars 0 forks source link

Enhance logging to allow overriding #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
We have our own logging framework, it would be great if the logging in this 
library was all centralized in a method that we could override and plugin our 
own stuff without changing the code in your base classes.

Original issue reported on code.google.com by d...@codesushi.com on 15 May 2012 at 3:42

GoogleCodeExporter commented 9 years ago
Right now all logging is going through standard Log.X() calls, you may try to 
import your own class, for example 'import com.your.company.domain.Log' in the 
beginning of AutoUpdateApk.java file and implement corresponding members, which 
will be called instead of android.util.Log

If this solution is somehow wrong or not acceptable, please, tell how would you 
prefer this to be implemented?

Original comment by lenik.terenin on 21 May 2012 at 11:56

GoogleCodeExporter commented 9 years ago
Ultimately I would like to use this source without modification as a library 
deployed in our maven repo. If the logging were to go through a protected 
method on the AutoUpdateApk class like

protected log(String level, String tag, String message, Exception e) {
  if(level.equals("E")) {
    if(e == null) Log.e(tag, message);
    else Log.e(tag, message, e);
  } else if(level.equals("W")) {
// etc
  }
// etc
} 

then our project could provide a simple class to override that one method and 
seamlessly integrate with our logging framework. just a thought...

Original comment by d...@codesushi.com on 22 May 2012 at 2:57

GoogleCodeExporter commented 9 years ago
more complete example:

    protected void v(String tag, String message) {v(tag, message, null);}
    protected void v(String tag, String message, Throwable e) {log("v", tag, message, e);}
    protected void d(String tag, String message) {d(tag, message, null);}
    protected void d(String tag, String message, Throwable e) {log("d", tag, message, e);}
    protected void i(String tag, String message) {d(tag, message, null);}
    protected void i(String tag, String message, Throwable e) {log("i", tag, message, e);}
    protected void w(String tag, String message) {w(tag, message, null);}
    protected void w(String tag, String message, Throwable e) {log("w", tag, message, e);}
    protected void e(String tag, String message) {e(tag, message, null);}
    protected void e(String tag, String message, Throwable e) {log("e", tag, message, e);}

    protected void log(String level, String tag, String message, Throwable e) {
        if(level.equals("v")) {
            if(e == null) Log.v(tag, message);
            else Log.v(tag, message, e);
        } else if(level.equals("d")) {
            if(e == null) Log.d(tag, message);
            else Log.d(tag, message, e);
        } else if(level.equals("i")) {
            if(e == null) Log.i(tag, message);
            else Log.i(tag, message, e);
        } else if(level.equals("w")) {
            if(e == null) Log.w(tag, message);
            else Log.w(tag, message, e);
        } else {
            if(e == null) Log.e(tag, message);
            else Log.e(tag, message, e);
        }
    }

Original comment by d...@codesushi.com on 22 May 2012 at 3:24

GoogleCodeExporter commented 9 years ago
Dan,

Thank you for a code sample, could you please tell me how these:
{{{
    protected void v/d/i/w/e( ... ) {
}}}

are supposed to be used? I'm asking because they are not referenced in 
"log(...)" function and I'm quite puzzled if their existence is really 
necessary?

Did you really meant something like that?
{{{
class Log {
    protected void v(String tag, String message) {v(tag, message, null);}
    protected void v(String tag, String message, Throwable e) {log("v", tag, message, e);}
    protected void d(String tag, String message) {d(tag, message, null);}
    protected void d(String tag, String message, Throwable e) {log("d", tag, message, e);}
    protected void i(String tag, String message) {d(tag, message, null);}
    protected void i(String tag, String message, Throwable e) {log("i", tag, message, e);}
    protected void w(String tag, String message) {w(tag, message, null);}
    protected void w(String tag, String message, Throwable e) {log("w", tag, message, e);}
    protected void e(String tag, String message) {e(tag, message, null);}
    protected void e(String tag, String message, Throwable e) {log("e", tag, message, e);}
}

    protected void log(String level, String tag, String message, Throwable e) {
        if(level.equals("v")) {
            if(e == null) Log.v(tag, message);
            else Log.v(tag, message, e);
        } else if(level.equals("d")) {
            if(e == null) Log.d(tag, message);
            else Log.d(tag, message, e);
        } else if(level.equals("i")) {
            if(e == null) Log.i(tag, message);
            else Log.i(tag, message, e);
        } else if(level.equals("w")) {
            if(e == null) Log.w(tag, message);
            else Log.w(tag, message, e);
        } else {
            if(e == null) Log.e(tag, message);
            else Log.e(tag, message, e);
        }
    }
}}}

Original comment by lenik.terenin on 24 May 2012 at 11:40

GoogleCodeExporter commented 9 years ago
They are just convenience methods to do the logging you wouldn't use the log 
function directly... 

d(TAG, "this is a debug message");

e(TAG, "an error occurred", exception);

Original comment by d...@codesushi.com on 25 May 2012 at 7:18

GoogleCodeExporter commented 9 years ago
Then we could override the log method in a subclass to hook into our custom 
logging framework.

Original comment by d...@codesushi.com on 25 May 2012 at 7:19

GoogleCodeExporter commented 9 years ago
could you please check the repo head if this is the changes you need?

http://code.google.com/p/auto-update-apk-client/source/list

Original comment by lenik.terenin on 25 May 2012 at 11:19

GoogleCodeExporter commented 9 years ago
I think if log() is static it wont get overridden as expected.

Original comment by d...@codesushi.com on 25 May 2012 at 11:37

GoogleCodeExporter commented 9 years ago
sorry, missed that. should be fixed now, please, check the repo head?

Original comment by lenik.terenin on 28 May 2012 at 11:31

GoogleCodeExporter commented 9 years ago
Yeah, I think that looks good now. I will get this code into our project this 
week and let you know how it works.

Original comment by d...@codesushi.com on 29 May 2012 at 2:21

GoogleCodeExporter commented 9 years ago

Original comment by lenik.terenin on 13 Jun 2012 at 5:45

GoogleCodeExporter commented 9 years ago
Sorry, forgot to get back to you, this is working great... now we use your 
library as written and have a very small class that extends the silent 
updater... perfect

Original comment by d...@codesushi.com on 13 Jun 2012 at 5:48