From 652f4bd848a4e36b991c1490eb516ff0f5b1687a Mon Sep 17 00:00:00 2001 From: qouyang Date: Tue, 20 Jun 2006 06:24:39 +0000 Subject: Add log and exception mechanism git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@566 6f19259b-4bc3-4df7-8a09-765794883524 --- .../org/tianocore/exception/EdkException.java | 47 +++++++++++ .../Common/org/tianocore/logger/DefaultLogger.java | 36 +++++++++ .../Source/Common/org/tianocore/logger/EdkLog.java | 91 ++++++++++++++++++++++ .../Common/org/tianocore/logger/LogMethod.java | 23 ++++++ .../org/tianocore/build/global/GenBuildLogger.java | 33 ++++++++ 5 files changed, 230 insertions(+) create mode 100644 Tools/Source/Common/org/tianocore/exception/EdkException.java create mode 100644 Tools/Source/Common/org/tianocore/logger/DefaultLogger.java create mode 100644 Tools/Source/Common/org/tianocore/logger/EdkLog.java create mode 100644 Tools/Source/Common/org/tianocore/logger/LogMethod.java create mode 100644 Tools/Source/GenBuild/org/tianocore/build/global/GenBuildLogger.java diff --git a/Tools/Source/Common/org/tianocore/exception/EdkException.java b/Tools/Source/Common/org/tianocore/exception/EdkException.java new file mode 100644 index 0000000000..d6258979c1 --- /dev/null +++ b/Tools/Source/Common/org/tianocore/exception/EdkException.java @@ -0,0 +1,47 @@ +/*++ + +Copyright (c) 2006, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + EdkException.java + +Abstract: + +--*/ +package org.tianocore.exception; + +public class EdkException extends Exception { + private StackTraceElement[] stackTrace; + public static boolean isPrintStack = false; + + public EdkException(String message) { + super("[EdkException]:" + message); + } + + public EdkException(String message, boolean traceStack) { + super(message); + + } + + public EdkException(){ + super(); + } + + public EdkException(Exception e, String message){ + super("[EdkException]:" + message); + if (isPrintStack){ + this.setStackTrace(e.getStackTrace()); + } + e.printStackTrace(); + } + public static void setIsprintStack (boolean flag){ + isPrintStack = flag; + } +} diff --git a/Tools/Source/Common/org/tianocore/logger/DefaultLogger.java b/Tools/Source/Common/org/tianocore/logger/DefaultLogger.java new file mode 100644 index 0000000000..4bec8e52b4 --- /dev/null +++ b/Tools/Source/Common/org/tianocore/logger/DefaultLogger.java @@ -0,0 +1,36 @@ +/*++ + +Copyright (c) 2006, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + DefaultLogger.java + +Abstract: + +--*/ + +package org.tianocore.logger; +import java.util.logging.Level; +import java.util.logging.Logger; + +class DefaultLogger implements LogMethod { + private Logger logger = Logger.global; + private static Level[] levelMap = { + Level.SEVERE, Level.WARNING, Level.INFO, Level.FINE, Level.ALL + }; + + public DefaultLogger() { + + } + + public void putMessage(Object msgSource, int msgLevel, String msg) { + logger.log(levelMap[msgLevel], msg); + } +} \ No newline at end of file diff --git a/Tools/Source/Common/org/tianocore/logger/EdkLog.java b/Tools/Source/Common/org/tianocore/logger/EdkLog.java new file mode 100644 index 0000000000..b16d39c2b1 --- /dev/null +++ b/Tools/Source/Common/org/tianocore/logger/EdkLog.java @@ -0,0 +1,91 @@ +/*++ + +Copyright (c) 2006, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + EdkLogger.java + +Abstract: + +--*/ +package org.tianocore.logger; + +import org.tianocore.logger.LogMethod; + + +public class EdkLog { + private static final String error = "ERROR"; + private static final String warning = "WARNING"; + private static final String info = "INFO"; + private static final String verbose = "VERBOSE"; + private static final String debug = "DEBUG"; + + public static final int EDK_ERROR = 0; + public static final int EDK_WARNING = 1; + public static final int EDK_INFO = 2; + public static final int EDK_VERBOSE = 3; + public static final int EDK_DEBUG = 4; + + private static int logLevel = EDK_INFO; + private static LogMethod logger = new DefaultLogger(); + + public static void log(int level, String message) { + if (level <= logLevel){ + logger.putMessage(null, logLevel, message); + } + + } + + public static void log(int logLevel, String message, Exception cause) { + + } + + public static void log(int logLevel, Exception cause) { + + } + + public static void log(Exception cause) { + + } + + public static void setLogger(LogMethod l) { + logger = l; + } + + public static void setLogLevel (int level){ + logLevel = level; + } + public static void setLogLevel (String level){ + if (level == null){ + return; + } + String levelStr = level.trim(); + if (levelStr.equalsIgnoreCase(error)){ + logLevel = EDK_ERROR; + } + if (levelStr.equalsIgnoreCase(debug)){ + logLevel = EDK_DEBUG; + } + if (levelStr.equalsIgnoreCase(info)){ + logLevel = EDK_INFO; + } + if (levelStr.equalsIgnoreCase(verbose)){ + logLevel = EDK_VERBOSE; + } + if (levelStr.equalsIgnoreCase(warning)){ + logLevel = EDK_WARNING; + } + } + public static int getLogLevel (){ + return logLevel; + } +} + + diff --git a/Tools/Source/Common/org/tianocore/logger/LogMethod.java b/Tools/Source/Common/org/tianocore/logger/LogMethod.java new file mode 100644 index 0000000000..ab6024083a --- /dev/null +++ b/Tools/Source/Common/org/tianocore/logger/LogMethod.java @@ -0,0 +1,23 @@ +/*++ + +Copyright (c) 2006, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + LogMethod.java + +Abstract: + +--*/ +package org.tianocore.logger; + + +public interface LogMethod { + public void putMessage(Object msgSource, int msgLevel, String msg); +} diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/GenBuildLogger.java b/Tools/Source/GenBuild/org/tianocore/build/global/GenBuildLogger.java new file mode 100644 index 0000000000..3578267e12 --- /dev/null +++ b/Tools/Source/GenBuild/org/tianocore/build/global/GenBuildLogger.java @@ -0,0 +1,33 @@ +/*++ + +Copyright (c) 2006, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + GenBuildLogger.java + +Abstract: + +--*/ + +package org.tianocore.build.global; +import org.apache.tools.ant.Project; +import org.tianocore.logger.LogMethod; + +class GenBuildLogger implements LogMethod { + private Project project; + public GenBuildLogger(Project project) { + this.project = project; + + } + + public void putMessage(Object msgSource, int msgLevel, String msg) { + this.project.log(msg, Project.MSG_INFO); + } +} \ No newline at end of file -- cgit v1.2.3