Skip to content

Commit 788e21b

Browse files
committed
Initial code for the migration examples
1 parent e76a3e6 commit 788e21b

File tree

7 files changed

+116
-0
lines changed

7 files changed

+116
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:name=".App"
7+
android:allowBackup="false"
8+
android:label="Migration Example"
9+
tools:targetApi="31">
10+
11+
<activity
12+
android:name=".MainActivity"
13+
android:exported="true">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
</manifest>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.github.neboskreb.log4j2.examples.migration
2+
3+
import android.app.Application
4+
5+
class App : Application() {
6+
7+
override fun onCreate() {
8+
super.onCreate()
9+
}
10+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.github.neboskreb.log4j2.examples.migration
2+
3+
import android.app.Activity
4+
import android.os.Bundle
5+
import android.util.Log
6+
7+
import com.github.neboskreb.log4j2.examples.migration.lib.MyLibrary
8+
9+
private const val TAG = "MAIN_ACTIVITY"
10+
11+
class MainActivity : Activity() {
12+
override fun onCreate(savedInstanceState: Bundle?) {
13+
Log.w(null, "This is a NULL-TAG message")
14+
Log.w(TAG, "This is a test warning message")
15+
16+
super.onCreate(savedInstanceState)
17+
Log.i(TAG, "Activity created")
18+
19+
setContentView(R.layout.content_main)
20+
Log.d(TAG, "ContentView is set")
21+
22+
Log.wtf(TAG, "This is a test WTF message with a stack trace", Throwable("WTF Exception"))
23+
24+
MyLibrary().logSomething()
25+
}
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context=".MainActivity">
8+
9+
<TextView
10+
android:layout_width="wrap_content"
11+
android:layout_height="wrap_content"
12+
android:text="Hello World!" />
13+
</RelativeLayout>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.neboskreb.log4j2.examples.migration.lib
2+
3+
import org.junit.jupiter.api.Test
4+
5+
class MyLibraryAndroidTest {
6+
@Test
7+
fun logSomething() {
8+
// GIVEN
9+
val library = MyLibrary()
10+
11+
// WHEN
12+
library.logSomething()
13+
14+
// THEN see the logs
15+
}
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.github.neboskreb.log4j2.examples.migration.lib
2+
3+
import android.util.Log
4+
5+
private const val TAG = "MY_LIBRARY"
6+
7+
class MyLibrary {
8+
fun logSomething() {
9+
Log.i(TAG, "Library logged this INFO message")
10+
11+
Log.w(TAG, "Library logged this WARN message")
12+
13+
Log.wtf(TAG, "Library logged this WTF message")
14+
}
15+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.github.neboskreb.log4j2.examples.migration.lib
2+
3+
import org.junit.jupiter.api.Test
4+
5+
class MyLibraryTest {
6+
@Test
7+
fun logSomething() {
8+
// GIVEN
9+
val library = MyLibrary()
10+
11+
// WHEN
12+
library.logSomething()
13+
14+
// THEN see the logs
15+
}
16+
}

0 commit comments

Comments
 (0)