class Metanorma::Utils::Log

def write(file)

def write(file)
  File.open(file, "w:UTF-8") do |f|
    f.puts "#{file} errors"
    @log.keys.each do |key|
      f.puts "\n\n== #{key}\n\n"
      @log[key].sort do |a, b|
        a[:location] <=> b[:location]
      end.each do |n|
        loc = n[:location] ? "(#{n[:location]}): " : ""
        f.puts "#{loc}#{n[:message]}" 
        n[:context]&.split(/\n/)&.first(5)&.each { |l| f.puts "\t#{l}" }
      end
    end
  end
end