Change GenBuildLogger format.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / GenBuildLogger.java
CommitLineData
b9546cc8 1/*++\r
2\r
c8df018e 3 Copyright (c) 2006, Intel Corporation\r
4 All rights reserved. This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
b9546cc8 8\r
c8df018e 9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
b9546cc8 11\r
c8df018e 12 Module Name:\r
13 GenBuildLogger.java\r
b9546cc8 14\r
c8df018e 15 Abstract:\r
b9546cc8 16\r
c8df018e 17 --*/\r
b9546cc8 18\r
19package org.tianocore.build.global;\r
ff225cbb 20\r
c8df018e 21import java.io.File;\r
22import java.util.List;\r
23import java.util.Vector;\r
24\r
b9546cc8 25import org.apache.tools.ant.Project;\r
91f7d582 26import org.apache.tools.ant.Task;\r
ff225cbb 27\r
c8df018e 28import org.tianocore.common.logger.EdkLog;\r
ff225cbb 29import org.tianocore.common.logger.LogMethod;\r
b9546cc8 30\r
31public class GenBuildLogger implements LogMethod {\r
c8df018e 32 private Project project = null;\r
33\r
34 ///\r
35 /// flag to present whether cache all msg or not\r
36 /// true means not to cache.\r
37 ///\r
38 private boolean flag = true;\r
39\r
40 private List<String> v = null;\r
41\r
42 public GenBuildLogger (Project project) {\r
43 this.project = project;\r
44 }\r
45\r
46 public GenBuildLogger (Project project, boolean flag) {\r
b9546cc8 47 this.project = project;\r
c8df018e 48 this.flag = flag;\r
ff225cbb 49\r
c8df018e 50 //\r
51 // Only flag is false, v will be initialized and used.\r
52 //\r
53 if (!flag) {\r
54 v = new Vector<String>(2048);\r
55 }\r
b9546cc8 56 }\r
57\r
c8df018e 58 /**\r
59 Rules: flag = true: means no cache Action: Print it to console\r
60 \r
61 flag = false: mean cache all msg exception some special Action: loglevel\r
62 is EDK_ALWAYS -- Print but no cache loglevel is EDK_ERROR -- Print and\r
63 cache the msg others -- No print and cache the msg\r
64 **/\r
65 public synchronized void putMessage(Object msgSource, int msgLevel,\r
66 String msg) {\r
67 if (this.project == null) {\r
68 return;\r
69 }\r
70\r
71 //\r
72 // If msgLevel is always print, then print it\r
73 //\r
74 switch (msgLevel) {\r
75 case EdkLog.EDK_ALWAYS:\r
91f7d582 76 log(msgSource, msg, Project.MSG_INFO);\r
c8df018e 77 break;\r
78 case EdkLog.EDK_ERROR:\r
79 if (flag) {\r
91f7d582 80 log(msgSource, msg, Project.MSG_ERR);\r
c8df018e 81 } else {\r
91f7d582 82 log(msgSource, msg, Project.MSG_ERR);\r
c8df018e 83 v.add(msg);\r
84 }\r
85 break;\r
86 case EdkLog.EDK_WARNING:\r
87 if (flag) {\r
91f7d582 88 log(msgSource, msg, Project.MSG_WARN);\r
c8df018e 89 } else {\r
90 v.add(msg);\r
91 }\r
92 break;\r
93 case EdkLog.EDK_INFO:\r
94 if (flag) {\r
91f7d582 95 log(msgSource, msg, Project.MSG_INFO);\r
c8df018e 96 } else {\r
97 v.add(msg);\r
98 }\r
99 break;\r
100 case EdkLog.EDK_VERBOSE:\r
101 if (flag) {\r
91f7d582 102 log(msgSource, msg, Project.MSG_VERBOSE);\r
c8df018e 103 } else {\r
104 v.add(msg);\r
105 }\r
106 break;\r
107 case EdkLog.EDK_DEBUG:\r
108 if (flag) {\r
91f7d582 109 log(msgSource, msg, Project.MSG_DEBUG);\r
c8df018e 110 } else {\r
111 v.add(msg);\r
112 }\r
113 break;\r
b9546cc8 114 }\r
c8df018e 115 }\r
116\r
117 public void flushToFile(File file) {\r
118 //\r
119 // Sort msg and store to the file (TBD)\r
120 //\r
ff225cbb 121\r
b9546cc8 122 }\r
91f7d582 123 \r
124 private void log(Object msgSource, String msg, int level) {\r
125 if (msgSource instanceof Task) {\r
126 this.project.log((Task)msgSource, msg, level);\r
2619585a 127 } else if (msgSource instanceof String){\r
128 \r
129 //\r
130 // Pad 12 space to keep message \r
131 //\r
132 msg = msg.replaceAll("\n", "\n ");\r
133 this.project.log(String.format("%12s", "[" + msgSource + "] ") + msg, level);\r
91f7d582 134 } else {\r
135 this.project.log(msg, level);\r
136 }\r
137 }\r
b9546cc8 138}