4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
7 * Kangho Kim <kh5325.kim@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
26 package org.tizen.common.util.log;
28 import java.text.MessageFormat;
30 import org.eclipse.core.runtime.CoreException;
31 import org.eclipse.core.runtime.IStatus;
32 import org.eclipse.core.runtime.Status;
33 import org.tizen.common.CommonPlugin;
34 import org.tizen.common.ui.view.console.ConsoleManager;
39 * @author Changhyun Lee {@literal <changhyun1.lee@samsung.com>} (S-Core)
42 private static String loggerName = Logger.class.getName();
44 public static void log(IStatus status) {
45 CommonPlugin plugin = CommonPlugin.getDefault();
47 plugin.getLog().log(status);
49 ConsoleManager conManager = new ConsoleManager("Error Log", false);
50 conManager.println(status.getPlugin() + " : " + status.getMessage());
54 private static String getCallerName() {
55 // Get the stack trace.
56 StackTraceElement stack[] = (new Throwable()).getStackTrace();
58 // Now search for the first frame before the "Logger" class.
59 while (ix < stack.length) {
60 StackTraceElement frame = stack[ix];
61 String cname = frame.getClassName();
62 if (!cname.equals(loggerName)) {
70 public static void log(Throwable e) {
71 if (e instanceof CoreException) {
72 log(new Status(IStatus.ERROR, getCallerName(), ((CoreException) e).getStatus().getSeverity(), e.getMessage(), e.getCause()));
74 log(new Status(IStatus.ERROR, getCallerName(), e.toString(), e));
78 public static void debug( String message, Object... arguments )
83 public static void info(String message, Object... arguments) {
84 log(new Status(Status.INFO, getCallerName(), getPossiblyFormattedString(message, arguments)));
87 public static void error(Object message, Throwable t) {
88 log(new Status(Status.ERROR, getCallerName(), message.toString(), t));
91 public static void error(String message, Object... arguments) {
92 log(new Status(Status.ERROR, getCallerName(), getPossiblyFormattedString(message, arguments)));
95 public static void warning(String message, Object... arguments) {
96 log(new Status(Status.WARNING, getCallerName(), getPossiblyFormattedString(message, arguments)));
99 private static String getPossiblyFormattedString(String message, Object... arguments) {
100 return arguments.length > 0 ? MessageFormat.format(message, arguments)