a67d2f9e4d79b59c108150e3336e9bb166167fb2
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / action / ActionMessage.java
1 /** @file
2 ActionMessage class.
3
4 ActionMessage class take over all message for loging and waning. This class should
5 dispatch message into different class according to instance class type.
6
7 Copyright (c) 2006, Intel Corporation
8 All rights reserved. This program and the accompanying materials
9 are licensed and made available under the terms and conditions of the BSD License
10 which accompanies this distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15
16 **/
17 package org.tianocore.build.pcd.action;
18
19 import org.apache.tools.ant.Task;
20 import org.tianocore.build.pcd.action.BuildAction;
21 import org.tianocore.build.pcd.action.UIAction;
22
23 /** ActionMessage class take over all message for loging and waning. This class
24 should dispatch message into different Action class according to instance
25 class type.
26 **/
27 public class ActionMessage {
28 ///
29 /// Macro definition for NULL messge level.
30 /// In this meessage level, all message will be hidden.
31 ///
32 public final static int NULL_MESSAGE_LEVEL = 0;
33 ///
34 /// Macro definition for Log messge level.
35 /// In this message level, Only log information will be shown.
36 ///
37 public final static int LOG_MESSAGE_LEVEL = 1;
38 ///
39 /// Macro definition for Warning message level.
40 /// In this message level, log and waning message will be shown.
41 ///
42 public final static int WARNING_MESSAGE_LEVEL = 2;
43 ///
44 /// Macro definition for Debug mesage level.
45 /// In this message level, log, warning, debug message will be shown.
46 ///
47 public final static int DEBUG_MESSAGE_LEVEL = 3;
48 ///
49 /// Macor definition for MAX message level.
50 /// In this message level, all message will be shown.
51 ///
52 public final static int MAX_MESSAGE_LEVEL = 4;
53 ///
54 /// Current message level. It will control all message output for PCD tool.
55 ///
56 public static int messageLevel = NULL_MESSAGE_LEVEL;
57
58 /**
59 Log() function provide common log information functionality for all
60 PCD tool includes all function
61
62 This function will dispatch message to special class such as BuildAction
63 Class, Entity Class etc.
64
65 @param thisClass The class object who want log information.
66 @param logStr The string contains log information.
67 **/
68 public static void log(Object thisClass, String logStr) {
69 if(messageLevel < LOG_MESSAGE_LEVEL) {
70 return;
71 }
72
73 if(thisClass instanceof Task) {
74 BuildAction.logMsg(thisClass, "$$LOG$$:" + logStr);
75 } else if(thisClass instanceof UIAction) {
76 UIAction.logMsg(thisClass, "$$LOG$$:" + logStr);
77 } else {
78 System.out.println("$$LOG$$:" + logStr);
79 }
80 }
81
82 /**
83 Warning() function provide common warning information functionality for all
84 PCD tool.
85
86 This function will dispatch message to special class such as BuildAction
87 Class, Entity Class etc.
88
89 @param thisClass The class object who want warn information.
90 @param warningStr The string contains warning information.
91 **/
92 public static void warning(Object thisClass, String warningStr) {
93 if(messageLevel < WARNING_MESSAGE_LEVEL) {
94 return;
95 }
96
97 if(thisClass instanceof Task) {
98 BuildAction.warningMsg(thisClass, "**WARNING**:" + warningStr);
99 } else if(thisClass instanceof UIAction) {
100 UIAction.warningMsg(thisClass, "**WARNING**:" + warningStr);
101 } else {
102 System.out.println("**WARNING**:" + warningStr);
103 }
104 }
105
106 /**
107 Debug() function provide common Debug information functionality for all
108 PCD tool.
109
110 This function will dispatch message to special class such as BuildAction
111 Class, Entity Class etc.
112
113 @param thisClass The class object who want Debug information.
114 @param debugStr The string contains Debug information.
115 **/
116 public static void debug(Object thisClass, String debugStr) {
117 if(messageLevel < DEBUG_MESSAGE_LEVEL) {
118 return;
119 }
120
121 if(thisClass instanceof Task) {
122 BuildAction.logMsg(thisClass, "%%DEBUG%%:" + debugStr);
123 } else if(thisClass instanceof UIAction) {
124 UIAction.logMsg(thisClass, "%%DEBUG%%:" + debugStr);
125 } else {
126 System.out.println("%%DEBUG%%:" + debugStr);
127 }
128 }
129 }