Module: MotherBrain::Logging
- Extended by:
- Logger::Severity
- Includes:
- Logger::Severity
- Included in:
- API::Endpoint, Application, Application::SupervisionGroup, Berkshelf::Lockfile, Bootstrap::Manager, Bootstrap::Worker, ChefMutex, CleanRoomBase, CommandInvoker, ConfigManager, EnvironmentManager, Gear::DynamicService, Job::StateMachine, JobManager, LockManager, Mixin::AttributeSetting, NodeQuerier, PluginManager, Provisioner::Base, Provisioner::Manager, RestGateway, Upgrade::Manager, Upgrade::Worker
- Defined in:
- lib/mb/logging.rb,
lib/mb/logging/basic_format.rb
Defined Under Namespace
Classes: BasicFormat
Class Method Summary collapse
-
.add_argument_header ⇒ Object
Places the arguments given surrounded by whitespace at the top of the logfile.
-
.dev ⇒ IO?
Returns the currrent logging device.
-
.filename ⇒ String?
Returns the filename of the current logger.
- .logger ⇒ Logger
- .reset ⇒ nil
- .set_logger(obj) ⇒ Logger
- .setup(options = {}) ⇒ Logger
Instance Method Summary collapse
-
#log_exception(ex) ⇒ Object
Log an exception and it’s backtrace to FATAL.
- #logger ⇒ Logger (also: #log)
Class Method Details
.add_argument_header ⇒ Object
Places the arguments given surrounded by whitespace at the top of the logfile. This makes it easier to scan logs for the beginning of a command.
14 15 16 17 18 19 20 21 |
# File 'lib/mb/logging.rb', line 14 def add_argument_header return if dev == STDOUT logger.unknown nil logger.unknown nil logger.unknown ARGV.join(" ") logger.unknown nil end |
.dev ⇒ IO?
Returns the currrent logging device
26 27 28 |
# File 'lib/mb/logging.rb', line 26 def dev logdev.dev end |
.filename ⇒ String?
Returns the filename of the current logger
33 34 35 |
# File 'lib/mb/logging.rb', line 33 def filename logdev.filename end |
.logger ⇒ Logger
38 39 40 |
# File 'lib/mb/logging.rb', line 38 def logger @logger ||= setup end |
.reset ⇒ nil
43 44 45 46 |
# File 'lib/mb/logging.rb', line 43 def reset @logger = nil @preserved_options = nil end |
.set_logger(obj) ⇒ Logger
92 93 94 |
# File 'lib/mb/logging.rb', line 92 def set_logger(obj) @logger = (obj.nil? ? Logger.new('/dev/null') : obj) end |
.setup(options = {}) ⇒ Logger
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/mb/logging.rb', line 52 def setup( = {}) = .keep_if { |key, value| value } = preserve().reverse_merge( level: INFO, location: FileSystem.logs.join('application.log') ) level = [:level].is_a?(String) ? [:level].upcase : [:level] location = [:location] if %w[DEBUG INFO WARN ERROR FATAL].include?(level) level = const_get(level) end if %w[STDERR STDOUT].include?(location) location = location.constantize end unless [STDERR, STDOUT].include?(location) setup_logdir(location) end if jruby? && location.is_a?(Pathname) location = location.to_s end @logger = Ridley::Logging::Logger.new(location).tap do |log| log.level = level log.formatter = BasicFormat.new end Ridley.logger = @logger Celluloid.logger = ENV["DEBUG_CELLULOID"] ? @logger : nil @logger end |
Instance Method Details
#log_exception(ex) ⇒ Object
Log an exception and it’s backtrace to FATAL
127 128 129 130 131 132 |
# File 'lib/mb/logging.rb', line 127 def log_exception(ex) ex = ex.respond_to?(:cause) ? ex.cause : ex log.fatal { "#{ex.class}: #{ex}" } log.fatal { ex.backtrace.join("\n") } unless ex.backtrace.nil? end |
#logger ⇒ Logger Also known as: log
119 120 121 |
# File 'lib/mb/logging.rb', line 119 def logger MB::Logging.logger end |