<commit_before>#include "engine.h"

namespace loftili {

int Engine::Initialize(int argc, char* argv[]) {
  int i = 1;
  char *p;

  std::string serial_no, logfile = LOFTILI_LOG_PATH;
  loftili::net::Url api_url;
  bool verbose = false;

  for(; i < argc; i++) {
    p = argv[i];
    // any iteration here should be the start of a flag
    if(*p++ != '-') {
      printf("%s\n", p);
      return DisplayHelp();
    }

    bool f = false;

    while(*p && f == false) {
      switch(*p++) {
        case 'h':
          return DisplayHelp();
        case 'v':
          verbose = true;
          break;
        case 'a':
          api_url = *p ? p : (argv[++i] ? argv[i] : "");
          if(api_url.Host().size() < 5) {
            printf("invalid api host argument [%s]\n", api_url.Host().c_str());
            return DisplayHelp();
          }
          f = true;
          continue;
        case 'l':
          if(*p) {
            logfile = p;
            f = true;
            continue;
          }
          if(argv[++i]) {
            logfile = argv[i];
            f = true;
            continue;
          }
          break;
        case 's':
          if(*p) {
            serial_no = p;
            f = true;
            continue;
          }
          if(argv[++i]) {
            serial_no = argv[i];
            f = true;
            continue;
          }
          break;
        default:
          printf("unrecognized option (%s)\n", --p);
          return DisplayHelp();
      }
    }
  }

  if(serial_no.size() != 40) {
    printf("\e[0;31minvalid serial number\e[0m\n\n");
    return DisplayHelp();
  }

  if(!verbose) {
    int childpid = 0;
    pid_t pid = 0;
    if((childpid = fork ()) < 0) return false;
    if(childpid > 0) exit(0);
  }

  auto lof = verbose ? spdlog::stdout_logger_mt(LOFTILI_SPDLOG_ID) 
    : spdlog::rotating_logger_mt(LOFTILI_SPDLOG_ID, logfile.c_str(), 1048576 * 5, 3);

  if(!verbose) {
    setsid();
    umask(0);

    close(fileno(stderr));
    close(fileno(stdout));
    close(STDIN_FILENO);
  }

  loftili::api::configuration.serial = serial_no;
  spdlog::set_level(spdlog::level::info);<commit_msg>[LFTCE-43] flushing log on each call - will consider log delay in future<commit_after>#include "engine.h"

namespace loftili {

int Engine::Initialize(int argc, char* argv[]) {
  int i = 1;
  char *p;

  std::string serial_no, logfile = LOFTILI_LOG_PATH;
  loftili::net::Url api_url;
  bool verbose = false;

  for(; i < argc; i++) {
    p = argv[i];
    // any iteration here should be the start of a flag
    if(*p++ != '-') {
      printf("%s\n", p);
      return DisplayHelp();
    }

    bool f = false;

    while(*p && f == false) {
      switch(*p++) {
        case 'h':
          return DisplayHelp();
        case 'v':
          verbose = true;
          break;
        case 'a':
          api_url = *p ? p : (argv[++i] ? argv[i] : "");
          if(api_url.Host().size() < 5) {
            printf("invalid api host argument [%s]\n", api_url.Host().c_str());
            return DisplayHelp();
          }
          f = true;
          continue;
        case 'l':
          if(*p) {
            logfile = p;
            f = true;
            continue;
          }
          if(argv[++i]) {
            logfile = argv[i];
            f = true;
            continue;
          }
          break;
        case 's':
          if(*p) {
            serial_no = p;
            f = true;
            continue;
          }
          if(argv[++i]) {
            serial_no = argv[i];
            f = true;
            continue;
          }
          break;
        default:
          printf("unrecognized option (%s)\n", --p);
          return DisplayHelp();
      }
    }
  }

  if(serial_no.size() != 40) {
    printf("\e[0;31minvalid serial number\e[0m\n\n");
    return DisplayHelp();
  }

  if(!verbose) {
    int childpid = 0;
    pid_t pid = 0;
    if((childpid = fork ()) < 0) return false;
    if(childpid > 0) exit(0);
  }

  auto lof = verbose ? spdlog::stdout_logger_mt(LOFTILI_SPDLOG_ID) 
    : spdlog::rotating_logger_mt(LOFTILI_SPDLOG_ID, logfile.c_str(), 1048576 * 5, 3, true);

  if(!verbose) {
    setsid();
    umask(0);

    close(fileno(stderr));
    close(fileno(stdout));
    close(STDIN_FILENO);
  }

  loftili::api::configuration.serial = serial_no;
  spdlog::set_level(spdlog::level::info);
{'fraction_non_alphanumeric': 0.15471006188402475, 'fraction_numerical': 0.011001604400641761, 'mean_word_length': 1.690505548705302, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '3774871', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1472, 'n_words': 325}