UNPKG

judgeval

Version:

Judgment SDK for TypeScript/JavaScript

64 lines 2.92 kB
"use strict"; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const winston_1 = __importDefault(require("winston")); // Define the logger configuration const logger = winston_1.default.createLogger({ level: process.env.JUDGMENT_LOG_LEVEL || 'info', // Default to 'info', allow override via env var format: winston_1.default.format.combine(winston_1.default.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston_1.default.format.printf((_a) => { var { timestamp, level, message } = _a, meta = __rest(_a, ["timestamp", "level", "message"]); // Simple format: Timestamp [LEVEL]: message {meta} let metaString = ''; if (Object.keys(meta).length > 0) { try { // Attempt to stringify metadata, handle potential circular references metaString = ` ${JSON.stringify(meta, (key, value) => { if (typeof value === 'object' && value !== null) { // Basic check for circular reference, might need refinement if (key === '') return value; // Root object if (metaString.includes(JSON.stringify(value))) return '[Circular]'; } return value; })}`; } catch (error) { metaString = ' [Meta stringify error]'; } } return `${timestamp} [${level.toUpperCase()}]: ${message}${metaString}`; }), winston_1.default.format.colorize({ all: true }) // Optional: Add colors ), transports: [ // Log to the console new winston_1.default.transports.Console(), // Future enhancement: Add file transport // new winston.transports.File({ filename: 'judgeval.log' }) ], // Handle exceptions exceptionHandlers: [ new winston_1.default.transports.Console() // new winston.transports.File({ filename: 'exceptions.log' }) ], // Handle promise rejections rejectionHandlers: [ new winston_1.default.transports.Console() // new winston.transports.File({ filename: 'rejections.log' }) ] }); exports.default = logger; //# sourceMappingURL=logger-instance.js.map