Git Product home page Git Product logo

Comments (13)

tony19 avatar tony19 commented on August 16, 2024

Currently, I'm piggy backing off of the same mailing list as the Logback
users list ([email protected]).

Do you have a specific question? I might be able to help you directly.

-Tony

On Tue, Nov 1, 2011 at 6:02 PM, Fred Eisele <
[email protected]>wrote:

Which forums/mailing lists should be used for questions regarding proper
use of logback for android?

Reply to this email directly or view it on GitHub:
#1

from logback-android.

phreed avatar phreed commented on August 16, 2024

Tony,

Yes I have a specific question.
When should the configuration file be processed?

In the example ( https://github.com/tony19/logback-android ) you
show an Activity opening and parsing the configuration file.
Doing this for every activity would be be quite a bit of overhead.
I'm guessing that the configuration only needs to be done once per
{thread, process, application}?
I have been using slf4j so I was able to drop logback-android in with no
changes.
I am looking for some guidance on the best way to deal with the
configuration file.
Thanks

Fred

On Tue, Nov 1, 2011 at 5:09 PM, Tony Trinh <
[email protected]>wrote:

Currently, I'm piggy backing off of the same mailing list as the Logback
users list ([email protected]).

Do you have a specific question? I might be able to help you directly.

-Tony

On Tue, Nov 1, 2011 at 6:02 PM, Fred Eisele <
[email protected]>wrote:

Which forums/mailing lists should be used for questions regarding proper
use of logback for android?

Reply to this email directly or view it on GitHub:
#1

Reply to this email directly or view it on GitHub:
#1 (comment)

"For a successful technology, reality must take precedence over public
relations, for nature cannot be fooled." --Feynman
"It's not nice to fool Mother Nature" --Mother Nature

from logback-android.

phreed avatar phreed commented on August 16, 2024

I have code that looks like this...

public class Subscribe extends ActivityEx implements OnClickListener {
private static final Logger logger = LoggerFactory.getLogger("my-api-d");
...

public class AmmoService extends Service implements
OnSharedPreferenceChangeListener {
private static final Logger logger = LoggerFactory.getLogger("my-service");
...

You get the idea.

from logback-android.

tony19 avatar tony19 commented on August 16, 2024

That's correct. The configuration only needs to be done once per
application and does not need to be done per Activity. If you have
multiple Activities in your application, then I recommend a separate class
(singleton) to manage the Logback initialization (invoke the
JoranConfigurator). The singleton would be shared among your Activities.
But upcoming changes would obviate the need for any code-based
configuration...

I'm actually in the process (actually, it's rather stop-and-go due to other
priorities) of updating logback-android to leverage AndroidManfiest.xml for
Logback configuration and/or specifying search paths for config files.

If you can't wait for my changes, another way to remove code-based
configuration is to insert your Logback config file (logback.xml or
logback-test.xml) into the root of your apk file (which is simply a ZIP
fle).

On Tue, Nov 1, 2011 at 6:22 PM, Fred Eisele <
[email protected]>wrote:

Tony,

Yes I have a specific question.
When should the configuration file be processed?

In the example ( https://github.com/tony19/logback-android ) you
show an Activity opening and parsing the configuration file.
Doing this for every activity would be be quite a bit of overhead.
I'm guessing that the configuration only needs to be done once per
{thread, process, application}?
I have been using slf4j so I was able to drop logback-android in with no
changes.
I am looking for some guidance on the best way to deal with the
configuration file.
Thanks

Fred

On Tue, Nov 1, 2011 at 5:09 PM, Tony Trinh <
[email protected]>wrote:

Currently, I'm piggy backing off of the same mailing list as the Logback
users list ([email protected]).

Do you have a specific question? I might be able to help you directly.

-Tony

On Tue, Nov 1, 2011 at 6:02 PM, Fred Eisele <
[email protected]>wrote:

Which forums/mailing lists should be used for questions regarding
proper
use of logback for android?

Reply to this email directly or view it on GitHub:
#1

Reply to this email directly or view it on GitHub:
#1 (comment)

"For a successful technology, reality must take precedence over public
relations, for nature cannot be fooled." --Feynman
"It's not nice to fool Mother Nature" --Mother Nature

Reply to this email directly or view it on GitHub:
#1 (comment)

from logback-android.

tony19 avatar tony19 commented on August 16, 2024

To answer your question, code-based Logback initialization should be done as early as possible (before you call the Logger). Otherwise, the BasicConfigurator will take effect, printing your log statements to stdout (logcat).

from logback-android.

phreed avatar phreed commented on August 16, 2024

The following fragment seems to do what I want.
Eventually, there will be an activity to control the logger but the application can get an initial configuration loaded.

public class ApplicationEx  extends Application {
   private static final Logger logger = LoggerFactory.getLogger(ApplicationEx.class);

   private static ApplicationEx singleton;

   public ApplicationEx() {
       super();
   }

   public static ApplicationEx getInstance() {
       return singleton;
   }

   @Override
   public final void onCreate() {
       super.onCreate();
       logger.debug("::onCreate");
       singleton = this;

       configure(this.getApplicationContext());
    }
}

public  static void configure(Context context) {
    final InputStream inputStream;
    final File configDir = context.getDir("logger", Context.MODE_WORLD_READABLE);
    final File configFile = new File(configDir, "logger.xml");
    Toast.makeText(context, configFile.toString(), Toast.LENGTH_LONG).show();
    final File globalConfigFile = new File(Environment.getDataDirectory(), "logger.xml");

    if (configFile.exists()) {
        try {
            inputStream = new FileInputStream(configFile);
        } catch (FileNotFoundException ex) {
            //logger.error("no policy file {} {}", configFile, ex.getStackTrace());
            return;
        }
    } else if (globalConfigFile.exists()) {
        try {
            inputStream = new FileInputStream(globalConfigFile);
        } catch (FileNotFoundException ex) {
            //logger.error("no policy file {} {}", globalConfigFile, ex.getStackTrace());
            return;
        }
    }
    else  {
        // Toast.makeText(context, R.string.no_log_config_file, Toast.LENGTH_LONG).show();
        try {
            final InputStream default_config = context.getResources().openRawResource(R.raw.default_logger);                
            final OutputStream out = new FileOutputStream(configFile);
            final byte[] buf = new byte[1024];
            int len;
            while ((len = default_config.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            default_config.close();
            out.close();
        } catch (NotFoundException ex) {
            //logger.error("asset not available {}", ex.getMessage());
        } catch (FileNotFoundException ex) {
            //logger.error("file not available {}", ex.getMessage());
        } catch (IOException ex) {
            //logger.error("file not writable {}", ex.getMessage());
        }
        inputStream = context.getResources().openRawResource(R.raw.default_logger);
    }

    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    try {
        final JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(lc);
        lc.reset();
        configurator.doConfigure(inputStream);
    } catch (JoranException je) {
        // StatusPrinter will handle this
    }
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}

Of course this configure method could be moved to a logging specific class.

from logback-android.

phreed avatar phreed commented on August 16, 2024

I notice in the logback documentation ...

"Specifying the location of the default configuration file as a system property

"If you wish, you can specify the location of the default configuration file with a system property named logback.configurationFile. The value of this property can be a URL, a resource on the class path or a path to a file external to the application.

java -Dlogback.configurationFile=/path/to/config.xml chapters.configuration.MyApp1

"
I would like to be able to do this with android.
Maybe something like...

adb shell setprop logback.config.file logger.xml

Along the line of the config method mentioned above this would check for logger configuration files.
/sdcard/logger.xml and /data/data/<blah.app>/app_logger/logger.xml
or something like that.

from logback-android.

tony19 avatar tony19 commented on August 16, 2024

I had started looking into this a while ago. AFAIK, Android doesn't provide a means of reading the properties set from adb shell setprop. Those are system-level properties as opposed to process-level ones that can be read by System.getProperty. Someone discovered hidden functions for this, but I'm hesitant to use something unsupported (not guaranteed to exist on the next Android release).

from logback-android.

phreed avatar phreed commented on August 16, 2024

I found this...
http://www.google.com/codesearch#2wSbThBwwIw/libcutils/properties.c&q=property_get%20package:android&type=cs
...and this...
http://rxwen.blogspot.com/2010/01/android-property-system.html

Sounds like the property_get() and property_set() are not part of the ndk but used widely
while, as you said, System.getProperty() is something completely different.
(Although it may be initialized from the native properties, but it would be unreliable if it works at all.)

It looks like property_get() is exposed through SystemProperties...
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2.1_r1/android/os/SystemProperties.java#SystemProperties
...which shows up in jni as...
http://www.google.com/codesearch#cZwlSNS7aEw/frameworks/base/core/jni/android_os_SystemProperties.cpp&ct=rc&cd=36&exact_package=android&q=package:android%20lang:%5Ec%2B%2B$%20property_get&sq=

But this is a hidden class.
Nevertheless, it can be accessed via reflection...
http://stackoverflow.com/questions/2641111/where-is-android-os-systemproperties
...or a jni could be written.

Or on a different tack, we could presume a file in a standard location such as the data directory...
http://developer.android.com/reference/android/os/Environment.html#getDataDirectory()
/data/data/logback.xml
...for example.

In any case I think the default should be to use the LogcatAppender rather than StdOut.
What do you think?

from logback-android.

tony19 avatar tony19 commented on August 16, 2024

I'm already working on a way to load the configuration file (or its search path). I'll probably have time for it in a few weeks.

You might be right about LogcatAppender.

from logback-android.

phreed avatar phreed commented on August 16, 2024

Anything I can do to help?

from logback-android.

tony19 avatar tony19 commented on August 16, 2024

Thanks, I could certainly use some help, but the configuration file stuff is still on hold for now. I'll keep you posted.

LogcatAppender is now the default. commit fa6c20b

from logback-android.

lock avatar lock commented on August 16, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

from logback-android.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.