Permalink
Browse files

adding some examples

  • Loading branch information...
1 parent facd6fa commit 6facb5930646fe3dd5a4f3f7421c995f5ba01e85 Rob Hurring committed Mar 10, 2011
Showing with 43 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +42 −0 examples/examples.rb
View
@@ -1,3 +1,4 @@
pkg/*
*.gem
.bundle
+*.log
View
@@ -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.