@levrbet/shared 0.2.11 → 0.2.13
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,
|
|
34
|
+
const { combine, timestamp, errors, json, printf, splat } = winston_1.default.format;
|
|
35
35
|
// Determine log level based on environment
|
|
36
36
|
const getLogLevel = () => {
|
|
37
37
|
switch (dotenv_1.LEVR_ENV) {
|
|
@@ -47,13 +47,28 @@ const getLogLevel = () => {
|
|
|
47
47
|
return "info";
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
+
// Color mapping for manual colorization
|
|
51
|
+
const colors = {
|
|
52
|
+
error: "\x1b[31m", // red
|
|
53
|
+
warn: "\x1b[33m", // yellow
|
|
54
|
+
info: "\x1b[36m", // cyan
|
|
55
|
+
http: "\x1b[35m", // magenta
|
|
56
|
+
verbose: "\x1b[90m", // gray
|
|
57
|
+
debug: "\x1b[34m", // blue
|
|
58
|
+
silly: "\x1b[90m", // gray
|
|
59
|
+
};
|
|
60
|
+
const reset = "\x1b[0m";
|
|
50
61
|
// Custom format for console output in non-production
|
|
51
62
|
const consoleFormat = printf(({ level, message, timestamp, stack, service, ...metadata }) => {
|
|
52
|
-
|
|
63
|
+
const color = colors[level] || "";
|
|
64
|
+
const coloredLevel = dotenv_1.LEVR_ENV === "prod" ? level : `${color}${level}${reset}`;
|
|
65
|
+
let msg = `${timestamp} [${coloredLevel}]`;
|
|
53
66
|
if (service) {
|
|
54
67
|
msg += ` [${service}]`;
|
|
55
68
|
}
|
|
56
|
-
|
|
69
|
+
// Ensure message is properly stringified
|
|
70
|
+
const formattedMessage = typeof message === "object" ? JSON.stringify(message) : String(message);
|
|
71
|
+
msg += `: ${formattedMessage}`;
|
|
57
72
|
// Add stack trace if error
|
|
58
73
|
if (stack) {
|
|
59
74
|
msg += `\n${stack}`;
|
|
@@ -69,11 +84,12 @@ const consoleFormat = printf(({ level, message, timestamp, stack, service, ...me
|
|
|
69
84
|
// Production format (structured JSON for OTEL)
|
|
70
85
|
const productionFormat = combine(timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), errors({ stack: true }), splat(), json());
|
|
71
86
|
// Development format (human-readable)
|
|
72
|
-
const developmentFormat = combine(timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), errors({ stack: true }), splat(),
|
|
87
|
+
const developmentFormat = combine(timestamp({ format: "YYYY-MM-DD HH:mm:ss" }), errors({ stack: true }), splat(), consoleFormat);
|
|
73
88
|
const createLogger = (options = {}) => {
|
|
74
89
|
const { service = "@levrbet/shared", level = getLogLevel(), additionalMeta = {} } = options;
|
|
75
90
|
const logger = winston_1.default.createLogger({
|
|
76
91
|
level,
|
|
92
|
+
levels: winston_1.default.config.npm.levels,
|
|
77
93
|
format: dotenv_1.LEVR_ENV === "prod" ? productionFormat : developmentFormat,
|
|
78
94
|
defaultMeta: {
|
|
79
95
|
service,
|
|
@@ -95,7 +111,11 @@ const logger = (0, exports.createLogger)();
|
|
|
95
111
|
// Create stream for Morgan (HTTP logging)
|
|
96
112
|
const createStream = (loggerInstance = logger) => ({
|
|
97
113
|
write: (message) => {
|
|
98
|
-
|
|
114
|
+
// Trim and ensure message is a string, not an array or object
|
|
115
|
+
const msg = typeof message === "string" ? message.trim() : String(message);
|
|
116
|
+
if (msg.length > 0) {
|
|
117
|
+
loggerInstance.info(msg);
|
|
118
|
+
}
|
|
99
119
|
},
|
|
100
120
|
});
|
|
101
121
|
exports.createStream = createStream;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"winston.js","sourceRoot":"","sources":["../../../src/server/config/winston.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6B;AAC7B,qCAAmC;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,EAAE,OAAO,EAA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