Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 53fcb2f
Showing
6 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pkg/* | ||
*.gem | ||
.bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source "http://rubygems.org" | ||
|
||
# Specify your gem's dependencies in class_logger.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require 'bundler' | ||
Bundler::GemHelper.install_tasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- encoding: utf-8 -*- | ||
$:.push File.expand_path("../lib", __FILE__) | ||
require "class_logger/version" | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "class_logger" | ||
s.version = ClassLogger::VERSION | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ["Rob Hurring"] | ||
s.email = ["rob@ubrio.us"] | ||
s.homepage = "" | ||
s.summary = %q{Adds custom logger(s) to any ruby module or class} | ||
s.description = %q{Allows you to create multiple loggers for any given class} | ||
|
||
s.rubyforge_project = "class_logger" | ||
|
||
s.files = `git ls-files`.split("\n") | ||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
s.require_paths = ["lib"] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module ClassLogger | ||
def self.included(base) | ||
base.extend DSL | ||
end | ||
|
||
module DSL | ||
def has_logger(options = {}) | ||
send :extend, ClassMethods | ||
default_options = { | ||
:rotate => nil, | ||
:max_size => nil, | ||
:keep => nil, | ||
:path => "%<rails_root>s/log", | ||
:in => "%<class_name>s.log", | ||
:as => :logger, | ||
:formatter => proc{ |severity, time, program_name, message| "[%s,%s]: %s\n" % [severity, time, message] }, | ||
:level => ::Logger::DEBUG | ||
} | ||
self.setup_logger(default_options.merge(options)) | ||
end | ||
end | ||
|
||
module ClassMethods | ||
def loggers | ||
@@loggers ||= {} | ||
end | ||
|
||
def setup_logger(options) | ||
file_path = File.join(options[:path], options[:in]).to_s % \ | ||
{:rails_root => (defined?(Rails) ? Rails.root : ''), :class_name => self.to_s.downcase} | ||
if (rotate = options[:rotate]) | ||
_logger = ::Logger.new(file_path, rotate) | ||
else | ||
_logger = ::Logger.new(file_path, options[:keep], options[:max_size]) | ||
end | ||
_logger.formatter = options[:formatter] | ||
_logger.level = options[:level] | ||
|
||
as = options[:as] | ||
self.loggers[as] = _logger | ||
define_method(as){ self.class.loggers[as] } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module ClassLogger | ||
VERSION = "0.0.1" | ||
end |