• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.tools.build.jetifier.core.utils
18 
19 object Log {
20 
21     var currentLevel: LogLevel = LogLevel.ERROR
22 
23     var logConsumer: LogConsumer = StdOutLogConsumer()
24 
setLevelnull25     fun setLevel(level: String?) {
26         currentLevel = when (level) {
27             "info" -> LogLevel.INFO
28             "error" -> LogLevel.ERROR
29             "warning" -> LogLevel.WARNING
30             "verbose" -> LogLevel.VERBOSE
31             else -> LogLevel.WARNING
32         }
33     }
34 
enull35     fun e(tag: String, message: String, vararg args: Any?) {
36         if (currentLevel >= LogLevel.ERROR) {
37             logConsumer.error("[$tag] $message".format(*args))
38         }
39     }
40 
wnull41     fun w(tag: String, message: String, vararg args: Any?) {
42         if (currentLevel >= LogLevel.WARNING) {
43             logConsumer.warning("[$tag] $message".format(*args))
44         }
45     }
46 
inull47     fun i(tag: String, message: String, vararg args: Any?) {
48         if (currentLevel >= LogLevel.INFO) {
49             logConsumer.info("[$tag] $message".format(*args))
50         }
51     }
52 
vnull53     fun v(tag: String, message: String, vararg args: Any?) {
54         if (currentLevel >= LogLevel.VERBOSE) {
55             logConsumer.verbose("[$tag] $message".format(*args))
56         }
57     }
58 }