# File lib/nanoc/cli/commands/compile.rb, line 95
    def setup_notifications
      # Diff generation
      require 'tempfile'
      old_contents = {}
      Nanoc::NotificationCenter.on(:will_write_rep) do |rep, snapshot|
        path = rep.raw_path(:snapshot => snapshot)
        old_contents[rep] = File.file?(path) ? File.read(path) : nil
      end
      Nanoc::NotificationCenter.on(:rep_written) do |rep, path, is_created, is_modified|
        if !rep.binary? && self.site.config[:enable_output_diff]
          new_contents = File.file?(path) ? File.read(path) : nil
          if old_contents[rep] && new_contents
            generate_diff_for(rep, old_contents[rep], new_contents)
          end
        end
      end

      # File notifications
      Nanoc::NotificationCenter.on(:rep_written) do |rep, path, is_created, is_modified|
        action = (is_created ? :create : (is_modified ? :update : :identical))
        level  = (is_created ? :high   : (is_modified ? :high   : :low))
        duration = Time.now - @rep_times[rep.raw_path] if @rep_times[rep.raw_path]
        Nanoc::CLI::Logger.instance.file(level, action, path, duration)
      end

      # Debug notifications
      if self.debug?
        Nanoc::NotificationCenter.on(:compilation_started) do |rep|
          puts "*** Started compilation of #{rep.inspect}"
        end
        Nanoc::NotificationCenter.on(:compilation_ended) do |rep|
          puts "*** Ended compilation of #{rep.inspect}"
          puts
        end
        Nanoc::NotificationCenter.on(:compilation_failed) do |rep, e|
          puts "*** Suspended compilation of #{rep.inspect}: #{e.message}"
        end
        Nanoc::NotificationCenter.on(:cached_content_used) do |rep|
          puts "*** Used cached compiled content for #{rep.inspect} instead of recompiling"
        end
        Nanoc::NotificationCenter.on(:filtering_started) do |rep, filter_name|
          puts "*** Started filtering #{rep.inspect} with #{filter_name}"
        end
        Nanoc::NotificationCenter.on(:filtering_ended) do |rep, filter_name|
          puts "*** Ended filtering #{rep.inspect} with #{filter_name}"
        end
        Nanoc::NotificationCenter.on(:visit_started) do |item|
          puts "*** Started visiting #{item.inspect}"
        end
        Nanoc::NotificationCenter.on(:visit_ended) do |item|
          puts "*** Ended visiting #{item.inspect}"
        end
        Nanoc::NotificationCenter.on(:dependency_created) do |src, dst|
          puts "*** Dependency created from #{src.inspect} onto #{dst.inspect}"
        end
      end

      # Timing notifications
      Nanoc::NotificationCenter.on(:compilation_started) do |rep|
        if @gc_count % 20 == 0 && !ENV.has_key?('TRAVIS')
          GC.enable
          GC.start
          GC.disable
        end
        @gc_count += 1
        @rep_times[rep.raw_path] = Time.now
      end
      Nanoc::NotificationCenter.on(:compilation_ended) do |rep|
        @rep_times[rep.raw_path] = Time.now - @rep_times[rep.raw_path]
      end
      Nanoc::NotificationCenter.on(:filtering_started) do |rep, filter_name|
        @filter_times[filter_name] ||= []
        @filter_times[filter_name] << Time.now
        start_filter_progress(rep, filter_name)
      end
      Nanoc::NotificationCenter.on(:filtering_ended) do |rep, filter_name|
        @filter_times[filter_name] << Time.now - @filter_times[filter_name].pop
        stop_filter_progress(rep, filter_name)
      end
    end