Class: TabKeeper::LogRedirection

Inherits:
Object
  • Object
show all
Defined in:
lib/tab_keeper/log_redirection.rb

Instance Method Summary collapse

Constructor Details

#initialize(previous, job: nil, job_name_proc: ->(x) { x }, timing: nil, log_directory: nil, error_suffix: nil, include_date_in_log_name: false, **_options) ⇒ LogRedirection

Returns a new instance of LogRedirection.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tab_keeper/log_redirection.rb', line 3

def initialize(previous, job: nil,
                         job_name_proc: ->(x) { x },
                         timing: nil,
                         log_directory: nil,
                         error_suffix: nil,
                         include_date_in_log_name: false,
                         **_options)
  if previous.nil?
    raise ArgumentError, "#{self.class.name} must not be first in the cron pipeline!"
  end

  if log_directory.nil?
    raise ArgumentError, "log_directory must be set for #{self.class.name}"
  end

  @previous = previous
  @job = job
  # Normalise the job name: if it's an array take the first thing, then get the last
  # thing after a "::" (if it's a class name), or a "/" (if it's a script, and removes
  # the need to escape yay)
  job_name = Array(@job).first.to_s.split(/((::)|\/)/).last.split(/[^\w\d]/).first
  @job_name = job_name_proc.call(job_name)
  @timing = timing
  @log_directory = log_directory
  @error_suffix = error_suffix
  @include_date_in_log_name = include_date_in_log_name
end

Instance Method Details

#to_sObject



31
32
33
34
35
# File 'lib/tab_keeper/log_redirection.rb', line 31

def to_s
  "#{@previous} " \
    ">> #{@log_directory}/#{job_name}#{date_part}.log " \
    "2>#{error_part}"
end