<commit_before>require 'rubygems'
require 'yaml'
require 'erb'
require 'pathname'
require 'logger'

module Daemonizer
  
  def self.root=(value)
    @@root = value
  end

  def self.root
    if defined?(@@root)
      @@root
    else
      File.dirname(daemonfile)
    end
  end
  
  def self.daemonfile=(daemonfile_name)
    @@daemonfile = File.expand_path(daemonfile_name)
    @@daemonfile
  end
  
  def self.daemonfile
    if defined?(@@daemonfile)
      @@daemonfile
    else
      "Demfile"
    end
  end
  
  def self.logger_context=(str)
    @@logger_context = str
  end
  
  def self.logger_context
    @@logger_context
  end
  
  def self.init_logger(name, log_file)
    @@logger_file = File.open(log_file, File::WRONLY | File::APPEND)
    @@logger = Logger.new(@@logger_file)
    set_logger_common_options
  end
  
  def self.set_logger_common_options
    @@logger.sev_threshold = Logger::INFO
    @@logger.formatter = Proc.new do |severity, datetime, progname, msg|
      "%s %s -- %s -- %s\n" % [ datetime.strftime("%Y-%m-%d %H:%M:%S"), severity, Daemonizer.logger_context, msg ]
    end
  end
  
  def self.reopen_log_file
    true #do not need it in append-only mode
  end
  
  def self.flush_logger<commit_msg>Making logfile sync by default<commit_after>require 'rubygems'
require 'yaml'
require 'erb'
require 'pathname'
require 'logger'

module Daemonizer
  
  def self.root=(value)
    @@root = value
  end

  def self.root
    if defined?(@@root)
      @@root
    else
      File.dirname(daemonfile)
    end
  end
  
  def self.daemonfile=(daemonfile_name)
    @@daemonfile = File.expand_path(daemonfile_name)
    @@daemonfile
  end
  
  def self.daemonfile
    if defined?(@@daemonfile)
      @@daemonfile
    else
      "Demfile"
    end
  end
  
  def self.logger_context=(str)
    @@logger_context = str
  end
  
  def self.logger_context
    @@logger_context
  end
  
  def self.init_logger(name, log_file)
    @@logger_file = File.open(log_file, File::WRONLY | File::APPEND)
    @@logger_file.sync = true
    @@logger = Logger.new(@@logger_file)
    set_logger_common_options
  end
  
  def self.set_logger_common_options
    @@logger.sev_threshold = Logger::INFO
    @@logger.formatter = Proc.new do |severity, datetime, progname, msg|
      "%s %s -- %s -- %s\n" % [ datetime.strftime("%Y-%m-%d %H:%M:%S"), severity, Daemonizer.logger_context, msg ]
    end
  end
  
  def self.reopen_log_file
    true #do not need it in append-only mode
  end
  
  def self.flush_logger
{'fraction_non_alphanumeric': 0.1145374449339207, 'fraction_numerical': 0.0, 'mean_word_length': 3.0225442834138487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3662499', 'n_tokens_mistral': 930, 'n_tokens_neox': 891, 'n_words': 197}