@loggerjs/node 0.5.5 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -172,8 +172,9 @@ function createNodeFileDestination(options) {
172
172
  const flags = options.flags ?? (options.append === false ? "w" : "a");
173
173
  if (options.mkdir) mkdirSync(dirname(options.path), { recursive: true });
174
174
  let fd;
175
+ const syncFlags = options.sync ? flags : "a";
175
176
  const getFd = () => {
176
- fd ??= openSync(options.path, flags);
177
+ fd ??= openSync(options.path, syncFlags);
177
178
  return fd;
178
179
  };
179
180
  const syncWrite = (payload) => {
@@ -1953,6 +1954,15 @@ const signalExitCodes = {
1953
1954
  SIGINT: 130,
1954
1955
  SIGTERM: 143
1955
1956
  };
1957
+ function unhandledRejectionsMode() {
1958
+ const flags = [...process.execArgv, ...(process.env.NODE_OPTIONS ?? "").split(/\s+/)];
1959
+ let mode = "throw";
1960
+ for (const flag of flags) {
1961
+ const match = /^--unhandled-rejections=(.+)$/.exec(flag);
1962
+ if (match?.[1]) mode = match[1];
1963
+ }
1964
+ return mode;
1965
+ }
1956
1966
  function captureProcessIntegration(options = {}) {
1957
1967
  const uncaughtException = options.uncaughtException ?? true;
1958
1968
  const unhandledRejection = options.unhandledRejection ?? true;
@@ -1963,6 +1973,8 @@ function captureProcessIntegration(options = {}) {
1963
1973
  const signals = options.signals ?? ["SIGTERM"];
1964
1974
  const exitOnSignal = options.exitOnSignal ?? true;
1965
1975
  const exitOnUncaught = options.exitOnUncaught ?? true;
1976
+ const rejectionsMode = unhandledRejectionsMode();
1977
+ const exitOnUnhandledRejection = options.exitOnUnhandledRejection ?? (rejectionsMode === "throw" || rejectionsMode === "strict");
1966
1978
  const flushTimeoutMs = options.flushTimeoutMs ?? 250;
1967
1979
  const exitFn = options.exitFn ?? ((code) => process.exit(code));
1968
1980
  return {
@@ -2008,7 +2020,7 @@ function captureProcessIntegration(options = {}) {
2008
2020
  if (unhandledRejection) {
2009
2021
  const onUnhandledRejection = (reason) => {
2010
2022
  capture({
2011
- level: "error",
2023
+ level: exitOnUnhandledRejection ? "fatal" : "error",
2012
2024
  message: reason instanceof Error ? reason.message : "Unhandled promise rejection",
2013
2025
  error: reason,
2014
2026
  props: {
@@ -2016,6 +2028,14 @@ function captureProcessIntegration(options = {}) {
2016
2028
  reason: normalizeValue(reason, { maxDepth: 5 })
2017
2029
  }
2018
2030
  });
2031
+ if (exitOnUnhandledRejection) {
2032
+ flushSync();
2033
+ flushBounded().finally(() => exitFn(1));
2034
+ return;
2035
+ }
2036
+ if (options.exitOnUnhandledRejection === void 0) {
2037
+ if (rejectionsMode === "warn-with-error-code") process.exitCode = 1;
2038
+ }
2019
2039
  flushBestEffort();
2020
2040
  };
2021
2041
  process.on("unhandledRejection", onUnhandledRejection);