2 * //******************************************************************
4 * // Copyright 2016 Samsung Electronics All Rights Reserved.
6 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 * // Licensed under the Apache License, Version 2.0 (the "License");
9 * // you may not use this file except in compliance with the License.
10 * // You may obtain a copy of the License at
12 * // http://www.apache.org/licenses/LICENSE-2.0
14 * // Unless required by applicable law or agreed to in writing, software
15 * // distributed under the License is distributed on an "AS IS" BASIS,
16 * // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * // See the License for the specific language governing permissions and
18 * // limitations under the License.
20 * //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
22 package org.iotivity.cloud.util;
24 import java.text.SimpleDateFormat;
25 import java.util.Calendar;
29 public static final int VERBOSE = 0;
30 public static final int DEBUG = 1;
31 public static final int INFO = 2;
32 public static final int WARNING = 3;
33 public static final int ERROR = 4;
35 private static int logLevel = DEBUG;
37 public static void setLogLevel(int level) {
41 public static void v(String log) {
42 printLog(VERBOSE, log);
45 public static void d(String log) {
49 public static void i(String log) {
53 public static void w(String log) {
54 printLog(WARNING, log);
57 public static void e(String log) {
61 public static void w(String log, Exception ex) {
62 printLog(WARNING, log);
66 public static void w(String log, Throwable th) {
67 printLog(WARNING, log);
71 public static void e(String log, Exception ex) {
76 public static void e(String log, Throwable th) {
81 private static void printLog(int level, String log) {
88 format += " [" + getLogLevelString(level) + "]";
91 format += " [" + getDetailInfo() + "]";
96 System.out.println(format);
99 private static String getDetailInfo() {
103 StackTraceElement ste = Thread.currentThread().getStackTrace()[4];
104 String className = ste.getClassName()
105 .substring(ste.getClassName().lastIndexOf(".") + 1);
107 res += ste.getFileName() + ", " + className + "." + ste.getMethodName()
108 + "(), line:" + ste.getLineNumber();
113 private static String getTime() {
114 Calendar calendar = Calendar.getInstance();
115 SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSS");
117 return dateFormat.format(calendar.getTime());
120 private static String getLogLevelString(int level) {
124 if (level == VERBOSE) {
126 } else if (level == DEBUG) {
128 } else if (level == INFO) {
130 } else if (level == WARNING) {
132 } else if (level == ERROR) {