Skip to content

SixArm/sixarm_ruby_pro_logger

Repository files navigation

SixArm.com → Ruby →
ProLogger custom logger with better information

Gem Version Build Status Code Climate

Introduction

ProLogger is a custom logger formatter for that prints these fields:

  • Time stamp: such as ISO 8601 format using YYYY-MM-DD and HH:MM:SS.
  • Program name: such as $PROGRAM_NAME
  • Hostname: such as Socket.gethostname.
  • Process Id: such as Process.pid.
  • Severity: such as debug, info, warn, error, and fatal.
  • Message: a string, exception, array, or any object that has a inspect method

Install

Gem

To install this gem in your shell or terminal:

gem install sixarm_ruby_pro_logger

Gemfile

To add this gem to your Gemfile:

gem 'sixarm_ruby_pro_logger'

Require

To require the gem in your code:

require 'sixarm_ruby_pro_logger'

Setup

Example setup:

Rails.logger.formatter = ProLogger.new

Example use:

logger.info("Hello")
=> "2011-12-31T12:59:59Z my_program my.example.com 1000 Hello"

Options

Intialize options:

  • time_format: A format string for the time.strftime method. Defaults to "%Y-%m-%dT%H:%M:%SZ" which is ISO 8601 format.

  • progname: The running program name. Default is $PROGRAM_NAME.

  • hostname: The server host name. Default is Socket.gethostname.

  • pid: The process id number. Default is Process.pid.

  • message_separator: Text to use to join mutiple messages. Default is " ... ".

  • backtrace_separator: Print this between exception backtrace lines. Default is " ... ".

  • line_separator: Change any message newlines to this text. Default is " ... ".

Example:

Rails.logger.formatter = ProLogger.new(
  strftime: "%Y-%m-%dT%H:%M:%SZ", 
  progname: "my_program"
  hostname: "my.example.com", 
  pid: 1000,
  line_separator: " / "
  backtrace_separator " \"
  message_separator: " | " 
)

The message can be:

  • a string: print the string, with leading whitespace stripped, and newlines replaced by line_separator.

  • an exception: print the class, message, and backtrace items separated by backtrace_separator.

  • an array of messages: print the items in the array, separated by message_separator.

  • any object: first convert it to a string using object.inspect, then print it as a string as above.

Thanks

Thanks to topfunky for the open source custom logger at: https://github.com/topfunky/hodel_3000_compliant_logger/

About

SixArm.com » Ruby » ProLogger custom logger with better information

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages