Class: FluentWrap
- Inherits:
-
Object
- Object
- FluentWrap
- Defined in:
- lib/fluent.rb
Overview
Small wrapper for fluent-logger gem. Most notably this wrapper filters out
all data keys with password
string
Constant Summary
Instance Method Summary (collapse)
-
- (Object) error(msg, attrs = nil)
Shortcut for #log(:error, msg).
-
- (Object) info(msg, attrs = nil)
Shortcut for #log(:info, msg).
-
- (FluentWrap) initialize(tag, base_attrs, logger = Fluent::Logger)
constructor
A new instance of FluentWrap.
-
- (Object) log(level, msg, attrs = nil)
Log a message.
-
- (Object) merge(more_attrs = nil, new_logger = nil)
Create new child logger.
-
- (Object) warn(msg, attrs = nil)
Shortcut for #log(:warn, msg).
Constructor Details
- (FluentWrap) initialize(tag, base_attrs, logger = Fluent::Logger)
Returns a new instance of FluentWrap
13 14 15 16 17 |
# File 'lib/fluent.rb', line 13 def initialize(tag, base_attrs, logger=Fluent::Logger) @tag = tag @logger = logger @base_attrs = clean(base_attrs) end |
Instance Method Details
- (Object) error(msg, attrs = nil)
Shortcut for #log(:error, msg)
69 70 71 |
# File 'lib/fluent.rb', line 69 def error(msg, attrs=nil) log("error", msg, attrs) end |
- (Object) info(msg, attrs = nil)
Shortcut for #log(:info, msg)
57 58 59 |
# File 'lib/fluent.rb', line 57 def info(msg, attrs=nil) log("info", msg, attrs) end |
- (Object) log(level, msg, attrs = nil)
Log a message
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fluent.rb', line 24 def log(level, msg, attrs=nil) if [:msg, :meta, :level].include?(msg) raise "Illegal fluentd message key: #{ msg }" end record = { :msg => msg, # for legacy elasticsearch support :meta => clean(@base_attrs), } record[:meta][:level] = level # Write attrs under a key defined by msg to avoid type errors in # elasticsearch record[msg] = clean(attrs) if attrs @logger.post(@tag, record) if !ENV["FLUENTD_STDOUT"] return if ENV["RACK_ENV"] == "test" return if ENV["RAILS_ENV"] == "test" end begin puts "#{ msg }: #{ record.to_json }" rescue Exception => e puts "Failed to log message: #{ record.inspect }" puts e end end |
- (Object) merge(more_attrs = nil, new_logger = nil)
Create new child logger. The child will inherit base_attrs from the parent
77 78 79 80 81 82 83 |
# File 'lib/fluent.rb', line 77 def merge(more_attrs=nil, new_logger=nil) FluentWrap.new( @tag, @base_attrs.merge(more_attrs || {}), new_logger || @logger ) end |
- (Object) warn(msg, attrs = nil)
Shortcut for #log(:warn, msg)
63 64 65 |
# File 'lib/fluent.rb', line 63 def warn(msg, attrs=nil) log("warn", msg, attrs) end |