skayn-trading-sdk
Version:
Professional Bitcoin trading strategy backtesting framework with institutional-grade architecture
95 lines (79 loc) • 2.31 kB
JavaScript
/**
* Simple Production Logger for Skayn SDK
* No external dependencies, clean output
*/
const LOG_LEVELS = {
error: 0,
warn: 1,
info: 2,
debug: 3
};
class Logger {
constructor() {
this.logLevel = this.getLogLevel();
this.isProduction = process.env.NODE_ENV === 'production';
}
getLogLevel() {
const envLevel = process.env.SKAYN_LOG_LEVEL || 'info';
return LOG_LEVELS[envLevel] !== undefined ? LOG_LEVELS[envLevel] : LOG_LEVELS.info;
}
shouldLog(level) {
return LOG_LEVELS[level] <= this.logLevel;
}
formatMessage(level, message, meta = {}) {
const timestamp = new Date().toISOString();
if (this.isProduction) {
// Production: minimal JSON logging
return JSON.stringify({
timestamp,
level,
message,
...meta
});
} else {
// Development: clean colored output
const colors = {
error: '\x1b[31m', // red
warn: '\x1b[33m', // yellow
info: '\x1b[32m', // green
debug: '\x1b[36m', // cyan
reset: '\x1b[0m'
};
const color = colors[level] || colors.reset;
const metaStr = Object.keys(meta).length > 0 ? ` ${JSON.stringify(meta)}` : '';
return `${color}${level}\x1b[0m: ${message}${metaStr}`;
}
}
error(message, meta = {}) {
if (this.shouldLog('error')) {
console.error(this.formatMessage('error', message, meta));
}
}
warn(message, meta = {}) {
if (this.shouldLog('warn')) {
console.warn(this.formatMessage('warn', message, meta));
}
}
info(message, meta = {}) {
if (this.shouldLog('info')) {
console.log(this.formatMessage('info', message, meta));
}
}
debug(message, meta = {}) {
if (this.shouldLog('debug')) {
console.log(this.formatMessage('debug', message, meta));
}
}
}
const logger = new Logger();
// Goose-specific logging methods
logger.skaynAction = (action, details) => {
logger.info(`[SKAYN ACTION] ${action}`, { skaynAction: action, ...details });
};
logger.skaynDecision = (decision, rationale) => {
logger.info(`[SKAYN DECISION] ${decision}`, { skaynDecision: decision, rationale });
};
logger.trade = (tradeData) => {
logger.info('Trade executed', { trade: tradeData });
};
module.exports = logger;