noveogroup / android-logger

Useful logger for Android based on standard android.util.Log class. Simple lightweight (< 50 Kb) implementation of SLF4J API. Easy but powerful configuration via properties file and some additional helpful logging methods. Easy analogue of popular log4j library.

Home Page:https://noveogroup.github.io/android-logger

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature: Dynamic tags

jromero opened this issue · comments

Can the tag be "dynamically" set? Maybe something like:

Properties:

# All classes in the following package will use the String or class as the logging tag
logger.com.example.activity=DEBUG:*

Code:

// TAG = MainActivity
private static final Logger LOG = LoggerManager.getLogger(MainActivity.class);

// TAG = "@@@@@@@"
private static final Logger LOG = LoggerManager.getLogger("@@@@@@@");

This would make the library extremely more useable for larger projects without defining different tags for packages or if you need to target certain classes quickly.

Hello,

Unfortunately, android-logger library doesn't support dynamic tag changing.

I suggest you using my fork of LOGBack library: https://github.com/noveogroup/logback-android
You can download it here: https://github.com/noveogroup/android-logger/blob/gh-downloads/logback-android-1.0.10-3-SNAPSHOT-android-logger.jar?raw=true
For more information look at the beggining of description of android-logger: https://github.com/noveogroup/android-logger/blob/master/README.md

LOGBack has a lot of useful settings including configurable tags you need. My fork of this library contains simple adapter ch.qos.logback.classic.android.Log that can be used as standard Android logger but without tag parameter - it will get the tag from the configuration as you described.

The configuration you need is (place it in manifest file):

<logback>
    <configuration>
      <appender
          name="LOGCAT"
          class="ch.qos.logback.classic.android.LogcatAppender" >
          <tagEncoder>
              <pattern>%logger{0}</pattern>
          </tagEncoder>
          <encoder>
              <pattern>%msg%n</pattern>
          </encoder>
      </appender>

      <root level="WARN" >
          <appender-ref ref="LOGCAT" />
      </root>
    </configuration>
</logback>

I hope it helps you :)

I would rather not add a large library for something as simple as logging with a configuration file. This was the original reason why I choose to use android-logger vs many others. I've built the functionality, see [https://github.com/jromero/android-logger/commit/c5cca70c8626acfa6945d0fb73bc466d3bf456a4]. I've also updated the sample branch [https://github.com/jromero/android-logger/commit/da316b6f5313978b95ecfe9bff6a58f8c8c85a32].

I think it would be beneficial to continue development of this particular library vs moving on to logback. I can make a pull request if you wish to continue maintaining it or otherwise I can rebrand and maintain it myself.

I'm developing new version of android-logger with tag & message formatting support but last months I was in "vacation".

May I publish a link to your fork until I do new version ?

By the way, thank you for the interest. It inspires :)

You can definitely link to my fork. Also, if I may suggest renaming the library to something more unique only so that it can more easily be searched for or suggested in conversation. If you search for android logger it's not really among the top answers but the built in android Log/Logger class. Keep up the good work. Can't wait for later releases.

The new release 1.3.0 is done :)