<commit_before>dateFormat = require './date-format'

module.exports = (options) -> new Logger options

colors =
     blue: ['\x1B[34m', '\x1B[39m']
     cyan: ['\x1B[36m', '\x1B[39m']
     green: ['\x1B[32m', '\x1B[39m']
     magenta: ['\x1B[36m', '\x1B[39m']
     red: ['\x1B[31m', '\x1B[39m']
     yellow: ['\x1B[33m', '\x1B[39m']

levelColors =
    error: colors.red
    debug: colors.green
    warn: colors.yellow
    info: colors.blue

class Logger

    constructor: (@options) ->
        @options ?= {}
        if @options.date and not @options.dateFormat?
            @options.dateFormat = 'YYYY-MM-DD hh:mm:ss:S'

    colorify: (text, color) ->
        "#{color[0]}#{text}#{color[1]}"

    format: (level, text) ->
        text = JSON.stringify text if text instanceof Object
        text = "#{@options.prefix} | #{text}" if @options.prefix?
        if process.env.NODE_ENV isnt 'production'
            level = @colorify level, levelColors[level]

        text = "#{level} - #{text}" if level
        if @options.date
            date = new Date().format @options.dateFormat
            text = "[#{date}] #{text}"
        text

    info: (text) ->
        console.info @format 'info', text if process.env.NODE_ENV isnt 'test'

    warn: (text) ->
        console.warn @format 'warn', text if process.env.NODE_ENV isnt 'test'

    error: (text) ->
        console.error @format 'error', text if process.env.NODE_ENV isnt 'test'

    debug: (text) ->
        console.info @format 'debug', text if process.env.NODE_ENV isnt 'test'

    raw: (text) ->
        console.log text

    lineBreak: (text) ->
        @raw Array(80).join("*")<commit_msg>display debug logs only when debug is activated<commit_after>dateFormat = require './date-format'

module.exports = (options) -> new Logger options

colors =
     blue: ['\x1B[34m', '\x1B[39m']
     cyan: ['\x1B[36m', '\x1B[39m']
     green: ['\x1B[32m', '\x1B[39m']
     magenta: ['\x1B[36m', '\x1B[39m']
     red: ['\x1B[31m', '\x1B[39m']
     yellow: ['\x1B[33m', '\x1B[39m']

levelColors =
    error: colors.red
    debug: colors.green
    warn: colors.yellow
    info: colors.blue

class Logger

    constructor: (@options) ->
        @options ?= {}
        if @options.date and not @options.dateFormat?
            @options.dateFormat = 'YYYY-MM-DD hh:mm:ss:S'

    colorify: (text, color) ->
        "#{color[0]}#{text}#{color[1]}"

    format: (level, text) ->
        text = JSON.stringify text if text instanceof Object
        text = "#{@options.prefix} | #{text}" if @options.prefix?
        if process.env.NODE_ENV isnt 'production'
            level = @colorify level, levelColors[level]

        text = "#{level} - #{text}" if level
        if @options.date
            date = new Date().format @options.dateFormat
            text = "[#{date}] #{text}"
        text

    info: (text) ->
        console.info @format 'info', text if process.env.NODE_ENV isnt 'test'

    warn: (text) ->
        console.warn @format 'warn', text if process.env.NODE_ENV isnt 'test'

    error: (text) ->
        console.error @format 'error', text if process.env.NODE_ENV isnt 'test'

    debug: (text) ->
        console.info @format 'debug', text if process.env.DEBUG

    raw: (text) ->
        console.log text

    lineBreak: (text) ->
        @raw Array(80).join("*")
{'fraction_non_alphanumeric': 0.1685224195004514, 'fraction_numerical': 0.024074631357207343, 'mean_word_length': 2.4057377049180326, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '4385161', 'n_tokens_mistral': 1177, 'n_tokens_neox': 1142, 'n_words': 282}