Module: Aspera::Ascp::LogLocations

Defined in:
lib/aspera/ascp/log_locations.rb

Overview

Location of the ascp log files of the local system. ascp logs in the folder of option -L (set by Connect, transferd, IBM Aspera for Desktop), else in <logging><directory> of aspera.conf, else in a default location that depends on the OS: syslog on Linux and Unix, ~/Library/Logs/Aspera on macOS, var\log of the product (or folder of ascp) on Windows.

Constant Summary collapse

SYSLOG_FILES =

Linux and Unix: ascp logs to syslog (facility local2), in one of these files depending on the syslog configuration

%w[/var/log/aspera.log /var/log/messages /var/log/syslog].freeze
SYSLOG =

Log location of ascp on Linux and Unix without -L nor <logging><directory>

'syslog'
DEFAULT_SOURCE =

Source of a location that is not specific to a product

'ascp default'
PATH_SOURCE =

Source of a location given by an ascp found in PATH, but not in the locations of known products

'ascp in PATH'
ASCP_FILE =

Names of the log files written by ascp in a folder (-L or aspera.conf): current file, rotations, compressed

/\A(?:aspera-scp-transfer|ascp4?)(?:\.\d+)?\.log(?:\.gz)?\z/

Class Method Summary collapse

Class Method Details

.ascp_log_location(ascp, root: nil, conf_file: nil) ⇒ String

Location of the log of ascp when it runs without option -L

Parameters:

  • ascp (String) —

    path of ascp

  • root (String, nil) (defaults to: nil) —

    root folder of the product, as reported by ascp (Windows)

  • conf_file (String, nil) (defaults to: nil) —

    aspera.conf used by ascp

Returns:

  • (String) —

    log folder, or syslog (Linux and Unix)



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/aspera/ascp/log_locations.rb', line 69

def ascp_log_location(ascp, root: nil, conf_file: nil)
  folder = conf_directory(conf_file)
  return folder unless folder.nil?
  case Environment.instance.os
  when Environment::OS_MACOS
    File.join(Dir.home.start_with?('/var/root') ? '' : Dir.home, 'Library', 'Logs', 'Aspera')
  when Environment::OS_WINDOWS
    var_log = File.join(root || File.dirname(File.dirname(ascp)), 'var', 'log')
    File.directory?(var_log) ? var_log : File.dirname(ascp)
  else SYSLOG
  end
end

.default_locations ⇒ Array<Array>

Returns locations not specific to an installed product: [path, source].

Returns:

  • (Array<Array>) —

    locations not specific to an installed product: [path, source]



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/aspera/ascp/log_locations.rb', line 51

def default_locations
  locations = case Environment.instance.os
  when Environment::OS_WINDOWS then []
  when Environment::OS_MACOS then [File.join(Dir.home, 'Library', 'Logs', 'Aspera'), File.join('', 'Library', 'Logs', 'Aspera')]
  else SYSLOG_FILES
  end.map { |path| [path, DEFAULT_SOURCE] }
  desktop = Products::Desktop.log_folder
  locations.push([desktop, Products::Desktop::APP_NAME]) unless desktop.nil?
  service = transferd_service_log_folder
  locations.push([service, 'transferd service']) unless service.nil?
  locations
end

.find(products, defaults: default_locations) ⇒ Array<Hash>

Returns files that contain ascp log lines: path, size, modified, source, most recent first.

Parameters:

  • products (Array<Hash>) —

    installed products, see Installation#installed_products

  • defaults (Array<Array>) (defaults to: default_locations) —

    default locations: [path, source]

Returns:

  • (Array<Hash>) —

    files that contain ascp log lines: path, size, modified, source, most recent first



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/aspera/ascp/log_locations.rb', line 36

def find(products, defaults: default_locations)
  seen = Set.new
  # Default locations first: they are shared by products (e.g. `~/Library/Logs/Aspera`)
  locations = defaults + (products + path_products(products)).flat_map { |product| product_locations(product) }
  files = locations.flat_map { |location, source| location_files(location).map { |file| [file, source] } }
  files.filter_map do |file, source|
    stat = File.stat(file)
    # Same file in several locations, or `<name>.log` hard link to `<name>.<n>.log`
    next unless seen.add?(stat.ino.zero? ? File.expand_path(file) : [stat.dev, stat.ino])
    next unless LogAnalyzer.ascp_log?(file)
    {'path' => file, 'size' => stat.size, 'modified' => stat.mtime, 'source' => source}
  end.sort_by { |row| -row['modified'].to_f }
end