<commit_before>import moment from 'moment';
import { red, dim } from 'colors/safe';

import Base from '../base';
import fs from '../fs';

import write from './utils/write';
import tryCatch from '../../utils/try-catch';

import bound from '../../decorators/bound';
import memoize from '../../decorators/memoize';

class Logger extends Base {
  @memoize
  get file() {
    return `${this.root}/log/${this.environment}.log`;
  }

  get timestamp() {
    return moment().format('M/d/YY h:m:ss A');
  }

  @bound
  log(message) {
    const { file, timestamp } = this;

    message = `${dim(`[${timestamp}]`)} ${message}\n`;

    process.stdout.write(message);
    setImmediate(write, file, message);
  }

  @bound
  error(message) {
    const { file, timestamp } = this;

    message = `${red(`[${timestamp}]`)} ${message}\n`;

    process.stderr.write(message);
    setImmediate(write, file, message);
  }

  static async create(props) {
    const instance = super.create(props);
    const { root, environment } = instance;
    let logFileExists = false;

    await tryCatch(async () => {
      await fs.mkdirAsync(`${root}/log`);
    }, () => {
      // Do nothing...
    });

    await tryCatch(async () => {
      await fs.accessAsync(`${root}/log/${environment}.log`);
      logFileExists = true;
    }, () => {
      // Do nothing...
    });

    if (!logFileExists) {
      await tryCatch(async () => {
        await fs.writeFileAsync(
          `${root}/log/${environment}.log`,
          '',
          'utf8'
        );
      }, () => {
        // Do nothing...
      });
    }

    return instance;
  }
}

export line from './utils/line';

export default Logger;
<commit_msg>fix: logger date incorrect (#35)<commit_after>import moment from 'moment';
import { red, dim } from 'colors/safe';

import Base from '../base';
import fs from '../fs';

import write from './utils/write';
import tryCatch from '../../utils/try-catch';

import bound from '../../decorators/bound';
import memoize from '../../decorators/memoize';

class Logger extends Base {
  @memoize
  get file() {
    return `${this.root}/log/${this.environment}.log`;
  }

  get timestamp() {
    return moment().format('M/D/YY h:m:ss A');
  }

  @bound
  log(message) {
    const { file, timestamp } = this;

    message = `${dim(`[${timestamp}]`)} ${message}\n`;

    process.stdout.write(message);
    setImmediate(write, file, message);
  }

  @bound
  error(message) {
    const { file, timestamp } = this;

    message = `${red(`[${timestamp}]`)} ${message}\n`;

    process.stderr.write(message);
    setImmediate(write, file, message);
  }

  static async create(props) {
    const instance = super.create(props);
    const { root, environment } = instance;
    let logFileExists = false;

    await tryCatch(async () => {
      await fs.mkdirAsync(`${root}/log`);
    }, () => {
      // Do nothing...
    });

    await tryCatch(async () => {
      await fs.accessAsync(`${root}/log/${environment}.log`);
      logFileExists = true;
    }, () => {
      // Do nothing...
    });

    if (!logFileExists) {
      await tryCatch(async () => {
        await fs.writeFileAsync(
          `${root}/log/${environment}.log`,
          '',
          'utf8'
        );
      }, () => {
        // Do nothing...
      });
    }

    return instance;
  }
}

export line from './utils/line';

export default Logger;

{'fraction_non_alphanumeric': 0.1899970405445398, 'fraction_numerical': 0.0011837821840781297, 'mean_word_length': 2.4454638124362895, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '2107525', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1074, 'n_words': 244}