Class: ActFluentLoggerRails::FluentLogger
- Inherits:
-
ActiveSupport::Logger
- Object
- ActiveSupport::Logger
- ActFluentLoggerRails::FluentLogger
- Defined in:
- lib/act-fluent-logger-rails/logger.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #add(severity, message = nil, progname = nil, &block) ⇒ Object
- #add_message(severity, message) ⇒ Object
- #close ⇒ Object
- #flush ⇒ Object
- #format_severity(severity) ⇒ Object
-
#initialize(options, level, log_tags) ⇒ FluentLogger
constructor
A new instance of FluentLogger.
- #level ⇒ Object
- #level=(l) ⇒ Object
Constructor Details
#initialize(options, level, log_tags) ⇒ FluentLogger
Returns a new instance of FluentLogger.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/act-fluent-logger-rails/logger.rb', line 77 def initialize(, level, ) self.level = level port = [:port] host = [:host] nanosecond_precision = [:nanosecond_precision] @messages_type = ([:messages_type] || :array).to_sym @tag = [:tag] @severity_key = ([:severity_key] || :severity).to_sym @flush_immediately = [:flush_immediately] logger_opts = {host: host, port: port, nanosecond_precision: nanosecond_precision} @fluent_logger = ::Fluent::Logger::FluentLogger.new(nil, logger_opts) @severity = 0 @messages = [] @log_tags = @map = {} after_initialize if respond_to? :after_initialize end |
Instance Method Details
#[](key) ⇒ Object
126 127 128 |
# File 'lib/act-fluent-logger-rails/logger.rb', line 126 def [](key) @map[key] end |
#[]=(key, value) ⇒ Object
130 131 132 |
# File 'lib/act-fluent-logger-rails/logger.rb', line 130 def []=(key, value) @map[key] = value end |
#add(severity, message = nil, progname = nil, &block) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/act-fluent-logger-rails/logger.rb', line 95 def add(severity, = nil, progname = nil, &block) return true if severity < level = (block_given? ? block.call : progname) if .blank? return true if .blank? (severity, ) true end |
#add_message(severity, message) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/act-fluent-logger-rails/logger.rb', line 103 def (severity, ) @severity = severity if @severity < severity = case when ::String when ::Exception "#{ . } (#{ .class })\n" << (.backtrace || []).join("\n") else .inspect end if .encoding == Encoding::UTF_8 @messages << else @messages << .dup.force_encoding(Encoding::UTF_8) end flush if @flush_immediately end |
#close ⇒ Object
155 156 157 |
# File 'lib/act-fluent-logger-rails/logger.rb', line 155 def close @fluent_logger.close end |
#flush ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/act-fluent-logger-rails/logger.rb', line 134 def flush return if @messages.empty? = if @messages_type == :string @messages.join("\n") else @messages end @map[:messages] = @map[@severity_key] = format_severity(@severity) if @tags @log_tags.keys.zip(@tags).each do |k, v| @map[k] = v end end @fluent_logger.post(@tag, @map) @severity = 0 @messages.clear @tags = nil @map.clear end |
#format_severity(severity) ⇒ Object
167 168 169 |
# File 'lib/act-fluent-logger-rails/logger.rb', line 167 def format_severity(severity) ActFluentLoggerRails::Logger::SEV_LABEL[severity] || 'ANY' end |
#level ⇒ Object
159 160 161 |
# File 'lib/act-fluent-logger-rails/logger.rb', line 159 def level @level end |
#level=(l) ⇒ Object
163 164 165 |
# File 'lib/act-fluent-logger-rails/logger.rb', line 163 def level=(l) @level = l end |