:construction: - Simple Android Kotlin logger (2017/2020)
Simple android logger (2020)
repositories {
jcenter()
}
dependencies {
implementation 'net.alexandroid.utils:mylogkt:1.13'
}
# Remove all log* methods from prpject
-assumenosideeffects class net.alexandroid.utils.mylogkt.MyLogKtKt { *; }
# Remove specific logger methods
-assumenosideeffects class net.alexandroid.utils.mylogkt.MyLogKtKt {
public static *** logD$default(...);
public static *** logW$default(...);
}
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Kotlin from Kotlin (Optional, to allow isPackageNameVisible = true)
MyLogKt.packageName = packageName
MyLogKt.isLogsShown = BuildConfig.DEBUG
MyLogKt.tag = "STATIC CUSTOM TAG"
// Other Kotlin version configurations
MyLogKt.packageName = ""
MyLogKt.isLogsShown = true
MyLogKt.isThreadNameVisible = false
MyLogKt.isTimeVisible = true
MyLogKt.isPackageNameVisible = false
MyLogKt.isClassNameVisible = true
MyLogKt.isMethodNameVisible = true
MyLogKt.isLengthShouldWrap = true
MyLogKt.classNameLength = 15
MyLogKt.packageAndClassNameLength = 35
MyLogKt.methodNameLength = 15
MyLogKt.threadNameLength = 6
MyLogKt.timeFormat = "HH:mm:ss.SSS"
}
}
<application
android:name=".MyApplication"
...>
logD("Empty 1")
logI("Empty 2")
logW("Empty 3")
logE("Empty 4")
logV("Empty 5")
// Same functions
debug("Empty 1")
info("Empty 2")
warn("Empty 3")
error("Empty 4")
verbose("Empty 5")
logD("Custom tag example 1", "CustomTag1")
logE("Show Exception", t = NullPointerException())
}
Usualy logs look like below:
First go to Configure Logcat Header:
Uncheck all options and press OK:
Now your logs looks like below:
File -> Settings -> Editor -> Colors & Fonts -> Android Logcat
Default:
MyLog.setPackageNameVisibility(true);
MyLogKt.isPackageNameVisible = true
MyLog.setIsTimeVisible(false);
MyLogKt.isTimeVisible = false
MyLog.setThreadIdVisibility(true);
MyLogKt.isThreadIdVisible = true
Copyright 2017 Alexey Korolev
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
repositories {
jcenter()
}
dependencies {
implementation 'net.alexandroid.utils:mylog:1.5'
}
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Java (Mandatory)
MyLog.init(this, "MyLog", BuildConfig.DEBUG); // Context, Tag, Show logs?
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Java lib
MyLog.setTag("STATIC CUSTOM TAG");
MyLog.d("Empty 1");
MyLog.i("Empty 2");
MyLog.w("Empty 3");
MyLog.e("Empty 4");
MyLog.d("CustomTag", "Custom tag example message");
MyLog.e("Show Exception", new NullPointerException());
}