• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2006 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.util;
18 
19 import android.compat.annotation.UnsupportedAppUsage;
20 import android.os.Build;
21 
22 /**
23  * API for sending log output to the {@link Log#LOG_ID_SYSTEM} buffer.
24  *
25  * <p>Should be used by system components. Use {@code adb logcat --buffer=system} to fetch the logs.
26  *
27  * @hide
28  */
29 public final class Slog {
30 
Slog()31     private Slog() {
32     }
33 
34     @UnsupportedAppUsage
v(String tag, String msg)35     public static int v(String tag, String msg) {
36         return Log.println_native(Log.LOG_ID_SYSTEM, Log.VERBOSE, tag, msg);
37     }
38 
v(String tag, String msg, Throwable tr)39     public static int v(String tag, String msg, Throwable tr) {
40         return Log.println_native(Log.LOG_ID_SYSTEM, Log.VERBOSE, tag,
41                 msg + '\n' + Log.getStackTraceString(tr));
42     }
43 
44     @UnsupportedAppUsage
d(String tag, String msg)45     public static int d(String tag, String msg) {
46         return Log.println_native(Log.LOG_ID_SYSTEM, Log.DEBUG, tag, msg);
47     }
48 
49     @UnsupportedAppUsage
d(String tag, String msg, Throwable tr)50     public static int d(String tag, String msg, Throwable tr) {
51         return Log.println_native(Log.LOG_ID_SYSTEM, Log.DEBUG, tag,
52                 msg + '\n' + Log.getStackTraceString(tr));
53     }
54 
55     @UnsupportedAppUsage
i(String tag, String msg)56     public static int i(String tag, String msg) {
57         return Log.println_native(Log.LOG_ID_SYSTEM, Log.INFO, tag, msg);
58     }
59 
i(String tag, String msg, Throwable tr)60     public static int i(String tag, String msg, Throwable tr) {
61         return Log.println_native(Log.LOG_ID_SYSTEM, Log.INFO, tag,
62                 msg + '\n' + Log.getStackTraceString(tr));
63     }
64 
65     @UnsupportedAppUsage
w(String tag, String msg)66     public static int w(String tag, String msg) {
67         return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag, msg);
68     }
69 
70     @UnsupportedAppUsage
w(String tag, String msg, Throwable tr)71     public static int w(String tag, String msg, Throwable tr) {
72         return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag,
73                 msg + '\n' + Log.getStackTraceString(tr));
74     }
75 
w(String tag, Throwable tr)76     public static int w(String tag, Throwable tr) {
77         return Log.println_native(Log.LOG_ID_SYSTEM, Log.WARN, tag, Log.getStackTraceString(tr));
78     }
79 
80     @UnsupportedAppUsage
e(String tag, String msg)81     public static int e(String tag, String msg) {
82         return Log.println_native(Log.LOG_ID_SYSTEM, Log.ERROR, tag, msg);
83     }
84 
85     @UnsupportedAppUsage
e(String tag, String msg, Throwable tr)86     public static int e(String tag, String msg, Throwable tr) {
87         return Log.println_native(Log.LOG_ID_SYSTEM, Log.ERROR, tag,
88                 msg + '\n' + Log.getStackTraceString(tr));
89     }
90 
91     /**
92      * Like {@link Log#wtf(String, String)}, but will never cause the caller to crash, and
93      * will always be handled asynchronously.  Primarily for use by coding running within
94      * the system process.
95      */
96     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
wtf(String tag, String msg)97     public static int wtf(String tag, String msg) {
98         return Log.wtf(Log.LOG_ID_SYSTEM, tag, msg, null, false, true);
99     }
100 
101     /**
102      * Like {@link #wtf(String, String)}, but does not output anything to the log.
103      */
wtfQuiet(String tag, String msg)104     public static void wtfQuiet(String tag, String msg) {
105         Log.wtfQuiet(Log.LOG_ID_SYSTEM, tag, msg, true);
106     }
107 
108     /**
109      * Like {@link Log#wtfStack(String, String)}, but will never cause the caller to crash, and
110      * will always be handled asynchronously.  Primarily for use by coding running within
111      * the system process.
112      */
113     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
wtfStack(String tag, String msg)114     public static int wtfStack(String tag, String msg) {
115         return Log.wtf(Log.LOG_ID_SYSTEM, tag, msg, null, true, true);
116     }
117 
118     /**
119      * Like {@link Log#wtf(String, Throwable)}, but will never cause the caller to crash,
120      * and will always be handled asynchronously.  Primarily for use by coding running within
121      * the system process.
122      */
wtf(String tag, Throwable tr)123     public static int wtf(String tag, Throwable tr) {
124         return Log.wtf(Log.LOG_ID_SYSTEM, tag, tr.getMessage(), tr, false, true);
125     }
126 
127     /**
128      * Like {@link Log#wtf(String, String, Throwable)}, but will never cause the caller to crash,
129      * and will always be handled asynchronously.  Primarily for use by coding running within
130      * the system process.
131      */
132     @UnsupportedAppUsage
wtf(String tag, String msg, Throwable tr)133     public static int wtf(String tag, String msg, Throwable tr) {
134         return Log.wtf(Log.LOG_ID_SYSTEM, tag, msg, tr, false, true);
135     }
136 
137     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
println(int priority, String tag, String msg)138     public static int println(int priority, String tag, String msg) {
139         return Log.println_native(Log.LOG_ID_SYSTEM, priority, tag, msg);
140     }
141 }
142