Skip to content

Commit 7614fa0

Browse files
committed
How to migrate an app
1 parent 3ddb6f6 commit 7614fa0

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

examples/migration-app/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,11 @@ android {
4747
dependencies {
4848
implementation(project(":examples:migration-lib"))
4949
implementation 'androidx.core:core-ktx:1.17.0'
50+
51+
implementation 'io.github.neboskreb:android-log4j2-migration:2.0'
52+
implementation 'io.github.neboskreb:android-log4j2:2.24'
53+
// Though android-log4j2 brings Log4J2 in as a transitive dependency,
54+
// it is always a good idea to pin the exact version:
55+
implementation 'org.apache.logging.log4j:log4j-core:2.24.3'
56+
implementation 'org.apache.logging.log4j:log4j-slf4j2-impl:2.24.3'
5057
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Root Logger
2+
rootLogger = WARN, LOGCAT
3+
4+
# Direct log messages to LOGCAT
5+
appender.logcat.type = Logcat
6+
appender.logcat.name = LOGCAT
7+
appender.logcat.layout.type = PatternLayout
8+
appender.logcat.layout.pattern = %m%n
9+
#appender.logcat.stack-trace-rendering = log4j
10+
appender.logcat.stack-trace-rendering = logcat
11+
12+
13+
logger.lib.name = MY_LIBRARY
14+
logger.lib.level = warn
15+
16+
logger.app.name = MAIN_ACTIVITY
17+
logger.app.level = all
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
package com.github.neboskreb.log4j2.examples.migration
22

33
import android.app.Application
4+
import com.github.neboskreb.log4j2.migration.Log
5+
import net.loune.log4j2android.AndroidLog4jHelper
46

57
class App : Application() {
8+
// NOTE: This is optional.
9+
// Force Log to invoke the Log4j calls directly, bypassing the SLF4J facade.
10+
init {
11+
Log.useLog4j2()
12+
}
613

714
override fun onCreate() {
815
super.onCreate()
16+
17+
AndroidLog4jHelper.initialize(applicationContext)
918
}
1019
}

examples/migration-app/src/main/kotlin/com/github/neboskreb/log4j2/examples/migration/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.github.neboskreb.log4j2.examples.migration
22

33
import android.app.Activity
44
import android.os.Bundle
5-
import android.util.Log
5+
import com.github.neboskreb.log4j2.migration.Log
66

77
import com.github.neboskreb.log4j2.examples.migration.lib.MyLibrary
88

0 commit comments

Comments
 (0)