Module: TrainPlugins::Juniper::Logging

Included in:
Connection
Defined in:
lib/train-juniper/helpers/logging.rb

Overview

Provides consistent logging patterns across the plugin

Instance Method Summary collapse

Instance Method Details

#log_bastion_connection(bastion_host) ⇒ Object

Log bastion connection attempt

Parameters:

  • bastion_host (String)

    The bastion host



67
68
69
# File 'lib/train-juniper/helpers/logging.rb', line 67

def log_bastion_connection(bastion_host)
  @logger.debug("Connecting through bastion host: #{bastion_host}")
end

#log_command(cmd) ⇒ Object

Log a command execution attempt

Parameters:

  • cmd (String)

    The command being executed



9
10
11
# File 'lib/train-juniper/helpers/logging.rb', line 9

def log_command(cmd)
  @logger.debug("Executing command: #{cmd}")
end

#log_connection_attempt(target, port = nil) ⇒ Object

Log a connection attempt

Parameters:

  • target (String)

    The host/target being connected to

  • port (Integer) (defaults to: nil)

    The port number



16
17
18
19
20
21
22
# File 'lib/train-juniper/helpers/logging.rb', line 16

def log_connection_attempt(target, port = nil)
  if port
    @logger.debug("Attempting connection to #{target}:#{port}")
  else
    @logger.debug("Attempting connection to #{target}")
  end
end

#log_connection_success(target) ⇒ Object

Log successful connection

Parameters:

  • target (String)

    The host that was connected to



43
44
45
# File 'lib/train-juniper/helpers/logging.rb', line 43

def log_connection_success(target)
  @logger.info("Successfully connected to #{target}")
end

#log_error(error, context = nil) ⇒ Object

Log an error with consistent formatting

Parameters:

  • error (Exception, String)

    The error to log

  • context (String) (defaults to: nil)

    Additional context for the error



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/train-juniper/helpers/logging.rb', line 27

def log_error(error, context = nil)
  message = if error.is_a?(Exception)
              "#{error.class}: #{error.message}"
            else
              error.to_s
            end

  if context
    @logger.error("#{context}: #{message}")
  else
    @logger.error(message)
  end
end

#log_mock_modeObject

Log mock mode activation



72
73
74
# File 'lib/train-juniper/helpers/logging.rb', line 72

def log_mock_mode
  @logger.info('Running in mock mode - no real device connection')
end

#log_platform_detection(platform_name, version) ⇒ Object

Log platform detection results

Parameters:

  • platform_name (String)

    Detected platform name

  • version (String)

    Detected version



61
62
63
# File 'lib/train-juniper/helpers/logging.rb', line 61

def log_platform_detection(platform_name, version)
  @logger.info("Platform detected: #{platform_name} #{version}")
end

#log_ssh_options(options) ⇒ Object

Log SSH session details (redacting sensitive info)

Parameters:

  • options (Hash)

    SSH options hash



49
50
51
52
53
54
55
56
# File 'lib/train-juniper/helpers/logging.rb', line 49

def log_ssh_options(options)
  safe_options = options.dup
  safe_options[:password] = '[REDACTED]' if safe_options[:password]
  safe_options[:passphrase] = '[REDACTED]' if safe_options[:passphrase]
  safe_options[:keys] = safe_options[:keys]&.map { |k| File.basename(k) } if safe_options[:keys]

  @logger.debug("SSH options: #{safe_options.inspect}")
end