Logger: Simple, pretty and powerful logger
A sample project which provides runnable code examples that demonstrate uses of the classes in this project is available in the entity/ folder. Initialize
Logger.addLogAdapter(new HarmonyLogAdapter());
And use
Logger.i("hello");
Options
Logger.d("debug");
Logger.e("error");
Logger.w("warning");
Logger.i("information");
Logger.f("fatal");
Logger.wtf("wtf")- this will print logs in info level.
String format arguments are supported
Logger.i("hello %s", "world");
Collections are supported.
Logger.i(MAP);
Logger.i(SET);
Logger.i(LIST);
Logger.i(ARRAY);
Json and Xml support (output will be in debug level)
Logger.json(JSON_CONTENT);
Logger.xml(XML_CONTENT);
Advanced
FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
.showThreadInfo(false) // (Optional) Whether to show thread info or not. Default true
.methodCount(0) // (Optional) How many method line to show. Default 2
.methodOffset(7) // (Optional) Hides internal method calls up to offset. Default 5
.logStrategy(customLog) // (Optional) Changes the log strategy to print out. Default LogCat
.tag("My custom tag") // (Optional) Global tag for every log. Default PRETTY_LOGGER
.build();
Logger.addLogAdapter(new HarmonyLogAdapter(formatStrategy));
Loggable
Log adapter checks whether the log should be printed or not by checking this function. If you want to disable/hide logs for output, override isLoggable method. true will print the log message, false will ignore it.
Logger.addLogAdapter(new HarmonyLogAdapter() {
@Override public boolean isLoggable(int priority, String tag) {
return BuildConfig.DEBUG;
}
});
Use filter for a better result. PRETTY_LOGGER or your custom tag Make sure that wrap option is disabled You can also simplify output by changing settings.
For using Logger module in your sample application.
Modify entry build.gradle as below :
dependencies {
implementation fileTree(dir: 'libs', include:['*.jar', '*.har'])
implementation project(':logger')
}
For using Logger in separate application, add the below dependencies and include "Logger.har" in libs folder of "entry" module :
Modify entry build.gradle as below :
dependencies {
implementation fileTree(dir: 'libs', include: ['*.har'])
}
For using Logger from a remote repository in separate application, add the below dependencies:
Modify entry build.gradle as below :
```
dependencies {
implementation fileTree(dir: 'libs', include: ['*.har'])
implementation 'io.openharmony.tpc.thirdlib:logger:1.0.0'
}
```
Copyright 2018 Orhan Obut
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.
Вы можете оставить комментарий после Вход в систему
Неприемлемый контент может быть отображен здесь и не будет показан на странице. Вы можете проверить и изменить его с помощью соответствующей функции редактирования.
Если вы подтверждаете, что содержание не содержит непристойной лексики/перенаправления на рекламу/насилия/вульгарной порнографии/нарушений/пиратства/ложного/незначительного или незаконного контента, связанного с национальными законами и предписаниями, вы можете нажать «Отправить» для подачи апелляции, и мы обработаем ее как можно скорее.
Опубликовать ( 0 )