Skip to content

Commit

Permalink
adding some examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Hurring committed Mar 10, 2011
1 parent facd6fa commit 6facb59
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pkg/*
*.gem
.bundle
*.log
42 changes: 42 additions & 0 deletions examples/examples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require File.expand_path('../../lib/class_logger', __FILE__)
$log_path = File.dirname(__FILE__)

# test module functionality
module Hello
include ClassLogger
has_logger :in => "%{class_name}.log", :as => :my_logger

def self.alternate
loggers[:my_logger]
end
end
Hello.my_logger.info "Hai"
Hello.alternate.info "Hai der!"

# test class functionality
class Gateway
include ClassLogger
has_logger :path => $log_path, :level => Logger::ERROR
has_logger :in => "%{caller_path}/transaction.log", :as => :transaction_logger,
:formatter => proc{ |severity, time, program_name, message| "[%s-Transaction]: %s\n" % [severity, message] }

def initialize
logger.info "Wont show up"
logger.error "Will show up"
end

def transact!
transaction_logger.info "Transacted"
end
end

g = Gateway.new
g.transact!

# test default functionality
class Default
include ClassLogger
has_logger :path => "%{caller_path}"
end

Default.new.logger.info "Testing"

0 comments on commit 6facb59

Please sign in to comment.