Class: RailsSemanticLogger::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_semantic_logger/options.rb

Overview

Options for controlling Rails Semantic Logger behavior

  • Convert Action Controller and Active Record text messages to semantic data

    Rails -- Started -- { :ip => "127.0.0.1", :method => "GET", :path => "/dashboards/inquiry_recent_activity" }
    UserController -- Completed #index -- { :action => "index", :db_runtime => 54.64, :format => "HTML", :method => "GET", :mongo_runtime => 0.0, :path => "/users", :status => 200, :status_message => "OK", :view_runtime => 709.88 }
    
    config.rails_semantic_logger.semantic = true
    
  • Change Rack started message to debug so that it does not appear in production

    config.rails_semantic_logger.started = false
    
  • Change Processing message to debug so that it does not appear in production

    config.rails_semantic_logger.processing = false
    
  • Change Action View render log messages to debug so that they do not appear in production

    ActionView::Base --   Rendered data/search/_user.html.haml (46.7ms)
    
    config.rails_semantic_logger.rendered = false
    
  • Override the Amazing Print options for logging Hash data as text:

    Any valid Amazing Print option for rendering data.
    The defaults can changed be creating a `~/.aprc` file.
    See: https://github.com/amazing-print/amazing_print
    
    Note: The option :multiline is set to false if not supplied.
    Note: Has no effect if Amazing Print is not installed.
    
       config.rails_semantic_logger.ap_options = {multiline: false}
    
  • Whether to automatically add an environment specific log file appender.

    For Example: 'log/development.log'
    
    Note:
      When Semantic Logger fails to log to an appender it logs the error to an
      internal logger, which by default writes to STDERR.
      Example, change the default internal logger to log to stdout:
        SemanticLogger::Processor.logger = SemanticLogger::Appender::IO.new($stdout, level: :warn)
    
      config.rails_semantic_logger.add_file_appender = true
    
  • Silence asset logging

    config.rails_semantic_logger.quiet_assets = false
    
  • Disable automatic logging to stderr when running a Rails console.

    config.rails_semantic_logger.console_logger = false
    
  • Override the output format for the primary Rails log file.

    Valid options:
    * :default
        Plain text output with no color.
    * :color
        Plain text output with color.
    * :json
        JSON output format.
    * class
    
    * Proc
        A block that will be called to format the output.
        It is supplied with the `log` entry and should return the formatted data.
    
    Note:
    * `:default` is automatically changed to `:color` if `config.colorize_logging` is `true`.
    
    JSON Example, in `application.rb`:
       config.rails_semantic_logger.format = :json
    
    Custom Example, create `app/lib/my_formatter.rb`:
    
      # My Custom colorized formatter
      class MyFormatter < SemanticLogger::Formatters::Color
        # Return the complete log level name in uppercase
        def level
          "#{color}log.level.upcase#{color_map.clear}"
        end
      end
    
     # In application.rb:
     config.rails_semantic_logger.format = MyFormatter.new
    
     config.rails_semantic_logger.format = :default
    
  • Add a filter to the file logger [Regexp|Proc] RegExp: Only include log messages where the class name matches the supplied

    regular expression. All other messages will be ignored.
    

    Proc: Only include log messages where the supplied Proc returns true.

        The Proc must return true or false.
    
    config.rails_semantic_logger.filter = nil
    
  • named_tags: DEPRECATED Instead, supply a Hash to config.log_tags config.rails_semantic_logger.named_tags = nil

  • Change the message format of Action Controller action. A block that will be called to format the message. It is supplied with the message and payload and should return the formatted data.

    config.rails_semantic_logger.action_message_format = -> (message, payload) do
      "#{message} - #{payload[:controller]}##{payload[:action]}"
    end
    

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptions

Setup default values



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/rails_semantic_logger/options.rb', line 116

def initialize
  @semantic              = true
  @started               = false
  @processing            = false
  @rendered              = false
  @ap_options            = {multiline: false}
  @add_file_appender     = true
  @quiet_assets          = false
  @format                = :default
  @named_tags            = nil
  @filter                = nil
  @console_logger        = true
  @action_message_format = nil
end

Instance Attribute Details

#action_message_formatObject

Returns the value of attribute action_message_format.



112
113
114
# File 'lib/rails_semantic_logger/options.rb', line 112

def action_message_format
  @action_message_format
end

#add_file_appenderObject

Returns the value of attribute add_file_appender.



112
113
114
# File 'lib/rails_semantic_logger/options.rb', line 112

def add_file_appender
  @add_file_appender
end

#ap_optionsObject

Returns the value of attribute ap_options.



112
113
114
# File 'lib/rails_semantic_logger/options.rb', line 112

def ap_options
  @ap_options
end

#console_loggerObject

Returns the value of attribute console_logger.



112
113
114
# File 'lib/rails_semantic_logger/options.rb', line 112

def console_logger
  @console_logger
end

#filterObject

Returns the value of attribute filter.



112
113
114
# File 'lib/rails_semantic_logger/options.rb', line 112

def filter
  @filter
end

#formatObject

Returns the value of attribute format.



112
113
114
# File 'lib/rails_semantic_logger/options.rb', line 112

def format
  @format
end

#named_tagsObject

Returns the value of attribute named_tags.



112
113
114
# File 'lib/rails_semantic_logger/options.rb', line 112

def named_tags
  @named_tags
end

#processingObject

Returns the value of attribute processing.



112
113
114
# File 'lib/rails_semantic_logger/options.rb', line 112

def processing
  @processing
end

#quiet_assetsObject

Returns the value of attribute quiet_assets.



112
113
114
# File 'lib/rails_semantic_logger/options.rb', line 112

def quiet_assets
  @quiet_assets
end

#renderedObject

Returns the value of attribute rendered.



112
113
114
# File 'lib/rails_semantic_logger/options.rb', line 112

def rendered
  @rendered
end

#semanticObject

Returns the value of attribute semantic.



112
113
114
# File 'lib/rails_semantic_logger/options.rb', line 112

def semantic
  @semantic
end

#startedObject

Returns the value of attribute started.



112
113
114
# File 'lib/rails_semantic_logger/options.rb', line 112

def started
  @started
end