<commit_before>local Object = require('core').Object
local String = require('string')
local Fs     = require('fs')
local Path   = require('path')
local Levels = require('./utils').Levels
local Utils  = require('./utils')

local function _noop(err)
  if err then
    error('Logger error: ' .. err.message)
  end
end

local FileLogger = Object:extend()

function FileLogger:initialize(options)

  self.type = options.type

  self.level = nil
  if type(options.level) == 'string' and Levels[String.lower(options.level)] then
    self.level = Levels[String.lower(options.level)]
  end

  self.dateformat = nil
  if options.dateformat and type(options.dateformat) == 'string' then
    self.dateformat = options.dateformat
  end

  if type(options.path) ~= 'string' then
    error('path: ' .. Utils.dump(options.path) .. ' is not a string')
  end
  self.path = options.path

  local dirname = Path.dirname(self.path)
  if not Fs.existsSync(dirname) then
    Fs.mkdir(dirname, '0740')
  end
  self.fd = Fs.openSync(self.path, 'a+', '0640')

end

function FileLogger:log(parent_level, level, s, ...)

  local final_level = self.level or parent_level

  if level.value <= final_level.value then
    Fs.write(self.fd, 0, Utils.finalString(self.dateformat, level, s, ...) .. '\n', _noop)
  end
end

function FileLogger:close()
  Fs.closeSync(self.fd)
end

return FileLogger
<commit_msg>add travis<commit_after>local Object = require('core').Object
local String = require('string')
local Fs     = require('fs')
local Path   = require('path')
local Levels = require('./utils').Levels
local Utils  = require('./utils')

local function _noop(err)
  if err then
    error('Logger error: ' .. err.message)
  end
end

local FileLogger = Object:extend()

function FileLogger:initialize(options)

  self.type = options.type

  self.level = nil
  if type(options.level) == 'string' and Levels[String.lower(options.level)] then
    self.level = Levels[String.lower(options.level)]
  end

  self.dateformat = nil
  if options.dateformat and type(options.dateformat) == 'string' then
    self.dateformat = options.dateformat
  end

  if type(options.path) ~= 'string' then
    error('path: ' .. Utils.dump(options.path) .. ' is not a string')
  end
  

  local is_absolute = options.path:sub(1, 1) == Path.sep
  if not is_absolute then
    self.path = Path.resolve(__dirname, options.path)
  else
    self.path = options.path
  end

  local dirname = Path.dirname(self.path)
  if not Fs.existsSync(dirname) then
    Fs.mkdir(dirname, '0740')
  end
  self.fd = Fs.openSync(self.path, 'a+', '0640')

end

function FileLogger:log(parent_level, level, s, ...)

  local final_level = self.level or parent_level

  if level.value <= final_level.value then
    Fs.write(self.fd, 0, Utils.finalString(self.dateformat, level, s, ...) .. '\n', _noop)
  end
end

function FileLogger:close()
  Fs.closeSync(self.fd)
end

return FileLogger

{'fraction_non_alphanumeric': 0.13709955218739237, 'fraction_numerical': 0.006889424733034792, 'mean_word_length': 3.7450980392156863, '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': '7076137', 'n_tokens_mistral': 1000, 'n_tokens_neox': 951, 'n_words': 243}