Class: Flydata::LogMonitor

Inherits:
Object
  • Object
show all
Defined in:
lib/flydata/log_monitor.rb

Overview

Directory structure

log_dir
  - log_path
  + .flydata
    + [log_file_name]
      + trash  <- temprary directory
        - [log_archived_files]
      + backup <- backup archive files when initialize
        - [log_archived_files]

Constant Summary collapse

FLYDATA_DIR =
'.flydata'
TRASH_DIR =
'trash'
BACKUP_DIR =
'backup'
DEFAULT_DAYS_TO_TRASH =

days

7
DEFAULT_DAYS_TO_DELETE =

days

DEFAULT_DAYS_TO_TRASH + 7

Instance Method Summary collapse

Constructor Details

#initialize(log_path, options = {}) ⇒ LogMonitor

Returns a new instance of LogMonitor.


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/flydata/log_monitor.rb', line 18

def initialize(log_path, options={})
  # check arguments
  raise "Cannot access to log path... #{log_path}" unless File.exist?(log_path)
  @log_path = log_path
  @options = options
  @days_to_trash = @options[:days_to_trash] ?
    @options[:days_to_trash] : DEFAULT_DAYS_TO_TRASH
  @days_to_delete = @options[:days_to_delete] ?
    @options[:days_to_delete] : DEFAULT_DAYS_TO_DELETE
  @setup_flag = false
  # initialize paths
  @flydata_path = File.join(File.dirname(@log_path),
                            FLYDATA_DIR,
                            File.basename(@log_path) + ".d")
  @backup_path = File.join(@flydata_path, BACKUP_DIR)
  @trash_path = File.join(@flydata_path, TRASH_DIR)
end

Instance Method Details

#rotateObject


44
45
46
47
48
49
50
# File 'lib/flydata/log_monitor.rb', line 44

def rotate
  check_setup_done
  # move files to trash
  trash_files
  # delete trashed files
  delete_files
end

#setupObject


35
36
37
38
39
40
41
42
43
# File 'lib/flydata/log_monitor.rb', line 35

def setup
  # create directories
  FileUtils.mkdir_p(@flydata_path)
  FileUtils.mkdir_p(@backup_path)
  # backup_files to avoid to delete non-uploaded files
  backup_files
  @setup_flag = true
  self
end