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
-
.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
.debug(channel = nil) ⇒ Object
Prints a debug message, on channel channel. Channel handling is not implemented yet.
30 31 32 |
# File 'lib/ctioga2/log.rb', line 30 def debug(channel = nil) @@logger.debug {yield} end |
.error ⇒ Object
Prints an error message
45 46 47 |
# File 'lib/ctioga2/log.rb', line 45 def error @@logger.error {yield} end |
.fatal ⇒ Object
Prints a fatal error message and initiates program termination.
50 51 52 53 |
# File 'lib/ctioga2/log.rb', line 50 def fatal @@logger.fatal {yield} exit 1 # Fatal error. end |
.info ⇒ Object
Prints an informational message
40 41 42 |
# File 'lib/ctioga2/log.rb', line 40 def info @@logger.info {yield} end |
.init_logger(stream = STDERR) ⇒ Object
63 64 65 66 67 |
# File 'lib/ctioga2/log.rb', line 63 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.
70 71 72 |
# File 'lib/ctioga2/log.rb', line 70 def self.logger return @@logger end |
.set_level(level = Logger::WARN) ⇒ Object
Sets the logging level.
75 76 77 |
# File 'lib/ctioga2/log.rb', line 75 def self.set_level(level = Logger::WARN) @@logger.level = level end |
.warn ⇒ Object
Prints a warning message
35 36 37 |
# File 'lib/ctioga2/log.rb', line 35 def warn @@logger.warn {yield} end |
Instance Method Details
#format_exception(e) ⇒ Object
Format an exception for displaying
59 60 61 |
# File 'lib/ctioga2/log.rb', line 59 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.
95 96 97 |
# File 'lib/ctioga2/log.rb', line 95 def identify(obj) return "#<%s 0x%x>" % [obj.class, obj.object_id] end |
#spawn(cmd, priority = :info) ⇒ Object
A logged replacement for system
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ctioga2/log.rb', line 80 def spawn(cmd, priority = :info) retval = system(cmd) self.send(priority) { "Spawned #{cmd} -> " + if retval "success" else "failure" end } return retval end |