lib/semantic_logger/appender/file.rb in semantic_logger-2.21.0 vs lib/semantic_logger/appender/file.rb in semantic_logger-3.0.0
- old
+ new
@@ -4,12 +4,27 @@
#
module SemanticLogger
module Appender
class File < SemanticLogger::Appender::Base
- # Create a File Logger appender instance
+ # Create a File Logger appender instance.
#
+ # Parameters
+ # filename [String|IO]
+ # Name of file to write to.
+ # Or, an IO stream to which to write the log message to.
+ #
+ # level [:trace | :debug | :info | :warn | :error | :fatal]
+ # Override the log level for this appender.
+ # Default: SemanticLogger.default_level
+ #
+ # filter [Regexp|Proc]
+ # RegExp: Only include log messages where the class name matches the supplied
+ # regular expression. All other messages will be ignored.
+ # Proc: Only include log messages where the supplied Proc returns true
+ # The Proc must return true or false.
+ #
# Example
# require 'semantic_logger'
#
# # Enable trace level logging
# SemanticLogger.default_level = :info
@@ -36,11 +51,10 @@
# # And log to a file at the same time, including all :trace level data
# SemanticLogger.add_appender('application.log')
#
# logger = SemanticLogger['test']
# logger.info 'Hello World'
- #
def initialize(filename, level=nil, filter=nil, &block)
raise 'filename cannot be null when initializing the SemanticLogging::Appender::File' unless filename
@log =
if filename.respond_to?(:write) and filename.respond_to?(:close)
filename
@@ -77,10 +91,10 @@
return false if (level_index > (log.level_index || 0)) || !include_message?(log)
# Since only one appender thread will be writing to the file at a time
# it is not necessary to protect access to the file with a semaphore
# Allow this logger to filter out log levels lower than it's own
- @log.write(@formatter.call(log) << "\n")
+ @log.write(@formatter.call(log, self) << "\n")
true
end
# Flush all pending logs to disk.
# Waits for all sent documents to be writted to disk