<commit_before>$daemon_logfile = nil

def init_daemon_log_file filepath
  File.delete filepath if File.exists? filepath
  $daemon_logfile = File.open(filepath, 'a')
end

# TODO: Create daemon message log in DB
def log_daemon(msg, lvl, service)
  case lvl
    when :error
      msg = "Error: #{msg}"
    when :warn
      msg = "Warning: #{msg}"
    when :info
      msg = "Info: #{msg}"
    else
  end
  unless service.nil?
    msg += "; Service '#{service.name}' (#{service.worker})"
    msg += "; Team '#{service.team.name}' (#{service.team_id})" unless service.team.nil? or service.team.id <= 0
  end
  $daemon_logfile.write("#{Time.now}: #{msg}\n")
  $daemon_logfile.flush
  true
end
def log_daemon_error(msg, service=nil)
  log_daemon msg, :error, service
end
def log_daemon_warn( msg, service=nil)
  log_daemon msg, :warn, service
end
def log_daemon_info(msg, service=nil)
  log_daemon msg, :info, service
end<commit_msg>Ignore log_daemon calls when logfile hasn't been opened<commit_after>$daemon_logfile = nil

def init_daemon_log_file filepath
  File.delete filepath if File.exists? filepath
  $daemon_logfile = File.open(filepath, 'a')
end

# TODO: Create daemon message log in DB
def log_daemon(msg, lvl, service)
  return true if $daemon_logfile.nil?
  case lvl
    when :error
      msg = "Error: #{msg}"
    when :warn
      msg = "Warning: #{msg}"
    when :info
      msg = "Info: #{msg}"
    else
  end
  unless service.nil?
    msg += "; Service '#{service.name}' (#{service.worker})"
    msg += "; Team '#{service.team.name}' (#{service.team_id})" unless service.team.nil? or service.team.id <= 0
  end
  $daemon_logfile.write("#{Time.now}: #{msg}\n")
  $daemon_logfile.flush
  true
end
def log_daemon_error(msg, service=nil)
  log_daemon msg, :error, service
end
def log_daemon_warn( msg, service=nil)
  log_daemon msg, :warn, service
end
def log_daemon_info(msg, service=nil)
  log_daemon msg, :info, service
end
{'fraction_non_alphanumeric': 0.13457556935817805, 'fraction_numerical': 0.0010351966873706005, 'mean_word_length': 4.020779220779221, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3170980', 'n_tokens_mistral': 702, 'n_tokens_neox': 696, 'n_words': 190}