Skip to content

blink22/tagged_objects_logger

Gem Version Build Status Code Climate

TaggedObjectsLogger

TaggedObjectsLogger is a flexible logging solution for Rails based on the Ruby logger. It extends the functionality of the logger by adding the ability to log errors, warnings, info, bugs and unknown messages in a custom format efficiently and easily.

Installation

Add this line to your application's Gemfile:

gem 'tagged_objects_logger'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tagged_objects_logger

And then add this line to your environment configuration file:

config.logger = TaggedLogger.instance

Usage

After configuring environment logger variable with TaggedLogger instance you can use This gem to log errors, info, bugs, warning, unknown messages and fatal errors. This gem tags object by its class name and ID in the log file. Log file created in log/[Rails environment].log. Log path could be customized by passing log path while intializing TaggedLogger instance ex: TaggedLogger.instance(Log_file_path)

Methods

  • TaggedLogger .unknown(message, objects_list)

    An unknown message that should always be logged.
  • TaggedLogger .fatal(message, objects_list)

    An unhandleable error that results in a program crash.
  • TaggedLogger .error(message, objects_list)

    A handleable error condition.
  • TaggedLogger .warn(message, objects_list)

    A warning.
  • TaggedLogger .info(message, objects_list)

    Generic (useful) information about system operation.
  • TaggedLogger .debug(message, objects_list)

    Low-level information for developers.

message: should be of type String objects_list: every object should have ID as an attribute

An Example of Log file content generated by each of these functions:

# Logfile created on 2018-07-18 14:59:55 +0200 by logger.rb/61378
A, [2018-07-18T14:59:55.708679 #20025]   ANY -- : [TestObject_25]: [TestObject_26]: [TestObject_27]: This is unknown message

F, [2018-07-18T14:59:55.706860 #20025] FATAL -- : [TestObject_22]: [TestObject_23]: [TestObject_24]: This is a Fatal error

E, [2018-07-18T14:59:55.700376 #20025] ERROR -- : [TestObject_16]: [TestObject_17]: [TestObject_18]: This is My Error Message

W, [2018-07-18T14:59:55.710540 #20025]  WARN -- : [TestObject_28]: [TestObject_29]: [TestObject_30]: This is just a warning

I, [2018-07-18T14:59:55.698298 #20025]  INFO -- : [TestObject_13]: [TestObject_14]: [TestObject_15]: This is My Info Message

D, [2018-07-18T14:59:55.704728 #20025] DEBUG -- : [TestObject_19]: [TestObject_20]: [TestObject_21]: This is My Debug Message

Log message format

Assume this message:

F, [2018-07-18T14:59:55.706860 #20025] FATAL -- : [TestObject_22]: [TestObject_23]: [TestObject_24]: This is a Fatal error

F: A character refer to the type of message, here it refers to Fatal error message
2018-07-18T14:59:55.706860 #20025: Date and time of the generated message
FATAL: Type of message
[TestObject_22]: [TestObject_23]: [TestObject_24]: the tagged objects, every object written in this form [ClassName_ObjectID]
This is a Fatal error: Text message. Message may include multiple lines

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/blink22/tagged_objects_logger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the TaggedObjectsLogger project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

No description, website, or topics provided.

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
LICENSE.txt

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published