Semantic Logger adds contextual information to every log message to assist significantly in searching and processing large amounts of log messages.

Additional information captured by Semantic Logger:

Log messages can be written to one or more of the following destinations at the same time:

Example:

logger.info("Queried users table in #{duration} ms, with a result code of #{result}")

Example, including semantic information:

logger.info('Queried table',
  duration: duration,
  result:   result,
  table:    'users',
  action:   'query')

Features

Colorize log files

Drop-in Replacement

Benchmarking

Metrics

Centralized Logging

Dynamic

Tagged Logging

Payload support

Exceptions

High Performance

Thread Safe

Thread Aware

Trace Level

Multiple Destinations

Customizable

Example:

require 'semantic_logger'

# Set the global default log level
SemanticLogger.default_level = :trace

# Log to a file, and use the colorized formatter
SemanticLogger.add_appender(file_name: 'development.log', formatter: :color)

# Create an instance of a logger
# Add the application/class name to every log message
logger = SemanticLogger['MyClass']

Informational logging

logger.info("Calling Supplier")

Error information

logger.error("Oops external call failed", :result => :failed, :reason_code => -10)

Set this thread’s name for when multiple threads are all logging at the same time

Thread.current.name = "main"

Debug information

results = [ 5, 7, 2, 10 ]
logger.debug { "A total of #{results.inject(0) {|sum, i| i+sum }} were processed" }

New level for logging low level trace information such as data sent or received

raw_response = "<xml><user>jbloggs</user><lastname>Bloggs</lastname><firstname>Joe</firstname></xml>"
logger.trace "Raw data received from Supplier:", raw_response

Measure and log how long it takes to execute a block of code

logger.measure_info "Called external interface" do
  # Code to call external service ...
  sleep 0.75
end

Add tags to every log entry within the code block. For example login, session id, source ip address, username, etc.

logger.tagged('jbloggs') do
  # All log entries in this block will include the tag 'jbloggs'
  logger.info("Hello World")
  logger.debug("More messages")
end

Output:

development.log

Next: Rails ==>