]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add log and exception mechanism
authorqouyang <qouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 20 Jun 2006 06:24:39 +0000 (06:24 +0000)
committerqouyang <qouyang@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 20 Jun 2006 06:24:39 +0000 (06:24 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@566 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/Common/org/tianocore/exception/EdkException.java [new file with mode: 0644]
Tools/Source/Common/org/tianocore/logger/DefaultLogger.java [new file with mode: 0644]
Tools/Source/Common/org/tianocore/logger/EdkLog.java [new file with mode: 0644]
Tools/Source/Common/org/tianocore/logger/LogMethod.java [new file with mode: 0644]
Tools/Source/GenBuild/org/tianocore/build/global/GenBuildLogger.java [new file with mode: 0644]

diff --git a/Tools/Source/Common/org/tianocore/exception/EdkException.java b/Tools/Source/Common/org/tianocore/exception/EdkException.java
new file mode 100644 (file)
index 0000000..d625897
--- /dev/null
@@ -0,0 +1,47 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+  EdkException.java\r
+\r
+Abstract:\r
+\r
+--*/\r
+package org.tianocore.exception;\r
+\r
+public class EdkException extends Exception {\r
+    private StackTraceElement[] stackTrace;\r
+    public static boolean isPrintStack = false;\r
+\r
+    public EdkException(String message) {\r
+        super("[EdkException]:" + message);\r
+    }\r
+\r
+    public EdkException(String message, boolean traceStack) {\r
+        super(message);\r
+        \r
+    }\r
+    \r
+    public EdkException(){\r
+        super();\r
+    }\r
+    \r
+    public EdkException(Exception e, String message){\r
+        super("[EdkException]:" + message);\r
+        if (isPrintStack){\r
+            this.setStackTrace(e.getStackTrace());\r
+        }\r
+        e.printStackTrace();\r
+    }\r
+    public static void setIsprintStack (boolean flag){\r
+        isPrintStack = flag;\r
+    }\r
+}\r
diff --git a/Tools/Source/Common/org/tianocore/logger/DefaultLogger.java b/Tools/Source/Common/org/tianocore/logger/DefaultLogger.java
new file mode 100644 (file)
index 0000000..4bec8e5
--- /dev/null
@@ -0,0 +1,36 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+  DefaultLogger.java\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+package org.tianocore.logger;\r
+import java.util.logging.Level;\r
+import java.util.logging.Logger;\r
+\r
+class DefaultLogger implements LogMethod {\r
+    private Logger logger = Logger.global;\r
+    private static Level[] levelMap = {\r
+        Level.SEVERE, Level.WARNING, Level.INFO, Level.FINE, Level.ALL\r
+    };\r
+\r
+    public DefaultLogger() {\r
+\r
+    }\r
+\r
+    public void putMessage(Object msgSource, int msgLevel, String msg) {\r
+        logger.log(levelMap[msgLevel], msg);\r
+    }\r
+}
\ 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 (file)
index 0000000..b16d39c
--- /dev/null
@@ -0,0 +1,91 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+  EdkLogger.java\r
+\r
+Abstract:\r
+\r
+--*/\r
+package org.tianocore.logger;\r
+\r
+import org.tianocore.logger.LogMethod;\r
+\r
+\r
+public class EdkLog {\r
+    private static final String error    = "ERROR";\r
+    private static final String warning  = "WARNING";\r
+    private static final String info     = "INFO";\r
+    private static final String verbose  = "VERBOSE";\r
+    private static final String debug    = "DEBUG";\r
+    \r
+    public static final int EDK_ERROR   = 0;\r
+    public static final int EDK_WARNING = 1;\r
+    public static final int EDK_INFO    = 2;\r
+    public static final int EDK_VERBOSE = 3;\r
+    public static final int EDK_DEBUG   = 4;\r
+\r
+    private static int logLevel = EDK_INFO;\r
+    private static LogMethod logger = new DefaultLogger();\r
+\r
+    public static void log(int level, String message) {\r
+        if (level <= logLevel){\r
+            logger.putMessage(null, logLevel, message);  \r
+        }\r
+       \r
+    }\r
+\r
+    public static void log(int logLevel, String message, Exception cause) {\r
+\r
+    }\r
+\r
+    public static void log(int logLevel, Exception cause) {\r
+\r
+    }\r
+\r
+    public static void log(Exception cause) {\r
+\r
+    }\r
+\r
+    public static void setLogger(LogMethod l) {\r
+        logger = l;\r
+    }\r
+    \r
+    public static void setLogLevel (int level){\r
+        logLevel = level;\r
+    }\r
+    public static void setLogLevel (String level){\r
+       if (level == null){\r
+           return;\r
+       }\r
+       String levelStr = level.trim();\r
+       if (levelStr.equalsIgnoreCase(error)){\r
+           logLevel = EDK_ERROR;\r
+       }\r
+       if (levelStr.equalsIgnoreCase(debug)){\r
+           logLevel = EDK_DEBUG;\r
+       } \r
+       if (levelStr.equalsIgnoreCase(info)){\r
+           logLevel = EDK_INFO;\r
+       } \r
+       if (levelStr.equalsIgnoreCase(verbose)){\r
+           logLevel = EDK_VERBOSE;\r
+       } \r
+       if (levelStr.equalsIgnoreCase(warning)){\r
+           logLevel = EDK_WARNING;\r
+       } \r
+    }\r
+    public static int getLogLevel (){\r
+        return logLevel;\r
+    }\r
+}\r
+\r
+\r
diff --git a/Tools/Source/Common/org/tianocore/logger/LogMethod.java b/Tools/Source/Common/org/tianocore/logger/LogMethod.java
new file mode 100644 (file)
index 0000000..ab60240
--- /dev/null
@@ -0,0 +1,23 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+  LogMethod.java\r
+\r
+Abstract:\r
+\r
+--*/\r
+package org.tianocore.logger;\r
+\r
+\r
+public interface LogMethod {\r
+    public void putMessage(Object msgSource, int msgLevel, String msg);\r
+}\r
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 (file)
index 0000000..3578267
--- /dev/null
@@ -0,0 +1,33 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+Module Name:\r
+  GenBuildLogger.java\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+package org.tianocore.build.global;\r
+import org.apache.tools.ant.Project;\r
+import org.tianocore.logger.LogMethod;\r
+\r
+class GenBuildLogger implements LogMethod {\r
+    private Project project;\r
+    public GenBuildLogger(Project project) {\r
+        this.project = project;\r
+        \r
+    }\r
+\r
+    public void putMessage(Object msgSource, int msgLevel, String msg) {\r
+        this.project.log(msg, Project.MSG_INFO);\r
+    }\r
+}
\ No newline at end of file