/*++\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
+ 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
+ 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
+ Module Name:\r
+ GenBuildLogger.java\r
\r
-Abstract:\r
+ Abstract:\r
\r
---*/\r
+ --*/\r
\r
package org.tianocore.build.global;\r
+\r
+import java.io.File;\r
+import java.util.List;\r
+import java.util.Vector;\r
+\r
import org.apache.tools.ant.Project;\r
-import org.tianocore.logger.LogMethod;\r
+import org.apache.tools.ant.Task;\r
+\r
+import org.tianocore.common.logger.EdkLog;\r
+import org.tianocore.common.logger.LogMethod;\r
\r
public class GenBuildLogger implements LogMethod {\r
- private Project project;\r
- public GenBuildLogger(Project project) {\r
+ private Project project = null;\r
+\r
+ ///\r
+ /// flag to present whether cache all msg or not\r
+ /// true means not to cache.\r
+ ///\r
+ private boolean flag = true;\r
+\r
+ private List<String> v = null;\r
+\r
+ public GenBuildLogger (Project project) {\r
+ this.project = project;\r
+ }\r
+\r
+ public GenBuildLogger (Project project, boolean flag) {\r
this.project = project;\r
- \r
+ this.flag = flag;\r
+\r
+ //\r
+ // Only flag is false, v will be initialized and used.\r
+ //\r
+ if (!flag) {\r
+ v = new Vector<String>(2048);\r
+ }\r
}\r
\r
- public void putMessage(Object msgSource, int msgLevel, String msg) {\r
- if (this.project != null){\r
- this.project.log(msg, Project.MSG_INFO);\r
+ /**\r
+ Rules: flag = true: means no cache Action: Print it to console\r
+ \r
+ flag = false: mean cache all msg exception some special Action: loglevel\r
+ is EDK_ALWAYS -- Print but no cache loglevel is EDK_ERROR -- Print and\r
+ cache the msg others -- No print and cache the msg\r
+ **/\r
+ public synchronized void putMessage(Object msgSource, int msgLevel,\r
+ String msg) {\r
+ if (this.project == null) {\r
+ return;\r
+ }\r
+\r
+ //\r
+ // If msgLevel is always print, then print it\r
+ //\r
+ switch (msgLevel) {\r
+ case EdkLog.EDK_ALWAYS:\r
+ log(msgSource, msg, Project.MSG_INFO);\r
+ break;\r
+ case EdkLog.EDK_ERROR:\r
+ if (flag) {\r
+ log(msgSource, msg, Project.MSG_ERR);\r
+ } else {\r
+ log(msgSource, msg, Project.MSG_ERR);\r
+ v.add(msg);\r
+ }\r
+ break;\r
+ case EdkLog.EDK_WARNING:\r
+ if (flag) {\r
+ log(msgSource, msg, Project.MSG_WARN);\r
+ } else {\r
+ v.add(msg);\r
+ }\r
+ break;\r
+ case EdkLog.EDK_INFO:\r
+ if (flag) {\r
+ log(msgSource, msg, Project.MSG_INFO);\r
+ } else {\r
+ v.add(msg);\r
+ }\r
+ break;\r
+ case EdkLog.EDK_VERBOSE:\r
+ if (flag) {\r
+ log(msgSource, msg, Project.MSG_VERBOSE);\r
+ } else {\r
+ v.add(msg);\r
+ }\r
+ break;\r
+ case EdkLog.EDK_DEBUG:\r
+ if (flag) {\r
+ log(msgSource, msg, Project.MSG_DEBUG);\r
+ } else {\r
+ v.add(msg);\r
+ }\r
+ break;\r
+ }\r
+ }\r
+\r
+ public void flushToFile(File file) {\r
+ //\r
+ // Sort msg and store to the file (TBD)\r
+ //\r
+\r
+ }\r
+ \r
+ private void log(Object msgSource, String msg, int level) {\r
+ if (msgSource instanceof Task) {\r
+ this.project.log((Task)msgSource, msg, level);\r
+ } else if (msgSource instanceof String){\r
+ \r
+ //\r
+ // Pad 12 space to keep message \r
+ //\r
+ msg = msg.replaceAll("\n", "\n ");\r
+ this.project.log(String.format("%12s", "[" + msgSource + "] ") + msg, level);\r
+ } else {\r
+ this.project.log(msg, level);\r
}\r
- \r
}\r
}
\ No newline at end of file