class Locd::CLI::Command::RotateLogs

Manage log rotation.

Definitions

Public Class Methods

agent_class() click to toggle source

Helpers

# File lib/locd/cli/command/rotate_logs.rb, line 45
def self.agent_class
  Locd::Agent::RotateLogs
end

Public Instance Methods

add() click to toggle source
# File lib/locd/cli/command/rotate_logs/add.rb, line 26
def add
  agent = agent_class.add **option_kwds( groups: [ :write, :add ] )

  logger.info "#{ agent_class.name } `#{ agent.label }` created."
  
  agent.reload if options[:load]
  
  respond agent
end
plist() click to toggle source
# File lib/locd/cli/command/rotate_logs.rb, line 99
def plist
  if options[:json] || options[:yaml]
    respond agent.plist
  else
    respond agent.path.read
  end
end
restart() click to toggle source
# File lib/locd/cli/command/rotate_logs.rb, line 135
def restart
  agent.restart **option_kwds( :write, groups: :stop )
end
run_() click to toggle source
# File lib/locd/cli/command/rotate_logs.rb, line 88
def run_
  Locd::Newsyslog.run_all
end
start() click to toggle source
# File lib/locd/cli/command/rotate_logs.rb, line 113
def start
  agent.start **option_kwds( :write )
end
stop() click to toggle source
# File lib/locd/cli/command/rotate_logs.rb, line 124
def stop
  agent.stop **option_kwds( :unload, groups: :stop )
end

Protected Instance Methods

agent() click to toggle source
# File lib/locd/cli/command/rotate_logs.rb, line 53
def agent
  @agent ||= begin
    agent = agent_class.get
    
    if agent.nil?
      logger.error "Agent plist not found",
        expected_path: agent_class.plist_abs_path.to_s
        
      logger.info "Run `locd setup` to create it."
      
      exit 1
    end
    
    agent
  end
end
find_multi!(pattern;) click to toggle source
# File lib/locd/cli/command/rotate_logs.rb, line 73
def find_multi! pattern; [ agent ]; end
find_only!(pattern;) click to toggle source
# File lib/locd/cli/command/rotate_logs.rb, line 71
def find_only! pattern; agent; end