Module: CTioga2::Log
- Included in:
- Commands::Documentation::Man, Commands::Documentation::MarkedUpText, Commands::Parsers::CommandLineParser, Commands::Parsers::FileParser, Data::Backends::Backend, Data::Backends::GnuplotBackend, Data::DataStack, Data::Dataset, Graphics::Elements::Curve2D, Graphics::Elements::Parametric2D, Graphics::Elements::TiogaElement, Graphics::Elements::XYZMap, Graphics::Legends::CurveLegend, Graphics::Styles::CurveStyleFactory, Graphics::Styles::PlotStyle, Graphics::Styles::TwoPointGradient, PlotMaker, PostProcess
- Defined in:
- lib/ctioga2/log.rb
Overview
The debug information should contain the command being
This module should be included (or extended) by every class that need logging/debugging facilities.
currently executed.
Class Method Summary collapse
- .context ⇒ Object
-
.debug(channel = nil) ⇒ Object
Prints a debug message, on channel channel.
-
.error ⇒ Object
Prints an error message.
-
.fatal ⇒ Object
Prints a fatal error message and initiates program termination.
-
.info ⇒ Object
Prints an informational message.
- .init_logger(stream = STDERR) ⇒ Object
-
.logger ⇒ Object
Simple accessor for the @@log class variable.
-
.set_level(level = Logger::WARN) ⇒ Object
Sets the logging level.
-
.warn ⇒ Object
Prints a warning message.
Instance Method Summary collapse
-
#format_exception(e) ⇒ Object
Format an exception for displaying.
-
#identify(obj) ⇒ Object
Returns a string suitable for identification of an object, a bit in the spirit of #inspect, but without displaying instance variables.
-
#spawn(cmd, priority = :info) ⇒ Object
A logged replacement for system.
Class Method Details
.context ⇒ Object
28 29 30 |
# File 'lib/ctioga2/log.rb', line 28 def self.context return " while processing #{PlotMaker.plotmaker.interpreter.context.to_s}" end |
.debug(channel = nil) ⇒ Object
Prints a debug message, on channel channel. Channel handling is not implemented yet.
34 35 36 |
# File 'lib/ctioga2/log.rb', line 34 def debug(channel = nil) @@logger.debug {yield + Log.context} end |
.error ⇒ Object
Prints an error message
49 50 51 |
# File 'lib/ctioga2/log.rb', line 49 def error @@logger.error {yield + Log.context} end |
.fatal ⇒ Object
Prints a fatal error message and initiates program termination.
54 55 56 57 |
# File 'lib/ctioga2/log.rb', line 54 def fatal @@logger.fatal {yield + Log.context} exit 1 # Fatal error. end |
.info ⇒ Object
Prints an informational message
44 45 46 |
# File 'lib/ctioga2/log.rb', line 44 def info @@logger.info {yield + Log.context} end |
.init_logger(stream = STDERR) ⇒ Object
67 68 69 70 71 |
# File 'lib/ctioga2/log.rb', line 67 def self.init_logger(stream = STDERR) Logger::Formatter::Format.replace("[%4$s] %6$s\n") @@logger = Logger.new(stream) @@logger.level = Logger::WARN # Warnings and more only by default end |
.logger ⇒ Object
Simple accessor for the @@log class variable.
74 75 76 |
# File 'lib/ctioga2/log.rb', line 74 def self.logger return @@logger end |
.set_level(level = Logger::WARN) ⇒ Object
Sets the logging level.
79 80 81 |
# File 'lib/ctioga2/log.rb', line 79 def self.set_level(level = Logger::WARN) @@logger.level = level end |
Instance Method Details
#format_exception(e) ⇒ Object
Format an exception for displaying
63 64 65 |
# File 'lib/ctioga2/log.rb', line 63 def format_exception(e) return "#{e.class}: #{e.}\n\t#{e.backtrace.join("\n\t")}" end |
#identify(obj) ⇒ Object
Returns a string suitable for identification of an object, a bit in the spirit of #inspect, but without displaying instance variables.
99 100 101 |
# File 'lib/ctioga2/log.rb', line 99 def identify(obj) return "#<%s 0x%x>" % [obj.class, obj.object_id] end |
#spawn(cmd, priority = :info) ⇒ Object
A logged replacement for system
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ctioga2/log.rb', line 84 def spawn(cmd, priority = :info) retval = system(cmd) self.send(priority) { "Spawned #{cmd} -> " + if retval "success" else "failure" end } return retval end |