https://github.com/sixarm/sixarm_ruby_pro_logger
SixArm.com » Ruby » ProLogger custom logger with better information
https://github.com/sixarm/sixarm_ruby_pro_logger
gem log logger ruby
Last synced: over 1 year ago
JSON representation
SixArm.com » Ruby » ProLogger custom logger with better information
- Host: GitHub
- URL: https://github.com/sixarm/sixarm_ruby_pro_logger
- Owner: SixArm
- License: other
- Created: 2011-11-28T07:54:46.000Z (over 14 years ago)
- Default Branch: main
- Last Pushed: 2023-09-15T19:28:50.000Z (almost 3 years ago)
- Last Synced: 2025-02-06T00:24:24.225Z (over 1 year ago)
- Topics: gem, log, logger, ruby
- Language: Ruby
- Homepage: http://sixarm.com
- Size: 449 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# SixArm.com → Ruby →
ProLogger custom logger with better information
[](http://badge.fury.io/rb/sixarm_ruby_pro_logger)
[](https://travis-ci.org/SixArm/sixarm_ruby_pro_logger)
[](https://codeclimate.com/github/SixArm/sixarm_ruby_pro_logger/maintainability)
* Git:
* Doc:
* Gem:
* Contact: Joel Parker Henderson,
* Project: [changes](CHANGES.md), [license](LICENSE.md), [contributing](CONTRIBUTING.md).
## 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/