Permalink
Browse files

Support Logem::Logger

  • Loading branch information...
1 parent c70855b commit 4c014b13096bde1f303b4a277fb376f53736911e @gcao committed Oct 9, 2012
Showing with 24 additions and 6 deletions.
  1. +12 −0 README.rdoc
  2. +12 −6 lib/aspector/logging.rb
View
@@ -51,6 +51,18 @@ gem install aspector
# do_that
# test
+== Notes
+ To use a different logger, e.g. Logem::Logger, run below command
+
+ ASPECTOR_LOGGER=Logem::Logger LOGEM_LOG_LEVEL=trace ruby -rlogem examples/cache_aspect.rb
+
+ Explanation:
+ ASPECTOR_LOGGER=Logem::Logger => set logger to Logem::Logger class
+ LOGEM_LOG_LEVEL=trace => set logem log level to trace
+ -rlogem => require logem otherwise it might not be available
+ when the logger is initialized. This could be handled by
+ bundler etc though.
+
== Contributing to aspector
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
View
@@ -1,5 +1,5 @@
module Aspector
- class Logging
+ module Logging
# Log levels
ERROR = 50
WARN = 40
@@ -12,11 +12,7 @@ class Logging
def self.get_logger context
if logger_class_name = ENV["ASPECTOR_LOGGER"]
begin
- unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)+)\z/ =~ logger_class_name
- raise NameError, "#{logger_class_name} is not a valid constant name!"
- end
-
- logger_class = Object.module_eval("::#{$1}", __FILE__, __LINE__)
+ logger_class = constanize(logger_class_name)
logger_class.new(context)
rescue => e
$stderr.puts e.message
@@ -27,5 +23,15 @@ def self.get_logger context
Logger.new(context)
end
end
+
+ private
+
+ def self.constanize class_name
+ unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)+)\z/ =~ class_name
+ raise NameError, "#{class_name} is not a valid constant name!"
+ end
+
+ Object.module_eval("::#{$1}", __FILE__, __LINE__)
+ end
end
end

0 comments on commit 4c014b1

Please sign in to comment.