sonarqube-issues-exporter
Version:
Enterprise-level SonarQube issues exporter with TypeScript support for generating comprehensive HTML reports with dark theme
100 lines • 3.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppLogger = void 0;
exports.initLogger = initLogger;
exports.getLogger = getLogger;
const winston_1 = require("winston");
class AppLogger {
logger;
MAX_META_LENGTH = 1000; // Maximum length for metadata objects
constructor(config) {
const logFormat = winston_1.format.combine(winston_1.format.timestamp({
format: () => new Date().toLocaleString('en-US', {
timeZone: Intl.DateTimeFormat().resolvedOptions().timeZone,
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: true,
}),
}), winston_1.format.errors({ stack: true }), winston_1.format.json(), winston_1.format.prettyPrint());
const logTransports = [
new winston_1.transports.Console({
level: config.level,
format: winston_1.format.combine(winston_1.format.colorize(), winston_1.format.simple()),
}),
];
if (config.file) {
logTransports.push(new winston_1.transports.File({
filename: config.file,
level: config.level,
format: logFormat,
}));
}
this.logger = (0, winston_1.createLogger)({
level: config.level,
format: logFormat,
transports: logTransports,
exitOnError: false,
});
}
sanitizeMeta(meta) {
if (!meta)
return meta;
// If it's a string, truncate if too long
if (typeof meta === 'string') {
return meta.length > this.MAX_META_LENGTH
? meta.substring(0, this.MAX_META_LENGTH) + '... [truncated]'
: meta;
}
// If it's an object, convert to string and truncate
if (typeof meta === 'object') {
try {
const jsonString = JSON.stringify(meta, (key, value) => {
// Hide sensitive data
if (key.toLowerCase().includes('token') ||
key.toLowerCase().includes('password') ||
key.toLowerCase().includes('secret')) {
return '[REDACTED]';
}
return value;
});
if (jsonString.length > this.MAX_META_LENGTH) {
return jsonString.substring(0, this.MAX_META_LENGTH) + '... [truncated]';
}
return JSON.parse(jsonString);
}
catch {
return '[Object - could not serialize]';
}
}
return meta;
}
info(message, meta) {
this.logger.info(message, this.sanitizeMeta(meta));
}
error(message, meta) {
this.logger.error(message, this.sanitizeMeta(meta));
}
warn(message, meta) {
this.logger.warn(message, this.sanitizeMeta(meta));
}
debug(message, meta) {
this.logger.debug(message, this.sanitizeMeta(meta));
}
}
exports.AppLogger = AppLogger;
// Default logger instance
let defaultLogger;
function initLogger(config) {
defaultLogger = new AppLogger(config);
}
function getLogger() {
if (!defaultLogger) {
defaultLogger = new AppLogger({ level: 'info' });
}
return defaultLogger;
}
//# sourceMappingURL=logger.js.map