@openhoo/hoopilot 2.1.7 → 2.1.8

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
@@ -742,6 +742,32 @@ var DEFAULT_LOG_FORMAT = "pretty";
742
742
  var DEFAULT_LOG_LEVEL = "info";
743
743
  var LOG_FORMATS = ["json", "pretty"];
744
744
  var LOG_LEVELS = ["trace", "debug", "info", "warn", "error", "fatal", "silent"];
745
+ var PRETTY_INLINE_FIELDS = [
746
+ "component",
747
+ "command",
748
+ "event",
749
+ "method",
750
+ "path",
751
+ "status",
752
+ "durationMs",
753
+ "stream",
754
+ "route",
755
+ "requestId",
756
+ "upstreamPath",
757
+ "upstreamStatus",
758
+ "url",
759
+ "baseUrl",
760
+ "origin",
761
+ "currentVersion",
762
+ "installKind",
763
+ "latestVersion",
764
+ "assetName",
765
+ "count",
766
+ "plan",
767
+ "apiBaseUrl",
768
+ "authStorePath"
769
+ ];
770
+ var PRETTY_IGNORED_FIELDS = ["pid", "hostname", "service", ...PRETTY_INLINE_FIELDS];
745
771
  var REDACT_PATHS = [
746
772
  "apiKey",
747
773
  "authorization",
@@ -805,9 +831,11 @@ function createHoopilotLogger(options = {}) {
805
831
  // stream's TTY-ness is unknown, so default to no color there.
806
832
  colorize: options.colorize ?? (options.stream ? false : process.stdout.isTTY),
807
833
  destination: options.stream ?? 1,
808
- ignore: "pid,hostname",
834
+ ignore: PRETTY_IGNORED_FIELDS.join(","),
835
+ levelFirst: true,
836
+ messageFormat: formatPrettyMessage,
809
837
  singleLine: true,
810
- translateTime: "SYS:standard"
838
+ translateTime: "SYS:HH:MM:ss"
811
839
  })
812
840
  )
813
841
  );
@@ -853,6 +881,45 @@ function errorDetails(error) {
853
881
  }
854
882
  return { message: String(error) };
855
883
  }
884
+ function formatPrettyMessage(log, messageKey) {
885
+ const message = formatPrettyLogMessage(log[messageKey]);
886
+ const fields = PRETTY_INLINE_FIELDS.flatMap((field) => {
887
+ const value = log[field];
888
+ if (value === void 0) {
889
+ return [];
890
+ }
891
+ return `${prettyFieldLabel(field)}=${formatPrettyFieldValue(field, value)}`;
892
+ });
893
+ return fields.length > 0 ? `${message} ${fields.join(" ")}` : message;
894
+ }
895
+ function formatPrettyLogMessage(value) {
896
+ return typeof value === "string" ? value : formatPrettyValue(value);
897
+ }
898
+ function prettyFieldLabel(field) {
899
+ return field === "durationMs" ? "duration" : field;
900
+ }
901
+ function formatPrettyFieldValue(field, value) {
902
+ const formatted = formatPrettyValue(value);
903
+ return field === "durationMs" && typeof value === "number" ? `${formatted}ms` : formatted;
904
+ }
905
+ function formatPrettyValue(value) {
906
+ if (typeof value === "number") {
907
+ return Number.isFinite(value) ? String(value) : JSON.stringify(value);
908
+ }
909
+ if (typeof value === "boolean") {
910
+ return String(value);
911
+ }
912
+ if (typeof value === "string") {
913
+ return isBarePrettyValue(value) ? value : JSON.stringify(value);
914
+ }
915
+ if (value === null) {
916
+ return "null";
917
+ }
918
+ return JSON.stringify(value) ?? String(value);
919
+ }
920
+ function isBarePrettyValue(value) {
921
+ return /^[A-Za-z0-9._~:/?#[\]@!$&'()*+,;=%-]+$/.test(value);
922
+ }
856
923
  function isLogFormat(value) {
857
924
  return LOG_FORMATS.includes(value);
858
925
  }