Log.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. *
  3. * Copyright (c) 2023 Project CHIP Authors
  4. * Copyright (c) 2015-2017 Nest Labs, Inc.
  5. * All rights reserved.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. /** Log.java Stub file to allow compiling standalone, without Android SDK. */
  20. package android.util;
  21. public final class Log {
  22. public static final int VERBOSE = 2;
  23. public static final int DEBUG = 3;
  24. public static final int INFO = 4;
  25. public static final int WARN = 5;
  26. public static final int ERROR = 6;
  27. public static final int ASSERT = 7;
  28. public static final int NONE = Integer.MAX_VALUE;
  29. /**
  30. * Send a DEBUG log message.
  31. *
  32. * @param tag Used to identify the source of a log message. It usually identifies the class or
  33. * activity where the log call occurs.
  34. * @param msg The message you would like logged.
  35. * @return A positive value if the message was loggable.
  36. */
  37. public static int d(String tag, String msg) {
  38. return log(DEBUG, tag, msg);
  39. }
  40. /**
  41. * Send a ERROR log message.
  42. *
  43. * @param tag Used to identify the source of a log message. It usually identifies the class or
  44. * activity where the log call occurs.
  45. * @param msg The message you would like logged.
  46. * @return A positive value if the message was loggable.
  47. */
  48. public static int e(String tag, String msg) {
  49. return log(ERROR, tag, msg);
  50. }
  51. /**
  52. * Send a ERROR log message and log the exception.
  53. *
  54. * @param tag Used to identify the source of a log message. It usually identifies the class or
  55. * activity where the log call occurs.
  56. * @param msg The message you would like logged.
  57. * @param tr An exception to log.
  58. * @return A positive value if the message was loggable.
  59. */
  60. public static int e(String tag, String msg, Throwable tr) {
  61. return log(ERROR, tag, msg, tr);
  62. }
  63. /**
  64. * Send a WARN log message.
  65. *
  66. * @param tag Used to identify the source of a log message. It usually identifies the class or
  67. * activity where the log call occurs.
  68. * @param msg The message you would like logged.
  69. * @return A positive value if the message was loggable.
  70. */
  71. public static int w(String tag, String msg) {
  72. return log(WARN, tag, msg);
  73. }
  74. private static int log(int level, String tag, String msg) {
  75. if (level > ASSERT) {
  76. return -1;
  77. }
  78. System.out.println(tag + ':' + msg);
  79. return 1;
  80. }
  81. private static int log(int level, String tag, String msg, Throwable tr) {
  82. if (level > ASSERT) {
  83. return -1;
  84. }
  85. System.out.println(tag + ':' + msg);
  86. System.out.println(tr.toString());
  87. return 1;
  88. }
  89. }