1 /*
2  * Copyright (C) 2024 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 android.telephony;
18 
19 import android.annotation.NonNull;
20 
21 /**
22  * A persistent logging client. Intended for persisting critical debug logs in situations where
23  * standard Android logcat logs may not be retained long enough.
24  *
25  * @hide
26  */
27 public class PersistentLogger {
28     private final PersistentLoggerBackend mPersistentLoggerBackend;
29 
PersistentLogger(@onNull PersistentLoggerBackend persistentLoggerBackend)30     public PersistentLogger(@NonNull PersistentLoggerBackend persistentLoggerBackend) {
31         mPersistentLoggerBackend = persistentLoggerBackend;
32     }
33 
34     /**
35      * Persist a DEBUG log message.
36      * @param tag Used to identify the source of a log message.
37      * @param msg The message you would like logged.
38      */
debug(@onNull String tag, @NonNull String msg)39     public void debug(@NonNull String tag, @NonNull String msg) {
40         mPersistentLoggerBackend.debug(tag, msg);
41     }
42 
43     /**
44      * Persist a INFO log message.
45      * @param tag Used to identify the source of a log message.
46      * @param msg The message you would like logged.
47      */
info(@onNull String tag, @NonNull String msg)48     public void info(@NonNull String tag, @NonNull String msg) {
49         mPersistentLoggerBackend.info(tag, msg);
50     }
51 
52     /**
53      * Persist a WARN log message.
54      * @param tag Used to identify the source of a log message.
55      * @param msg The message you would like logged.
56      */
warn(@onNull String tag, @NonNull String msg)57     public void warn(@NonNull String tag, @NonNull String msg) {
58         mPersistentLoggerBackend.warn(tag, msg);
59     }
60 
61     /**
62      * Persist a WARN log message.
63      * @param tag Used to identify the source of a log message.
64      * @param msg The message you would like logged.
65      * @param t An exception to log.
66      */
warn(@onNull String tag, @NonNull String msg, @NonNull Throwable t)67     public void warn(@NonNull String tag, @NonNull String msg, @NonNull Throwable t) {
68         mPersistentLoggerBackend.warn(tag, msg, t);
69     }
70 
71     /**
72      * Persist a ERROR log message.
73      * @param tag Used to identify the source of a log message.
74      * @param msg The message you would like logged.
75      */
error(@onNull String tag, @NonNull String msg)76     public void error(@NonNull String tag, @NonNull String msg) {
77         mPersistentLoggerBackend.error(tag, msg);
78     }
79 
80     /**
81      * Persist a ERROR log message.
82      * @param tag Used to identify the source of a log message.
83      * @param msg The message you would like logged.
84      * @param t An exception to log.
85      */
error(@onNull String tag, @NonNull String msg, @NonNull Throwable t)86     public void error(@NonNull String tag, @NonNull String msg, @NonNull Throwable t) {
87         mPersistentLoggerBackend.error(tag, msg, t);
88     }
89 }
90