]>
Commit | Line | Data |
---|---|---|
1 | /*++\r | |
2 | \r | |
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 | |
8 | \r | |
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 | |
11 | \r | |
12 | Module Name:\r | |
13 | GenBuildLogger.java\r | |
14 | \r | |
15 | Abstract:\r | |
16 | \r | |
17 | --*/\r | |
18 | \r | |
19 | package org.tianocore.build.global;\r | |
20 | \r | |
21 | import java.io.File;\r | |
22 | import java.util.List;\r | |
23 | import java.util.Vector;\r | |
24 | \r | |
25 | import org.apache.tools.ant.Project;\r | |
26 | import org.apache.tools.ant.Task;\r | |
27 | \r | |
28 | import org.tianocore.common.logger.EdkLog;\r | |
29 | import org.tianocore.common.logger.LogMethod;\r | |
30 | \r | |
31 | public class GenBuildLogger implements LogMethod {\r | |
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 | |
47 | this.project = project;\r | |
48 | this.flag = flag;\r | |
49 | \r | |
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 | |
56 | }\r | |
57 | \r | |
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 | |
76 | log(msgSource, msg, Project.MSG_INFO);\r | |
77 | break;\r | |
78 | case EdkLog.EDK_ERROR:\r | |
79 | if (flag) {\r | |
80 | log(msgSource, msg, Project.MSG_ERR);\r | |
81 | } else {\r | |
82 | log(msgSource, msg, Project.MSG_ERR);\r | |
83 | v.add(msg);\r | |
84 | }\r | |
85 | break;\r | |
86 | case EdkLog.EDK_WARNING:\r | |
87 | if (flag) {\r | |
88 | log(msgSource, msg, Project.MSG_WARN);\r | |
89 | } else {\r | |
90 | v.add(msg);\r | |
91 | }\r | |
92 | break;\r | |
93 | case EdkLog.EDK_INFO:\r | |
94 | if (flag) {\r | |
95 | log(msgSource, msg, Project.MSG_INFO);\r | |
96 | } else {\r | |
97 | v.add(msg);\r | |
98 | }\r | |
99 | break;\r | |
100 | case EdkLog.EDK_VERBOSE:\r | |
101 | if (flag) {\r | |
102 | log(msgSource, msg, Project.MSG_VERBOSE);\r | |
103 | } else {\r | |
104 | v.add(msg);\r | |
105 | }\r | |
106 | break;\r | |
107 | case EdkLog.EDK_DEBUG:\r | |
108 | if (flag) {\r | |
109 | log(msgSource, msg, Project.MSG_DEBUG);\r | |
110 | } else {\r | |
111 | v.add(msg);\r | |
112 | }\r | |
113 | break;\r | |
114 | }\r | |
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 | |
121 | \r | |
122 | }\r | |
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 | |
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 | |
134 | } else {\r | |
135 | this.project.log(msg, level);\r | |
136 | }\r | |
137 | }\r | |
138 | } |