Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | 12x 12x 12x 60x 60x 60x 12x 12x 12x 12x 12x 12x 92x 92x 12x 89x 89x 89x 12x 1x 20x 1x 12x 2x 1x 12x 1x 12x 27x 26x 3x 12x 1x | /**
* @fileoverview Logger Utility Module
* @description Centralized logging with configurable levels using loglevel library.
* Provides module-specific loggers for simulation, physics, rendering, file operations, and UI.
* @module utils/logger
* @author Molecular Dynamics Team
* @version 3.0.0
*/
import log from 'loglevel';
/**
* Log level configuration based on environment
* @constant {string}
* @default 'debug' in development, 'warn' in production
*/
const LOG_LEVEL = process.env.NODE_ENV === 'production' ? 'warn' : 'debug';
log.setLevel(LOG_LEVEL);
/**
* Create a named logger for a specific module
* @function createLogger
* @param {string} moduleName - The name of the module for the logger
* @returns {Object} Configured loglevel logger instance
* @private
*/
const createLogger = (moduleName) => {
const logger = log.getLogger(moduleName);
logger.setLevel(LOG_LEVEL);
return logger;
};
/**
* Logger instance for simulation-related operations
* @type {Object}
*/
export const simulationLogger = createLogger('simulation');
/**
* Logger instance for physics calculations
* @type {Object}
*/
export const physicsLogger = createLogger('physics');
/**
* Logger instance for rendering operations
* @type {Object}
*/
export const renderLogger = createLogger('renderer');
/**
* Logger instance for file reading/parsing operations
* @type {Object}
*/
export const fileLogger = createLogger('fileReader');
/**
* Logger instance for UI interactions
* @type {Object}
*/
export const uiLogger = createLogger('ui');
/**
* Format a message with ISO timestamp
* @function formatMessage
* @param {string} message - The log message to format
* @returns {string} Formatted message with timestamp prefix [ISO-8601]
* @example
* formatMessage('Test message');
* // Returns: '[2025-01-01T12:00:00.000Z] Test message'
*/
export const formatMessage = (message) => {
const timestamp = new Date().toISOString();
return `[${timestamp}] ${message}`;
};
/**
* Log a message with context object to a specified logger
* @function logWithContext
* @param {Object} logger - The loglevel logger instance to use
* @param {('debug'|'info'|'warn'|'error')} level - The log level
* @param {string} message - The log message
* @param {Object} [context={}] - Additional context object to include in log
* @example
* logWithContext(simulationLogger, 'info', 'Atom added', { id: 1, type: 'H' });
* // Logs: '[2025-01-01T12:00:00.000Z] Atom added | {"id":1,"type":"H"}'
*/
export const logWithContext = (logger, level, message, context = {}) => {
const formattedMessage = formatMessage(message);
const contextStr = Object.keys(context).length > 0
? ` | ${JSON.stringify(context)}`
: '';
logger[level](`${formattedMessage}${contextStr}`);
};
/**
* Convenience logger object for simulation operations
* @namespace logSimulation
* @property {Function} debug - Log debug message
* @property {Function} info - Log info message
* @property {Function} warn - Log warning message
* @property {Function} error - Log error message
*/
export const logSimulation = {
/**
* Log debug message for simulation
* @param {string} msg - Message to log
* @param {Object} [ctx] - Context object
*/
debug: (msg, ctx) => logWithContext(simulationLogger, 'debug', msg, ctx),
/**
* Log info message for simulation
* @param {string} msg - Message to log
* @param {Object} [ctx] - Context object
*/
info: (msg, ctx) => logWithContext(simulationLogger, 'info', msg, ctx),
/**
* Log warning message for simulation
* @param {string} msg - Message to log
* @param {Object} [ctx] - Context object
*/
warn: (msg, ctx) => logWithContext(simulationLogger, 'warn', msg, ctx),
/**
* Log error message for simulation
* @param {string} msg - Message to log
* @param {Object} [ctx] - Context object
*/
error: (msg, ctx) => logWithContext(simulationLogger, 'error', msg, ctx),
};
/**
* Convenience logger object for physics calculations
* @namespace logPhysics
* @property {Function} debug - Log debug message
* @property {Function} info - Log info message
* @property {Function} warn - Log warning message
* @property {Function} error - Log error message
*/
export const logPhysics = {
debug: (msg, ctx) => logWithContext(physicsLogger, 'debug', msg, ctx),
info: (msg, ctx) => logWithContext(physicsLogger, 'info', msg, ctx),
warn: (msg, ctx) => logWithContext(physicsLogger, 'warn', msg, ctx),
error: (msg, ctx) => logWithContext(physicsLogger, 'error', msg, ctx),
};
/**
* Convenience logger object for rendering operations
* @namespace logRender
* @property {Function} debug - Log debug message
* @property {Function} info - Log info message
* @property {Function} warn - Log warning message
* @property {Function} error - Log error message
*/
export const logRender = {
debug: (msg, ctx) => logWithContext(renderLogger, 'debug', msg, ctx),
info: (msg, ctx) => logWithContext(renderLogger, 'info', msg, ctx),
warn: (msg, ctx) => logWithContext(renderLogger, 'warn', msg, ctx),
error: (msg, ctx) => logWithContext(renderLogger, 'error', msg, ctx),
};
/**
* Convenience logger object for file operations
* @namespace logFile
* @property {Function} debug - Log debug message
* @property {Function} info - Log info message
* @property {Function} warn - Log warning message
* @property {Function} error - Log error message
*/
export const logFile = {
debug: (msg, ctx) => logWithContext(fileLogger, 'debug', msg, ctx),
info: (msg, ctx) => logWithContext(fileLogger, 'info', msg, ctx),
warn: (msg, ctx) => logWithContext(fileLogger, 'warn', msg, ctx),
error: (msg, ctx) => logWithContext(fileLogger, 'error', msg, ctx),
};
/**
* Convenience logger object for UI interactions
* @namespace logUI
* @property {Function} debug - Log debug message
* @property {Function} info - Log info message
* @property {Function} warn - Log warning message
* @property {Function} error - Log error message
*/
export const logUI = {
debug: (msg, ctx) => logWithContext(uiLogger, 'debug', msg, ctx),
info: (msg, ctx) => logWithContext(uiLogger, 'info', msg, ctx),
warn: (msg, ctx) => logWithContext(uiLogger, 'warn', msg, ctx),
error: (msg, ctx) => logWithContext(uiLogger, 'error', msg, ctx),
};
/**
* Default export - the root loglevel instance
* @type {Object}
*/
export default log;
|