Module: SimplyGenius::Atmos::Logging
- Defined in:
- lib/simplygenius/atmos/logging.rb
Defined Under Namespace
Modules: GemLoggerConcern Classes: CaptureStream
Class Method Summary collapse
- .clear ⇒ Object
- .contents ⇒ Object
- .init_logger ⇒ Object
- .setup_logging(level, color, logfile) ⇒ Object
- .sio ⇒ Object
- .testing ⇒ Object
- .testing=(t) ⇒ Object
Class Method Details
.clear ⇒ Object
100 101 102 |
# File 'lib/simplygenius/atmos/logging.rb', line 100 def self.clear sio.try(:clear) end |
.contents ⇒ Object
96 97 98 |
# File 'lib/simplygenius/atmos/logging.rb', line 96 def self.contents sio.try(:sio).try(:to_s) end |
.init_logger ⇒ Object
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 |
# File 'lib/simplygenius/atmos/logging.rb', line 55 def self.init_logger return if @initialized @initialized = true ::Logging.format_as :inspect ::Logging.backtrace true ::Logging.color_scheme( 'bright', lines: { debug: :green, info: :default, warn: :yellow, error: :red, fatal: [:white, :on_red] }, date: :blue, logger: :cyan, message: :magenta ) ::Logging.logger.root.level = :info GemLogger.configure do |config| config.default_logger = ::Logging.logger.root config.logger_concern = Logging::GemLoggerConcern end end |
.setup_logging(level, color, logfile) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/simplygenius/atmos/logging.rb', line 104 def self.setup_logging(level, color, logfile) init_logger ::Logging.logger.root.level = level appenders = [] detail_pattern = '[%d] %-5l %c{2} %m\n' plain_pattern = '%m\n' = { pattern: plain_pattern } if color [:color_scheme] = 'bright' end if self.testing appender = ::Logging.appenders.string_io( 'sio', layout: ::Logging.layouts.pattern() ) appenders << appender else appender = ::Logging.appenders.stdout( 'stdout', layout: ::Logging.layouts.pattern() ) appenders << appender end # Do this after setting up stdout appender so we don't duplicate output # to stdout with our capture if logfile.present? appender = ::Logging.appenders.file( logfile, truncate: true, layout: ::Logging.layouts.pattern(pattern: detail_pattern) ) appenders << appender if ! $stdout.is_a? CaptureStream $stdout = CaptureStream.new("stdout", appender, $stdout) $stderr = CaptureStream.new("stderr", appender, $stderr, :red) silence_warnings { Object.const_set(:STDOUT, $stdout) Object.const_set(:STDERR, $stderr) } end end ::Logging.logger.root.appenders = appenders end |
.sio ⇒ Object
92 93 94 |
# File 'lib/simplygenius/atmos/logging.rb', line 92 def self.sio ::Logging.logger.root.appenders.find {|a| a.name == 'sio' } end |
.testing ⇒ Object
84 85 86 |
# File 'lib/simplygenius/atmos/logging.rb', line 84 def self.testing @t end |
.testing=(t) ⇒ Object
88 89 90 |
# File 'lib/simplygenius/atmos/logging.rb', line 88 def self.testing=(t) @t = t end |