@levrbet/shared 0.2.14 → 0.2.15
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.
|
@@ -31,7 +31,7 @@ const dotenv_1 = require("./dotenv");
|
|
|
31
31
|
logger.info("Using default logger")
|
|
32
32
|
*
|
|
33
33
|
*/
|
|
34
|
-
const { combine, timestamp, errors, json, printf
|
|
34
|
+
const { combine, timestamp, errors, json, printf } = winston_1.default.format;
|
|
35
35
|
// Determine log level based on environment
|
|
36
36
|
const getLogLevel = () => {
|
|
37
37
|
switch (dotenv_1.LEVR_ENV) {
|
|
@@ -58,67 +58,51 @@ const colors = {
|
|
|
58
58
|
silly: "\x1b[90m", // gray
|
|
59
59
|
};
|
|
60
60
|
const reset = "\x1b[0m";
|
|
61
|
-
// Helper to detect if object is array-like with numeric keys
|
|
62
|
-
const isArrayLikeObject = (obj) => {
|
|
63
|
-
if (typeof obj !== "object" || obj === null)
|
|
64
|
-
return false;
|
|
65
|
-
const keys = Object.keys(obj);
|
|
66
|
-
return keys.length > 0 && keys.every((key) => /^\d+$/.test(key));
|
|
67
|
-
};
|
|
68
|
-
// Safe stringify that handles array-like objects
|
|
69
|
-
const safeStringify = (value) => {
|
|
70
|
-
if (value === null || value === undefined)
|
|
71
|
-
return "";
|
|
72
|
-
if (typeof value === "string")
|
|
73
|
-
return value;
|
|
74
|
-
if (typeof value === "number" || typeof value === "boolean")
|
|
75
|
-
return String(value);
|
|
76
|
-
// Check if it's an array-like object (string that got converted to object)
|
|
77
|
-
if (isArrayLikeObject(value)) {
|
|
78
|
-
// Reconstruct the original string
|
|
79
|
-
const keys = Object.keys(value).sort((a, b) => parseInt(a) - parseInt(b));
|
|
80
|
-
return keys.map((key) => value[key]).join("");
|
|
81
|
-
}
|
|
82
|
-
try {
|
|
83
|
-
return JSON.stringify(value);
|
|
84
|
-
}
|
|
85
|
-
catch (err) {
|
|
86
|
-
return String(value);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
61
|
// Custom format for console output in non-production
|
|
90
|
-
const consoleFormat = printf((
|
|
62
|
+
const consoleFormat = printf((info) => {
|
|
63
|
+
const { level, message, timestamp, stack, service, ...metadata } = info;
|
|
91
64
|
const color = colors[level] || "";
|
|
92
65
|
const coloredLevel = dotenv_1.LEVR_ENV === "prod" ? level : `${color}${level}${reset}`;
|
|
93
66
|
let msg = `${timestamp} [${coloredLevel}]`;
|
|
94
67
|
if (service) {
|
|
95
68
|
msg += ` [${service}]`;
|
|
96
69
|
}
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
70
|
+
// Simple message handling
|
|
71
|
+
if (typeof message === "string") {
|
|
72
|
+
msg += `: ${message}`;
|
|
73
|
+
}
|
|
74
|
+
else if (message !== undefined && message !== null) {
|
|
75
|
+
try {
|
|
76
|
+
msg += `: ${JSON.stringify(message)}`;
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
msg += `: ${String(message)}`;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
100
82
|
// Add stack trace if error
|
|
101
83
|
if (stack) {
|
|
102
84
|
msg += `\n${stack}`;
|
|
103
85
|
}
|
|
104
|
-
// Add metadata if present
|
|
105
|
-
const
|
|
106
|
-
if (
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
86
|
+
// Add metadata if present (this is where extra arguments go)
|
|
87
|
+
const relevantKeys = Object.keys(metadata).filter((key) => !["level", "message", "timestamp", "service", "environment", "splat"].includes(key));
|
|
88
|
+
if (relevantKeys.length > 0) {
|
|
89
|
+
const metaObj = Object.fromEntries(relevantKeys.map((key) => [key, metadata[key]]));
|
|
90
|
+
try {
|
|
91
|
+
msg += `\n${JSON.stringify(metaObj, null, 2)}`;
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
msg += `\n${String(metaObj)}`;
|
|
110
95
|
}
|
|
111
|
-
msg += `\n${JSON.stringify(filteredMeta, null, 2)}`;
|
|
112
96
|
}
|
|
113
97
|
return msg;
|
|
114
98
|
});
|
|
115
99
|
// Production format (structured JSON for OTEL)
|
|
116
|
-
const productionFormat = combine(timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), errors({ stack: true }),
|
|
117
|
-
// Development format (human-readable)
|
|
118
|
-
const developmentFormat = combine(timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), errors({ stack: true }),
|
|
100
|
+
const productionFormat = combine(timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), errors({ stack: true }), json());
|
|
101
|
+
// Development format (human-readable) - NO splat()
|
|
102
|
+
const developmentFormat = combine(timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), errors({ stack: true }), consoleFormat);
|
|
119
103
|
const createLogger = (options = {}) => {
|
|
120
104
|
const { service = "@levrbet/shared", level = getLogLevel(), additionalMeta = {} } = options;
|
|
121
|
-
const
|
|
105
|
+
const winstonLogger = winston_1.default.createLogger({
|
|
122
106
|
level,
|
|
123
107
|
levels: winston_1.default.config.npm.levels,
|
|
124
108
|
format: dotenv_1.LEVR_ENV === "prod" ? productionFormat : developmentFormat,
|
|
@@ -134,7 +118,7 @@ const createLogger = (options = {}) => {
|
|
|
134
118
|
],
|
|
135
119
|
exitOnError: false,
|
|
136
120
|
});
|
|
137
|
-
return
|
|
121
|
+
return winstonLogger;
|
|
138
122
|
};
|
|
139
123
|
exports.createLogger = createLogger;
|
|
140
124
|
// Default logger instance
|
|
@@ -142,7 +126,6 @@ const logger = (0, exports.createLogger)();
|
|
|
142
126
|
// Create stream for Morgan (HTTP logging)
|
|
143
127
|
const createStream = (loggerInstance = logger) => ({
|
|
144
128
|
write: (message) => {
|
|
145
|
-
// Trim and ensure message is a string, not an array or object
|
|
146
129
|
const msg = typeof message === "string" ? message.trim() : String(message);
|
|
147
130
|
if (msg.length > 0) {
|
|
148
131
|
loggerInstance.info(msg);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"winston.js","sourceRoot":"","sources":["../../../src/server/config/winston.ts"],"names":[],"mappings":";;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