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
99 100 101 |
# File 'lib/simplygenius/atmos/logging.rb', line 99 def self.clear sio.try(:clear) end |
.contents ⇒ Object
95 96 97 |
# File 'lib/simplygenius/atmos/logging.rb', line 95 def self.contents sio.try(:sio).try(:to_s) end |
.init_logger ⇒ Object
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 |
# File 'lib/simplygenius/atmos/logging.rb', line 54 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
103 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 |
# File 'lib/simplygenius/atmos/logging.rb', line 103 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
91 92 93 |
# File 'lib/simplygenius/atmos/logging.rb', line 91 def self.sio ::Logging.logger.root.appenders.find {|a| a.name == 'sio' } end |
.testing ⇒ Object
83 84 85 |
# File 'lib/simplygenius/atmos/logging.rb', line 83 def self.testing @t end |
.testing=(t) ⇒ Object
87 88 89 |
# File 'lib/simplygenius/atmos/logging.rb', line 87 def self.testing=(t) @t = t end |