Class: TaskJuggler::MessageHandlerInstance
- Includes:
- Singleton
- Defined in:
- lib/taskjuggler/MessageHandler.rb
Overview
The MessageHandler can display and store application messages. Depending on the type of the message, a TjExeption can be raised (:error), or the program can be immedidately aborted (:fatal). Other types will just continue the program flow.
Constant Summary collapse
- LogLevels =
{ :none => 0, :fatal => 1, :error => 2, :critical => 2, :warning => 3, :info => 4, :debug => 5 }
Instance Attribute Summary collapse
-
#abortOnWarning ⇒ Object
Returns the value of attribute abortOnWarning.
-
#appName ⇒ Object
Returns the value of attribute appName.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#logFile ⇒ Object
Returns the value of attribute logFile.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
- #baselineSFI=(line) ⇒ Object
-
#clear ⇒ Object
Clear the error log.
-
#critical(id, message, sourceFileInfo = nil, line = nil, data = nil, scenario = nil) ⇒ Object
Generate an critical message.
-
#debug(id, message, sourceFileInfo = nil, line = nil, data = nil, scenario = nil) ⇒ Object
Generate a debug message.
-
#error(id, message, sourceFileInfo = nil, line = nil, data = nil, scenario = nil) ⇒ Object
Generate an error message.
-
#fatal(id, message, sourceFileInfo = nil, line = nil, data = nil, scenario = nil) ⇒ Object
Generate a fatal message that will abort the application.
-
#info(id, message, sourceFileInfo = nil, line = nil, data = nil, scenario = nil) ⇒ Object
Generate an info message.
-
#initialize ⇒ MessageHandlerInstance
constructor
Initialize the MessageHandler.
-
#logLevel=(level) ⇒ Object
Set the log output level.
-
#outputLevel=(level) ⇒ Object
Set the console output level.
-
#reset ⇒ Object
Reset the MessageHandler to the initial state.
-
#to_s ⇒ Object
Convert all messages into a single String.
- #trapSetup=(enable) ⇒ Object
-
#warning(id, message, sourceFileInfo = nil, line = nil, data = nil, scenario = nil) ⇒ Object
Generate a warning.
Constructor Details
#initialize ⇒ MessageHandlerInstance
Initialize the MessageHandler.
124 125 126 |
# File 'lib/taskjuggler/MessageHandler.rb', line 124 def initialize reset end |
Instance Attribute Details
#abortOnWarning ⇒ Object
Returns the value of attribute abortOnWarning.
118 119 120 |
# File 'lib/taskjuggler/MessageHandler.rb', line 118 def abortOnWarning @abortOnWarning end |
#appName ⇒ Object
Returns the value of attribute appName.
118 119 120 |
# File 'lib/taskjuggler/MessageHandler.rb', line 118 def appName @appName end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
117 118 119 |
# File 'lib/taskjuggler/MessageHandler.rb', line 117 def errors @errors end |
#logFile ⇒ Object
Returns the value of attribute logFile.
118 119 120 |
# File 'lib/taskjuggler/MessageHandler.rb', line 118 def logFile @logFile end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
117 118 119 |
# File 'lib/taskjuggler/MessageHandler.rb', line 117 def @messages end |
Instance Method Details
#baselineSFI=(line) ⇒ Object
155 156 157 |
# File 'lib/taskjuggler/MessageHandler.rb', line 155 def baselineSFI=(line) @baselineSFI[Thread.current.object_id] = line end |
#clear ⇒ Object
Clear the error log.
164 165 166 167 168 169 |
# File 'lib/taskjuggler/MessageHandler.rb', line 164 def clear # A counter for messages of type error. @errors = 0 # A list of all generated messages. @messages = [] end |
#critical(id, message, sourceFileInfo = nil, line = nil, data = nil, scenario = nil) ⇒ Object
Generate an critical message.
195 196 197 198 |
# File 'lib/taskjuggler/MessageHandler.rb', line 195 def critical(id, , sourceFileInfo = nil, line = nil, data = nil, scenario = nil) addMessage(:critical, id, , sourceFileInfo, line, data, scenario) end |
#debug(id, message, sourceFileInfo = nil, line = nil, data = nil, scenario = nil) ⇒ Object
Generate a debug message.
213 214 215 216 |
# File 'lib/taskjuggler/MessageHandler.rb', line 213 def debug(id, , sourceFileInfo = nil, line = nil, data = nil, scenario = nil) addMessage(:debug, id, , sourceFileInfo, line, data, scenario) end |
#error(id, message, sourceFileInfo = nil, line = nil, data = nil, scenario = nil) ⇒ Object
Generate an error message.
189 190 191 192 |
# File 'lib/taskjuggler/MessageHandler.rb', line 189 def error(id, , sourceFileInfo = nil, line = nil, data = nil, scenario = nil) addMessage(:error, id, , sourceFileInfo, line, data, scenario) end |
#fatal(id, message, sourceFileInfo = nil, line = nil, data = nil, scenario = nil) ⇒ Object
Generate a fatal message that will abort the application.
183 184 185 186 |
# File 'lib/taskjuggler/MessageHandler.rb', line 183 def fatal(id, , sourceFileInfo = nil, line = nil, data = nil, scenario = nil) addMessage(:fatal, id, , sourceFileInfo, line, data, scenario) end |
#info(id, message, sourceFileInfo = nil, line = nil, data = nil, scenario = nil) ⇒ Object
Generate an info message.
207 208 209 210 |
# File 'lib/taskjuggler/MessageHandler.rb', line 207 def info(id, , sourceFileInfo = nil, line = nil, data = nil, scenario = nil) addMessage(:info, id, , sourceFileInfo, line, data, scenario) end |
#logLevel=(level) ⇒ Object
Set the log output level.
178 179 180 |
# File 'lib/taskjuggler/MessageHandler.rb', line 178 def logLevel=(level) @logLevel = checkLevel(level) end |
#outputLevel=(level) ⇒ Object
Set the console output level.
173 174 175 |
# File 'lib/taskjuggler/MessageHandler.rb', line 173 def outputLevel=(level) @outputLevel = checkLevel(level) end |
#reset ⇒ Object
Reset the MessageHandler to the initial state. All messages will be purged and the error counter set to 0.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/taskjuggler/MessageHandler.rb', line 130 def reset # This setting controls what type of messages will be written to the # console. @outputLevel = 4 # This setting controls what type of messages will be written to the log # file. @logLevel = 3 # The full file name of the log file. @logFile = nil # The name of the current application @appName = 'unknown' # Set to true if program should be exited on warnings. @abortOnWarning = false # A SourceFileInfo object that will be used to baseline the provided # source file infos of the messages. We use a Hash to keep per Thread # values. @baselineSFI = {} # Each tread can request to only throw a TjRuntimeError instead of # using exit(). This hash keeps a flag for each thread using the # object_id of the Thread object as key. @trapSetup = {} clear end |
#to_s ⇒ Object
Convert all messages into a single String.
219 220 221 222 223 |
# File 'lib/taskjuggler/MessageHandler.rb', line 219 def to_s text = '' @messages.each { |msg| text += msg.to_s } text end |
#trapSetup=(enable) ⇒ Object
159 160 161 |
# File 'lib/taskjuggler/MessageHandler.rb', line 159 def trapSetup=(enable) @trapSetup[Thread.current.object_id] = enable end |
#warning(id, message, sourceFileInfo = nil, line = nil, data = nil, scenario = nil) ⇒ Object
Generate a warning.
201 202 203 204 |
# File 'lib/taskjuggler/MessageHandler.rb', line 201 def warning(id, , sourceFileInfo = nil, line = nil, data = nil, scenario = nil) addMessage(:warning, id, , sourceFileInfo, line, data, scenario) end |