• Stars
    star
    523
  • Rank 81,443 (Top 2 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 16 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A flexible logging library for use in Ruby programs based on the design of Java's log4j library.

.github/workflows/ruby.yml

Logging

by Tim Pease

Description

Logging is a flexible logging library for use in Ruby programs based on the design of Java's log4j library. It features a hierarchical logging system, custom level names, multiple output destinations per log event, custom formatting, and more.

Installation

gem install logging

Examples

This example configures a logger to output messages in a format similar to the core ruby Logger class. Only log messages that are warnings or higher will be logged.

require 'logging'

logger = Logging.logger(STDOUT)
logger.level = :warn

logger.debug "this debug message will not be output by the logger"
logger.warn "this is your last warning"

In this example, a single logger is created that will append to STDOUT and to a file. Only log messages that are informational or higher will be logged.

require 'logging'

logger = Logging.logger['example_logger']
logger.level = :info

logger.add_appenders \
    Logging.appenders.stdout,
    Logging.appenders.file('example.log')

logger.debug "this debug message will not be output by the logger"
logger.info "just some friendly advice"

The Logging library was created to allow each class in a program to have its own configurable logger. The logging level for a particular class can be changed independently of all other loggers in the system. This example shows the recommended way of accomplishing this.

require 'logging'

Logging.logger['FirstClass'].level = :warn
Logging.logger['SecondClass'].level = :debug

class FirstClass
  def initialize
    @logger = Logging.logger[self]
  end

  def some_method
    @logger.debug "some method was called on #{self.inspect}"
  end
end

class SecondClass
  def initialize
    @logger = Logging.logger[self]
  end

  def another_method
    @logger.debug "another method was called on #{self.inspect}"
  end
end

There are many more examples in the examples folder of the logging package. The recommended reading order is the following:

Extending

The Logging framework is extensible via the little-plugger gem-based plugin system. New appenders, layouts, or filters can be released as ruby gems. When installed locally, the Logging framework will automatically detect these gems as plugins and make them available for use.

The logging-email plugin is a good example to follow. It includes a lib/logging/plugins/email.rb file which is detected by the plugin framework. This file declares a Logging::Plugins::Email.initialize_email method that is called when the plugin is loaded.

The three steps for creating a plugin are:

  • create a new Ruby gem: logging-<name>
  • include a plugin file: lib/logging/plugins/<name>.rb
  • define a plugin initializer: Logging::Plugins::<Name>.initialize_<name>

Development

The Logging source code relies on the Mr Bones project for default rake tasks. You will need to install the Mr Bones gem if you want to build or test the logging gem. Conveniently there is a bootstrap script that you can run to setup your development environment.

script/bootstrap

This will install the Mr Bones gem and the required Ruby gems for development. After this is done you can rake rake -T to see the available rake tasks.

License

The MIT License - see the LICENSE file for the full text.

More Repositories

1

webby

NO LONGER UNDER DEVELOPMENT
Ruby
266
star
2

servolux

Threads : Servers : Forks : Daemons
Ruby
198
star
3

bones

Mr Bones is a handy tool that creates new projects from a code skeleton
Ruby
121
star
4

inifile

Native Ruby package for reading and writing INI files
Ruby
95
star
5

logging-rails

Railtie for integrating the Logging framework with Rails
Ruby
81
star
6

directory_watcher

Event notification for file system changes
Ruby
73
star
7

little-plugger

A gems based plugin framework for Ruby
Ruby
31
star
8

loquacious

tell everyone how to configure your project
Ruby
19
star
9

dotfiles

my dotfiles
Vim Script
18
star
10

jquery-ui.flipbook

jQuery UI FlipBook image viewer
JavaScript
11
star
11

pixel_pi

A library for controlling NeoPixels via Ruby on the RaspberryPi
C
8
star
12

polylog

Logging Framework Abstraction Layer
Ruby
8
star
13

bitwise

Packed binary data manipulation library for Ruby
Ruby
7
star
14

spawner

Manage a collection of child processes in a cross platform fashion
Ruby
7
star
15

mmap

Guy Decuox's mmap library for ruby
C
6
star
16

miscellanea

fun, exciting, and useful chunks of text and software
Tcl
6
star
17

logging-email

An email appender for the Ruby Logging framework
Ruby
5
star
18

expiration-date

auto expiring / auto refreshing attributes for all your ruby classes
Ruby
5
star
19

elasticon-2015

Talk for Elastic{on} 2015
4
star
20

githubbub

making rubyforge and github play together
Ruby
4
star
21

pdf_merge

OS X utility for merging PDF documents
Ruby
4
star
22

enigma

Presentation for the Boulder Ruby Users Group
Ruby
3
star
23

bones-git

Ruby
3
star
24

heap_hop

Ruby heap parser and analyzer
Ruby
3
star
25

bones-rspec

Mr Bones plugin for RSpec
Ruby
3
star
26

bones-extras

Extra plugins for Mr Bones
Ruby
2
star
27

bones-rcov

Mr Bones plugin for rcov tasks
Ruby
2
star
28

logtastic

A web application for storing, searching, and viewing log events
JavaScript
2
star
29

pixelbot

Tasty integration of neopixels and web services
Ruby
2
star
30

bones-yard

Mr Bones plugin for the Yard documentation gem
Ruby
1
star
31

MacCraft

tools for the private MacOS Minecraft server
Ruby
1
star
32

bones-rubyforge

Mr Bones plugin for the Rubyforge gem
Ruby
1
star
33

roadie

environment based configuration
Ruby
1
star
34

bones-zentest

Mr Bones plugin for the ZenTest gem
Ruby
1
star
35

twp.github.io

Pea53 GitHub Pages
CSS
1
star