Class: Logger::LogDevice (Ruby 2.2.3)
Description: Class : Logger::LogDevice - Ruby 2.2.3

- Home
- Core 2.2.3
- Std-lib 2.2.3
- Downloads

Support for the Ruby 2.2 series has ended. See here for reference.

### Home Classes Methods

### In Files

- logger.rb

### Parent

Object

### Namespace

- CLASS Logger::LogDevice::LogDeviceMutex

### Methods

- ::new
- #close
- #write

### Included Modules

- Logger::Period

### Class/Module Index

Quicksearch

- Logger
- Logger::Formatter
- Logger::LogDevice
- Logger::LogDevice::LogDeviceMutex
- Logger::Period
- Logger::Severity

No matching classes.

# Logger::LogDevice

Device used for logging messages.

### Attributes

dev[R]
filename[R]

### Public Class Methods

new(log = nil, opt = {}) click to toggle source

                   # File logger.rb, line 578
    def initialize(log = nil, opt = {})
      @dev = @filename = @shift_age = @shift_size = nil
      @mutex = LogDeviceMutex.new
      if log.respond_to?(:write) and log.respond_to?(:close)
        @dev = log
      else
        @dev = open_logfile(log)
        @dev.sync = true
        @filename = log
        @shift_age = opt[:shift_age] || 7
        @shift_size = opt[:shift_size] || 1048576
        @next_rotate_time = next_rotate_time(Time.now, @shift_age) unless @shift_age.is_a?(Integer)
      end
    end

### Public Instance Methods

close() click to toggle source

                   # File logger.rb, line 614
    def close
      begin
        @mutex.synchronize do
          @dev.close rescue nil
        end
      rescue Exception
        @dev.close rescue nil
      end
    end

write(message) click to toggle source

                   # File logger.rb, line 593
    def write(message)
      begin
        @mutex.synchronize do
          if @shift_age and @dev.respond_to?(:stat)
            begin
              check_shift_log
            rescue
              warn("log shifting failed. #{$!}")
            end
          end
          begin
            @dev.write(message)
          rescue
            warn("log writing failed. #{$!}")
          end
        end
      rescue Exception => ignored
        warn("log writing failed. #{ignored}")
      end
    end