Class: Nanoc::CLI::CompileListeners::DebugPrinter Private

Inherits:
Abstract
  • Object
show all
Defined in:
lib/nanoc/cli/compile_listeners/debug_printer.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

COLOR_MAP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

{
  'compilation' => :red,
  'content' => :green,
  'filtering' => :yellow,
  'dependency_tracking' => :blue,
  'stage' => :cyan,
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#initialize, #on, #run_while, #start_safely, #stop, #stop_safely, #wrapped_start, #wrapped_stop

Constructor Details

This class inherits a constructor from Nanoc::CLI::CompileListeners::Abstract

Class Method Details

.enable_for?(command_runner, _config) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

See Also:

  • Listener#enable_for?


6
7
8
# File 'lib/nanoc/cli/compile_listeners/debug_printer.rb', line 6

def self.enable_for?(command_runner, _config)
  command_runner.debug?
end

Instance Method Details

#colorizerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
# File 'lib/nanoc/cli/compile_listeners/debug_printer.rb', line 79

def colorizer
  @_colorizer ||= Nanoc::CLI::ANSIStringColorizer.new($stdout)
end

#log(progname, msg) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
# File 'lib/nanoc/cli/compile_listeners/debug_printer.rb', line 66

def log(progname, msg)
  logger.info(progname) { msg }
end

#loggerObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



70
71
72
73
74
75
76
77
# File 'lib/nanoc/cli/compile_listeners/debug_printer.rb', line 70

def logger
  @_logger ||=
    Logger.new($stdout).tap do |l|
      l.formatter = proc do |_severity, datetime, progname, msg|
        "*** #{datetime.strftime('%H:%M:%S.%L')} #{colorizer.c(msg, COLOR_MAP[progname])}\n"
      end
    end
end

#startObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

See Also:

  • Listener#start


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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/nanoc/cli/compile_listeners/debug_printer.rb', line 19

def start
  on(:compilation_started) do |rep|
    log('compilation', "Started compilation of #{rep}")
  end

  on(:compilation_ended) do |rep|
    log('compilation', "Ended compilation of #{rep}")
    log('compilation', '')
  end

  on(:compilation_suspended) do |rep|
    log('compilation', "Suspended compilation of #{rep}")
  end

  on(:cached_content_used) do |rep|
    log('content', "Used cached compiled content for #{rep} instead of recompiling")
  end

  on(:snapshot_created) do |rep, snapshot_name|
    log('content', "Snapshot #{snapshot_name} created for #{rep}")
  end

  on(:filtering_started) do |rep, filter_name|
    log('filtering', "Started filtering #{rep} with #{filter_name}")
  end

  on(:filtering_ended) do |rep, filter_name|
    log('filtering', "Ended filtering #{rep} with #{filter_name}")
  end

  on(:dependency_created) do |src, dst|
    log('dependency_tracking', "Dependency created from #{src.inspect} onto #{dst.inspect}")
  end

  on(:stage_started) do |stage_name|
    log('stage', "Stage started: #{stage_name}")
  end

  on(:stage_ended) do |stage_name|
    log('stage', "Stage ended: #{stage_name}")
  end

  on(:stage_aborted) do |stage_name|
    log('stage', "Stage aborted: #{stage_name}")
  end
end