@putkoff/abstract-logger 0.0.40 → 0.0.46

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/cjs/index.js CHANGED
@@ -187,10 +187,6 @@ const COLS = {
187
187
  /* ------------------------------------------------------------------ */
188
188
  /* Winston logger (Node only) */
189
189
  /* ------------------------------------------------------------------ */
190
- console.log("ENV CHECK:", {
191
- LOG_SHOW_DETAILS: process.env.LOG_SHOW_DETAILS,
192
- LOG_DETAILS_ALLOWLIST: process.env.LOG_DETAILS_ALLOWLIST,
193
- });
194
190
  function getLogConfig() {
195
191
  return {
196
192
  condensed: process.env.LOG_CONDENSED !== "false",
@@ -213,6 +209,17 @@ function getLogConfig() {
213
209
  : [],
214
210
  };
215
211
  }
212
+ function debugLogConfig() {
213
+ if (process.env.LOG_DEBUG_CONFIG === "true") {
214
+ console.log("LOG CONFIG ENV:", {
215
+ LOG_SHOW_DETAILS: process.env.LOG_SHOW_DETAILS,
216
+ LOG_DETAILS_ALLOWLIST: process.env.LOG_DETAILS_ALLOWLIST,
217
+ LOG_PRETTY_DETAILS: process.env.LOG_PRETTY_DETAILS,
218
+ LOG_CONDENSED: process.env.LOG_CONDENSED,
219
+ LOG_EXPAND_DEBUG: process.env.LOG_EXPAND_DEBUG,
220
+ });
221
+ }
222
+ }
216
223
  function parse$1(v) {
217
224
  return v ? v.split(",").map(s => s.trim()) : [];
218
225
  }
@@ -14820,12 +14827,13 @@ function hash(str) {
14820
14827
  }
14821
14828
  function shouldLog(opts, caller) {
14822
14829
  const cfg = getLogConfig();
14830
+ // logType is already normalized upstream
14831
+ const type = opts.logType;
14823
14832
  const fn = caller.functionName;
14824
- const type = opts.logType ?? "info";
14825
14833
  const activity = opts.activity;
14826
14834
  const message = opts.message;
14827
14835
  // ─────────────────────────────────────
14828
- // 1️⃣ Hard allowlist (strongest gate)
14836
+ // 1️⃣ Hard allowlist
14829
14837
  // ─────────────────────────────────────
14830
14838
  if (cfg.functionAllowlist.length > 0) {
14831
14839
  if (!cfg.functionAllowlist.includes(fn))
@@ -14841,17 +14849,17 @@ function shouldLog(opts, caller) {
14841
14849
  if (cfg.logTypeBlocklist.includes(type))
14842
14850
  return false;
14843
14851
  // ─────────────────────────────────────
14844
- // 3️⃣ Burst protection (debug spam)
14852
+ // 3️⃣ Burst protection (debug)
14845
14853
  // ─────────────────────────────────────
14846
14854
  if (type === "debug") {
14847
14855
  const key = fn + ":" + message;
14848
14856
  const count = (seen.get(key) ?? 0) + 1;
14849
14857
  seen.set(key, count);
14850
14858
  if (count > 5)
14851
- return false; // drop after 5 identical logs
14859
+ return false;
14852
14860
  }
14853
14861
  // ─────────────────────────────────────
14854
- // 4️⃣ Deterministic sampling
14862
+ // 4️⃣ Sampling
14855
14863
  // ─────────────────────────────────────
14856
14864
  if (cfg.sampleRate < 1) {
14857
14865
  const pct = (hash(fn) % 100) / 100;
@@ -14861,19 +14869,13 @@ function shouldLog(opts, caller) {
14861
14869
  return true;
14862
14870
  }
14863
14871
 
14864
- /* ------------------------------------------------------------------ */
14865
- /* IMPLEMENTATION */
14866
- /* ------------------------------------------------------------------ */
14867
14872
  function getLogString(messageOrOptions, logType = null, details = null, function_name = null, file_location = null, consumerLogger = null) {
14868
- // ---------------- Normalize inputs ----------------
14869
- let opts;
14870
- if (typeof messageOrOptions === "object" && messageOrOptions !== null) {
14871
- // Dict-style
14872
- opts = messageOrOptions;
14873
- }
14874
- else {
14875
- // Positional-style
14876
- opts = {
14873
+ /* -------------------------------------------------- */
14874
+ /* Normalize inputs */
14875
+ /* -------------------------------------------------- */
14876
+ const opts = typeof messageOrOptions === "object" && messageOrOptions !== null
14877
+ ? messageOrOptions
14878
+ : {
14877
14879
  message: messageOrOptions,
14878
14880
  logType,
14879
14881
  details,
@@ -14881,27 +14883,39 @@ function getLogString(messageOrOptions, logType = null, details = null, function
14881
14883
  file_location,
14882
14884
  consumerLogger,
14883
14885
  };
14884
- }
14885
14886
  let { message, logType: resolvedLogType, details: resolvedDetails, function_name: resolvedFunctionName, file_location: resolvedFileLocation, consumerLogger: resolvedLoggerInput, } = opts;
14886
- // ---------------- Resolve caller info ----------------
14887
+ /* -------------------------------------------------- */
14888
+ /* Caller info */
14889
+ /* -------------------------------------------------- */
14887
14890
  const caller = getCallerInfo(getLogString);
14891
+ /* -------------------------------------------------- */
14892
+ /* 🔒 Single source of truth for logType */
14893
+ /* -------------------------------------------------- */
14894
+ const finalLogType = resolvedLogType ?? "info";
14895
+ // 🔒 overwrite raw input so downstream never guesses
14896
+ opts.logType = finalLogType;
14897
+ /* -------------------------------------------------- */
14898
+ /* Blocking */
14899
+ /* -------------------------------------------------- */
14888
14900
  if (!shouldLog(opts, caller)) {
14889
- return ""; // 🔕 blocked — nothing emitted
14901
+ return "";
14890
14902
  }
14891
- // ---------------- Resolve caller info ----------------
14903
+ /* -------------------------------------------------- */
14904
+ /* Resolve names */
14905
+ /* -------------------------------------------------- */
14892
14906
  resolvedFunctionName = resolveValue(resolvedFunctionName, caller.functionName);
14893
14907
  resolvedFileLocation = resolveValue(resolvedFileLocation, caller.file);
14894
- const finalLogType = resolvedLogType ?? "info";
14895
- const emoji = activityEmojiMap[resolvedLogType ?? ""] ??
14896
- "ℹ️";
14908
+ /* -------------------------------------------------- */
14909
+ /* Formatting decisions */
14910
+ /* -------------------------------------------------- */
14897
14911
  const LOG_CONFIG = getLogConfig();
14898
14912
  const condense = shouldCondense(finalLogType);
14899
14913
  const showDetails = shouldShowDetails(finalLogType);
14900
- // 👇 ADD THIS
14901
14914
  const pretty = LOG_CONFIG.prettyDetails &&
14902
14915
  !condense;
14916
+ const emoji = activityEmojiMap[finalLogType] ?? "ℹ️";
14903
14917
  const timestamp = new Date().toISOString();
14904
- if (condense) {
14918
+ if (condense && resolvedFileLocation) {
14905
14919
  resolvedFileLocation = resolvedFileLocation.split("/").pop();
14906
14920
  }
14907
14921
  padRight(emoji, 3);
@@ -14919,7 +14933,7 @@ function getLogString(messageOrOptions, logType = null, details = null, function
14919
14933
  file: resolvedFileLocation,
14920
14934
  condense,
14921
14935
  maxDetailsLength: LOG_CONFIG.maxDetailsLength,
14922
- pretty, // 👈 THIS IS THE MISSING WIRE
14936
+ pretty,
14923
14937
  }), finalLogType, resolvedLoggerInput);
14924
14938
  }
14925
14939
 
@@ -14927,6 +14941,7 @@ exports.COLS = COLS;
14927
14941
  exports.IS_BROWSER = IS_BROWSER;
14928
14942
  exports.IS_NODE = IS_NODE;
14929
14943
  exports.activityEmojiMap = activityEmojiMap;
14944
+ exports.debugLogConfig = debugLogConfig;
14930
14945
  exports.extractFile = extractFile;
14931
14946
  exports.formatLogLine = formatLogLine;
14932
14947
  exports.getCallerInfo = getCallerInfo;