Class: Lumberjack::Device::LogFile

Inherits:
Writer show all
Defined in:
lib/lumberjack/device/log_file.rb

Overview

This is a logging device that appends log entries to a file.

Direct Known Subclasses

RollingLogFile

Constant Summary collapse

EXTERNAL_ENCODING =
"ascii-8bit"

Constants inherited from Writer

Writer::DEFAULT_ADDITIONAL_LINES_TEMPLATE, Writer::DEFAULT_FIRST_LINE_TEMPLATE

Instance Attribute Summary collapse

Attributes inherited from Writer

#buffer_size

Instance Method Summary collapse

Methods inherited from Writer

#close, #datetime_format, #datetime_format=, #flush, #write

Methods inherited from Lumberjack::Device

#cleanup_files!, #close, #datetime_format, #datetime_format=, #do_once, #flush, #write

Constructor Details

#initialize(path, options = {}) ⇒ LogFile

Create a logger to the file at path. Options are passed through to the Writer constructor.

Parameters:

  • path (String, Pathname)

    The path to the log file.

  • options (Hash) (defaults to: {})

    The options for the device.



18
19
20
21
22
# File 'lib/lumberjack/device/log_file.rb', line 18

def initialize(path, options = {})
  @path = File.expand_path(path)
  FileUtils.mkdir_p(File.dirname(@path))
  super(file_stream, options)
end

Instance Attribute Details

#pathObject (readonly)

The absolute path of the file being logged to.



12
13
14
# File 'lib/lumberjack/device/log_file.rb', line 12

def path
  @path
end

Instance Method Details

#reopen(logdev = nil) ⇒ void

This method returns an undefined value.

Reopen the log file.

Parameters:

  • logdev (Object) (defaults to: nil)

    not used



28
29
30
31
# File 'lib/lumberjack/device/log_file.rb', line 28

def reopen(logdev = nil)
  close
  @stream = file_stream
end