Java tutorial
//package com.java2s; /* * Copyright (C) 2012 The Android Open Source Project * * 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 */ import android.util.Log; public class Main { /** * Priority constant for the println method; use LogUtils.e. */ public static final int ERROR = Log.ERROR; /** * Used to enable/disable logging that we don't want included in * production releases. */ private static final int MAX_ENABLED_LOG_LEVEL = ERROR; /** * Send a {@link #ERROR} log message. * @param tag Used to identify the source of a log message. It usually identifies * the class or activity where the log call occurs. * @param format the format string (see {@link java.util.Formatter#format}) * @param args * the list of arguments passed to the formatter. If there are * more arguments than required by {@code format}, * additional arguments are ignored. */ public static int e(String tag, String format, Object... args) { if (isLoggable(tag, ERROR)) { return Log.e(tag, String.format(format, args)); } return 0; } /** * Send a {@link #ERROR} log message. * @param tag Used to identify the source of a log message. It usually identifies * the class or activity where the log call occurs. * @param tr An exception to log * @param format the format string (see {@link java.util.Formatter#format}) * @param args * the list of arguments passed to the formatter. If there are * more arguments than required by {@code format}, * additional arguments are ignored. */ public static int e(String tag, Throwable tr, String format, Object... args) { if (isLoggable(tag, ERROR)) { return Log.e(tag, String.format(format, args), tr); } return 0; } /** * Checks to see whether or not a log for the specified tag is loggable at the specified level. */ public static boolean isLoggable(String tag, int level) { if (MAX_ENABLED_LOG_LEVEL > level) { return false; } return Log.isLoggable(tag, level); } }