Class: EasyCaddy::Commands::Logs
- Inherits:
-
Object
- Object
- EasyCaddy::Commands::Logs
- Defined in:
- lib/easy_caddy/commands/logs.rb
Overview
Tails Caddy access/error log files for a registered site.
Instance Method Summary collapse
-
#call ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity.
-
#initialize(site:, lines:, follow:) ⇒ Logs
constructor
A new instance of Logs.
Constructor Details
#initialize(site:, lines:, follow:) ⇒ Logs
Returns a new instance of Logs.
11 12 13 14 15 |
# File 'lib/easy_caddy/commands/logs.rb', line 11 def initialize(site:, lines:, follow:) @site = site @lines = lines @follow = follow end |
Instance Method Details
#call ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/easy_caddy/commands/logs.rb', line 18 def call registry = Registry.load entry = registry.find(@site) abort " [ecaddy] No site '#{@site}' in registry. Run `ecaddy list` to see registered sites." unless entry fragment = resolve_fragment(entry) abort " [ecaddy] Fragment not found for '#{@site}' in sites/ or disabled/." unless fragment paths = Parser.parse(File.read(fragment)).log_paths if paths.empty? puts " [ecaddy] No 'output file' log directives found in #{fragment}." puts ' Add a log block to your Caddyfile, e.g.:' puts ' log { output file log/caddy.log }' return end paths.each do |p| next if File.exist?(p) puts " [ecaddy] Note: #{p} not yet created (Caddy writes it on first request)." end existing = paths.select { |p| File.exist?(p) } if existing.empty? puts ' [ecaddy] No log files exist yet. Make a request to the site first.' return end tail_args = @follow ? ['-F'] : ['-n', @lines.to_s] exec('tail', *tail_args, *existing) end |