lib/semantic_logger/base.rb in semantic_logger-0.6.0 vs lib/semantic_logger/base.rb in semantic_logger-0.6.1
- old
+ new
@@ -35,11 +35,11 @@
else
message << " -- " << log.payload.inspect
end
end
- str = "#{log.time.strftime("%Y-%m-%d %H:%M:%S")}.#{"%03d" % (log.time.usec/1000)} #{log.level.to_s[0..0].upcase} [#{$$}:#{log.thread_name}] #{tags}#{log.name} -- #{message}"
+ str = "#{SemanticLogger::Base.formatted_time(log.time)} #{log.level.to_s[0..0].upcase} [#{$$}:#{log.thread_name}] #{tags}#{log.name} -- #{message}"
str << " (#{'%.1f' % log.duration}ms)" if log.duration
str
end
end
@@ -238,15 +238,28 @@
# Internal index of the log level
Log = Struct.new(:level, :thread_name, :name, :message, :payload, :time, :duration, :tags, :level_index)
# For JRuby include the Thread name rather than its id
if defined? Java
+ # Name of the current Thread
def self.thread_name
Java::java.lang::Thread.current_thread.name
end
+
+ # Return the Time as a formatted string
+ # JRuby only supports time in ms
+ def self.formatted_time(time)
+ "#{time.strftime("%Y-%m-%d %H:%M:%S")}.#{"%03d" % (time.usec/1000)}"
+ end
else
def self.thread_name
Thread.current.object_id
+ end
+
+ # Return the Time as a formatted string
+ # Ruby MRI supports micro seconds
+ def self.formatted_time(time)
+ "#{time.strftime("%Y-%m-%d %H:%M:%S")}.#{"%06d" % (time.usec)}"
end
end
# Internal method to return the log level as an internal index
# Also supports mapping the ::Logger levels to SemanticLogger levels