Semantic Logger is a comprehensive logging interface that enables human and machine readable logging outputs.

Semantic Logger adds contextual information to every log entry:

Example:"Queried users table in #{duration} ms, with a result code of #{result}")

Example, including semantic information:'Queried table',
  duration: duration,
  result:   result,
  table:    'users',
  action:   'query')


Colorize log files




Centralized Logging


Tags & Named Tags


High Performance

Thread Safe

Thread Aware

Trace Level

Multiple Destinations



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"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 = "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

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

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



Add named tags to every log entry within the code block.

SemanticLogger.tagged(name: "jbloggs") do
  # All log entries in this block will include the named tag: `{name: "jbloggs"}`"Hello World")
  logger.debug("More messages")

Ruby Support

For the complete list of supported Ruby versions, see the Testing file.

Next: Rails ==>