Giter Club home page Giter Club logo

chrono_logger's Introduction

ChronoLogger

Gem Version Build Status Code Climate Coverage Status Inline docs endorse

A lock-free logger with timebased file rotation.

Ruby's stdlib Logger wraps IO#write in mutexes. ChronoLogger removes these mutexes.

ChronoLogger provides time based file rotation such as:

logger = ChronoLogger.new('/log/production.log.%Y%m%d')
Time.now.strftime('%F')
# => "2015-01-26"
File.exist?('/log/production.log.20150126')
# => true

# one day later
Time.now.strftime('%F')
# => "2015-01-27"
logger.write('hi next day')
File.exist?('/log/production.log.20150127')
# => true

Motivation

Current my projects uses ::Logger with cronolog. So

  • Reduce dependency such as cronolog
  • Remove mutexes in ruby world because os already does when some environments (ex: ext4 file system)
  • Support time based rotation without renaming file because file renaming sometime makes problem

Installation

Add this line to your application's Gemfile:

gem 'chrono_logger'

And then execute:

$ bundle

Or install it yourself as:

$ gem install chrono_logger

Usage

Same interfaces ruby's stdlib Logger except for new method.

require 'chrono_logger'

# specify path with `Time#strftime` format
logger = ChronoLogger.new('development.%Y%m%d')

logger.error("Enjoy")
logger.warn("logging!")
logger.info("Enjoy")
logger.debug("programming!")

With Rails:

# in config/environments/{development,production}.rb

config.logger = ChronoLogger.new("#{config.paths['log'].first}.%Y%m%d")

Migrating from ::Logger with cronolog

You only change Logger.new into ChronoLogger.new:

# for instance your setup is like the following
Logger.new(IO.popen("/usr/sbin/cronolog production.%Y%m%d", "w"))

# turns into
ChronoLogger.new('production.%Y%m%d')

Limitation

  • High performance logging only daily based time formatting path for example '%Y%m%d'. You can create pull request if you need other time period.

Contributing

  1. Fork it ( https://github.com/ma2gedev/chrono_logger/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

MIT. See LICENSE.txt for more details.

Resources

Bitdeli Badge

chrono_logger's People

Contributors

bitdeli-chef avatar ma2gedev avatar sonots avatar y-takahashi avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.