lib/semantic_logger/logger.rb in semantic_logger-0.3.3 vs lib/semantic_logger/logger.rb in semantic_logger-0.4.0
- old
+ new
@@ -10,20 +10,27 @@
# require 'logger'
# require 'semantic_logger'
# log = Logger.new(STDOUT)
# log.level = Logger::DEBUG
#
-# SemanticLogger::Manager.register_appender(SemanticLogger::Appender::Logger.new(log))
+# SemanticLogger::Logger.appenders << SemanticLogger::Appender::Logger.new(log)
#
# logger = SemanticLogger::Logger.new("my.app.class")
# logger.debug("Login time", :user => 'Joe', :duration => 100, :ip_address=>'127.0.0.1')
#
-# # Now log to the Logger above as well as Mongo at the same time
+# # Now log to the Logger above as well as MongoDB at the same time
#
-# SemanticLogger::Manager.register_appender(SemanticLogger::Appender::Mongo.new(cfg))
+# db = Mongo::Connection.new['production_logging']
+#
+# SemanticLogger::Logger.appenders << SemanticLogger::Appender::MongoDB.new(
+# :db => db,
+# :collection_size => 25.gigabytes
+# )
# ...
+# # This will be logged to both the Ruby Logger and MongoDB
# logger.debug("Login time", :user => 'Mary', :duration => 230, :ip_address=>'192.168.0.1')
+#
module SemanticLogger
class Logger
include SyncAttr
# Logging levels in order of precedence
@@ -213,16 +220,10 @@
queue.size
end
# Flush all pending log entry disk, database, etc.
# All pending log writes are completed and each appender is flushed in turn
- def flush
- self.class.flush
- end
-
- # Flush all pending log entry disk, database, etc.
- # All pending log writes are completed and each appender is flushed in turn
def self.flush
return false unless @@appender_thread.alive?
reply_queue = Queue.new
queue << { :command => :flush, :reply_queue => reply_queue }
@@ -249,9 +250,36 @@
startup
at_exit { shutdown }
Queue.new
end
+ # Struct Log
+ #
+ # level
+ # Log level of the supplied log call
+ # :trace, :debug, :info, :warn, :error, :fatal
+ #
+ # thread_name
+ # Name of the thread in which the logging call was called
+ #
+ # name
+ # Class name supplied to the logging instance
+ #
+ # message
+ # Text message to be logged
+ #
+ # payload
+ # Optional Hash or Ruby Exception object to be logged
+ #
+ # time
+ # The time at which the log entry was created
+ #
+ # duration
+ # The time taken to complete a benchmark call
+ #
+ # tags
+ # Any tags active on the thread when the log call was made
+ #
Log = Struct.new(:level, :thread_name, :name, :message, :payload, :time, :duration, :tags)
# For JRuby include the Thread name rather than its id
if defined? Java
def self.thread_name