1 // Copyright 2021 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 package com.google.android.downloader;
16 
17 import android.util.Log;
18 import com.google.errorprone.annotations.FormatMethod;
19 import com.google.errorprone.annotations.FormatString;
20 import javax.annotation.Nullable;
21 
22 /**
23  * Implementation of {@link DownloaderLogger} backed by Android's {@link Log} system. Useful for
24  * contexts (e.g. AOSP) that can't take the Flogger dependency.
25  */
26 public class AndroidDownloaderLogger implements DownloaderLogger {
27   private static final String TAG = "downloader2";
28 
29   @Override
30   @FormatMethod
logFine(@ormatString String message, Object... args)31   public void logFine(@FormatString String message, Object... args) {
32     Log.d(TAG, String.format(message, args));
33   }
34 
35   @Override
36   @FormatMethod
logInfo(@ormatString String message, Object... args)37   public void logInfo(@FormatString String message, Object... args) {
38     Log.i(TAG, String.format(message, args));
39   }
40 
41   @Override
42   @FormatMethod
logWarning(@ormatString String message, Object... args)43   public void logWarning(@FormatString String message, Object... args) {
44     Log.w(TAG, String.format(message, args));
45   }
46 
47   @Override
48   @FormatMethod
logWarning(@ullable Throwable cause, @FormatString String message, Object... args)49   public void logWarning(@Nullable Throwable cause, @FormatString String message, Object... args) {
50     Log.w(TAG, String.format(message, args), cause);
51   }
52 
53   @Override
54   @FormatMethod
logError(@ormatString String message, Object... args)55   public void logError(@FormatString String message, Object... args) {
56     Log.e(TAG, String.format(message, args));
57   }
58 
59   @Override
60   @FormatMethod
logError(@ullable Throwable cause, @FormatString String message, Object... args)61   public void logError(@Nullable Throwable cause, @FormatString String message, Object... args) {
62     Log.e(TAG, String.format(message, args), cause);
63   }
64 }
65