@wgtechlabs/log-engine
Version:
A lightweight, security-first logging utility with automatic data redaction for Node.js applications - the first logging library with built-in PII protection.
40 lines • 1.64 kB
JavaScript
;
/**
* Timestamp formatting utilities
* Handles ISO timestamp and local time formatting for log messages
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTimestampComponents = getTimestampComponents;
exports.formatTimestamp = formatTimestamp;
/**
* Generates the current timestamp as both an ISO 8601 string and a compact US English local time string.
*
* @returns An object containing `isoTimestamp` (ISO 8601 format) and `timeString` (localized time string without spaces)
*/
function getTimestampComponents() {
const now = new Date();
const isoTimestamp = now.toISOString();
const timeString = now.toLocaleTimeString('en-US', {
hour: 'numeric',
minute: '2-digit',
hour12: true
}).replace(/\s+/g, '');
return {
isoTimestamp,
timeString
};
}
/**
* Returns a formatted string combining an ISO timestamp and a local time string, each wrapped with specified color codes for console output.
*
* @param isoTimestamp - The ISO 8601 formatted timestamp to display
* @param timeString - The local time string to display
* @param colors - An object containing color codes for the timestamp, time string, and reset sequence
* @returns The combined, colorized timestamp string suitable for log messages
*/
function formatTimestamp(isoTimestamp, timeString, colors) {
const coloredTimestamp = `${colors.timestamp}[${isoTimestamp}]${colors.reset}`;
const coloredTimeString = `${colors.timeString}[${timeString}]${colors.reset}`;
return `${coloredTimestamp}${coloredTimeString}`;
}
//# sourceMappingURL=timestamp.js.map