Class Index [+]

Quicksearch

DataMapper::Logger

Constants

Levels

Notes

Ruby (standard) logger levels:

:fatal

An unhandleable error that results in a program crash

:error

A handleable error condition

:warn

A warning

:info

generic (useful) information about system operation

:debug

low-level information for developers

Attributes

level[RW]
delimiter[RW]
auto_flush[RW]
buffer[R]
log[R]
init_args[R]

Public Class Methods

new(*args) click to toggle source

To initialize the logger you create a new object, proxies to set_log.

Parameters

*args

Arguments to create the log from. See set_logs for specifics.

    # File lib/dm-core/support/logger.rb, line 92
92:     def initialize(*args)
93:       @init_args = args
94:       set_log(*args)
95:       self.auto_flush = true
96:       DataMapper.logger = self
97:     end

Public Instance Methods

<<(string = nil) click to toggle source

Appends a message to the log. The methods yield to an optional block and the output of this block will be appended to the message.

Parameters

string

The message to be logged. Defaults to nil.

Returns

String

The resulting message added to the log file.

     # File lib/dm-core/support/logger.rb, line 145
145:     def <<(string = nil)
146:       message = ""
147:       message << delimiter
148:       message << string if string
149:       message << "\n" unless message[1] == \n\
150:       @buffer << message
151:       flush if @auto_flush
152: 
153:       message
154:     end
Also aliased as: push
close() click to toggle source

Close and remove the current log object.

     # File lib/dm-core/support/logger.rb, line 131
131:     def close
132:       flush
133:       @log.close if @log.respond_to?(:close) && !@log.tty?
134:       @log = nil
135:     end
flush() click to toggle source

Flush the entire buffer to the log object.

     # File lib/dm-core/support/logger.rb, line 125
125:     def flush
126:       return unless @buffer.size > 0
127:       @log.write(@buffer.slice!(0..1).join)
128:     end
push(string = nil) click to toggle source
Alias for: <<
set_log(log, log_level = nil, delimiter = " ~ ", auto_flush = false) click to toggle source

Replaces an existing logger with a new one.

Parameters

log

Either an IO object or a name of a logfile.

log_level<~to_sym>

The log level from, e.g. :fatal or :info. Defaults to :error in the production environment and :debug otherwise.

delimiter

Delimiter to use between message sections. Defaults to “ ~ “.

auto_flush

Whether the log should automatically flush after new messages are added. Defaults to false.

     # File lib/dm-core/support/logger.rb, line 111
111:     def set_log(log, log_level = nil, delimiter = " ~ ", auto_flush = false)
112:       if log_level && Levels[log_level.to_sym]
113:         @level = Levels[log_level.to_sym]
114:       else
115:         @level = Levels[:debug]
116:       end
117:       @buffer     = []
118:       @delimiter  = delimiter
119:       @auto_flush = auto_flush
120: 
121:       initialize_log(log)
122:     end

Private Instance Methods

initialize_log(log) click to toggle source

Readies a log for writing.

Parameters

log

Either an IO object or a name of a logfile.

    # File lib/dm-core/support/logger.rb, line 70
70:     def initialize_log(log)
71:       close if @log # be sure that we don't leave open files laying around.
72: 
73:       if log.respond_to?(:write)
74:         @log = log
75:       elsif File.exist?(log)
76:         @log = open(log, (File::WRONLY | File::APPEND))
77:         @log.sync = true
78:       else
79:         FileUtils.mkdir_p(File.dirname(log)) unless File.directory?(File.dirname(log))
80:         @log = open(log, (File::WRONLY | File::APPEND | File::CREAT))
81:         @log.sync = true
82:         @log.write("#{Time.now.httpdate} #{delimiter} info #{delimiter} Logfile created\n")
83:       end
84:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.