{"size": 1239, "ext": "js", "max_stars_repo_path": "src/logger.js", "max_stars_repo_name": "fortressdev/squidex-client-manager", "max_stars_repo_stars_event_min_datetime": "2020-06-16T02:59:06.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-24T07:25:49.000Z", "max_issues_repo_path": "src/logger.js", "max_issues_repo_name": "fortressdev/squidex-client-manager", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/logger.js", "max_forks_repo_name": "fortressdev/squidex-client-manager", "max_forks_repo_forks_event_min_datetime": "2022-03-25T16:33:29.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-25T16:33:29.000Z"}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 19.359375, "max_line_length": 64, "alphanum_fraction": 0.6279257466}
const util = require('util');

const writeLine = (prefix, msg, stream) => {
  stream.write(`[squidex-client-manager][${prefix}]: ${msg}\n`);
};

/**
 * Write a debug message
 *
 * @param {the message to write} msg
 */
function Debug(msg) {
  if (process.env.PRODUCTION) {
    return;
  }
  writeLine('debug', msg, process.stdout);
}

/**
 * Write a info message to standard output
 * @param {the message to write} msg
 */
const Info = msg => writeLine('info', msg, process.stdout);

/**
 * Write a error message to standard output
 * @param {the message to write} msg
 */
const Error = (error) => {
  writeLine('error', error, process.stdout);
  if (error.stack) {
    writeLine('stack', error.stack, process.stdout);
  }
};

/**
 * Write out a message before exiting current process
 * @param {string to print out} msg
 * @param {error to be printed} err
 * @param {exitCode the code to be used for the process}
 */
const bail = (msg, err, exitCode) => {
  Info(msg);
  Error(err);

  if (exitCode) {
    process.exit(exitCode);
  } else {
    process.exit(1);
  }
};

const inspect = (prefix, object) => {
  Info(`${prefix} inspecting ${util.inspect(object)}`);
};

module.exports.Log = {
  Debug,
  Info,
  Error,
  bail,
  inspect,
};
