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 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | 15x 15x 26x 26x 26x 16x 16x 16x 16x 16x 16x 3x 16x 6x 6x 16x 5x 16x 16x 11x 11x 11x 11x 11x 11x 3x 11x 3x 3x 11x 4x 11x 11x 36x 36x 36x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 15x | const chalk = require('chalk');
const messageCollector = require('./message-collector');
/**
* Logger utility with color-coded console output
* Provides consistent logging across the spec-up-t application
*
* All messages are automatically collected when message collection is active,
* allowing healthchecks and other tools to consume the output in JSON format.
*/
class Logger {
/**
* Success messages - green with checkmark
*/
static success(message, ...args) {
console.log(chalk.green('✅'), chalk.green(message), ...args);
messageCollector.addMessage('success', message, args);
console.log(); // Extra newline for readability
}
/**
* Error messages - red with X mark
*
* Enhanced error logging with optional context and actionable guidance.
*
* @param {string} message - The main error message
* @param {...any} args - Additional arguments. Can include:
* - Regular values (strings, numbers, objects) for message formatting
* - An options object (if last arg is object with 'hint', 'context', or 'details' keys):
* - hint: Actionable suggestion for fixing the error
* - context: Additional context about where/why the error occurred
* - details: Technical details or error objects
*
* @example
* Logger.error('File not found', {
* context: 'specs.json',
* hint: 'Create a specs.json file in your project root',
* details: error.message
* });
*/
static error(message, ...args) {
// Extract options object if present (last arg with special keys)
const lastArg = args[args.length - 1];
const isOptionsObject = lastArg && typeof lastArg === 'object' &&
(lastArg.hint || lastArg.context || lastArg.details);
const options = isOptionsObject ? args.pop() : {};
const regularArgs = args;
// Display main error message
console.log(chalk.red('❌'), chalk.red(message), ...regularArgs);
// Display context if provided - helps identify the scope of the error
if (options.context) {
console.log(chalk.red(' Context:'), chalk.gray(options.context));
}
// Display technical details if provided - useful for debugging
if (options.details) {
const detailsStr = typeof options.details === 'object'
? JSON.stringify(options.details, null, 2)
: String(options.details);
console.log(chalk.red(' Details:'), chalk.gray(detailsStr));
}
// Display actionable hint if provided - most valuable for authors
if (options.hint) {
console.log(chalk.yellow(' 💡 How to fix:'), chalk.yellow(options.hint));
}
// Collect message with all context for healthcheck/JSON output
messageCollector.addMessage('error', message, [...regularArgs, options]);
console.log(); // Extra newline for readability
}
/**
* Warning messages - yellow with warning symbol
*
* Enhanced warning logging with optional context and actionable guidance.
*
* @param {string} message - The main warning message
* @param {...any} args - Additional arguments. Can include:
* - Regular values (strings, numbers, objects) for message formatting
* - An options object (if last arg is object with 'hint', 'context', or 'details' keys):
* - hint: Actionable suggestion for addressing the warning
* - context: Additional context about where/why the warning occurred
* - details: Technical details or related information
*
* @example
* Logger.warn('Using fallback configuration', {
* context: 'specs.json missing optional field',
* hint: 'Add "output_path" to specs.json for better control',
* details: 'Using default: ./docs'
* });
*/
static warn(message, ...args) {
// Extract options object if present (last arg with special keys)
const lastArg = args[args.length - 1];
const isOptionsObject = lastArg && typeof lastArg === 'object' &&
(lastArg.hint || lastArg.context || lastArg.details);
const options = isOptionsObject ? args.pop() : {};
const regularArgs = args;
// Display main warning message
console.log(chalk.keyword('orange')('❗'), chalk.yellow(message), ...regularArgs);
// Display context if provided - helps identify the scope of the warning
if (options.context) {
console.log(chalk.yellow(' Context:'), chalk.gray(options.context));
}
// Display technical details if provided - useful for understanding the situation
if (options.details) {
const detailsStr = typeof options.details === 'object'
? JSON.stringify(options.details, null, 2)
: String(options.details);
console.log(chalk.yellow(' Details:'), chalk.gray(detailsStr));
}
// Display actionable hint if provided - helps authors improve their spec
if (options.hint) {
console.log(chalk.cyan(' 💡 Suggestion:'), chalk.cyan(options.hint));
}
// Collect message with all context for healthcheck/JSON output
messageCollector.addMessage('warn', message, [...regularArgs, options]);
console.log(); // Extra newline for readability
}
/**
* Action required messages - red with pointing hand icon
*
* Indicates that the user must take action to proceed.
* More urgent than a warning, used when user intervention is required.
*
* @param {string} message - The main action required message
* @param {...any} args - Additional arguments. Can include:
* - Regular values (strings, numbers, objects) for message formatting
* - An options object (if last arg is object with 'hint', 'context', or 'details' keys):
* - hint: Clear instruction on what action to take
* - context: Additional context about why action is needed
* - details: Technical details or related information
*
* @example
* Logger.action('Configuration required before proceeding', {
* context: 'specs.json is incomplete',
* hint: 'Add the "title" and "github_url" fields to specs.json',
* details: 'See https://example.com/docs'
* });
*/
static action(message, ...args) {
// Extract options object if present (last arg with special keys)
const lastArg = args[args.length - 1];
const isOptionsObject = lastArg && typeof lastArg === 'object' &&
(lastArg.hint || lastArg.context || lastArg.details);
const options = isOptionsObject ? args.pop() : {};
const regularArgs = args;
// Display main action required message - red to signal urgency
console.log(chalk.red('👉'), chalk.red(message), ...regularArgs);
// Display context if provided - explains why action is needed
if (options.context) {
console.log(chalk.red(' Context:'), chalk.gray(options.context));
}
// Display technical details if provided - helps understand the situation
if (options.details) {
const detailsStr = typeof options.details === 'object'
? JSON.stringify(options.details, null, 2)
: String(options.details);
console.log(chalk.red(' Details:'), chalk.gray(detailsStr));
}
// Display hint if provided - critical instruction on what to do
if (options.hint) {
console.log(chalk.red(' 👉 Action:'), chalk.red(options.hint));
}
// Collect message with all context for healthcheck/JSON output
messageCollector.addMessage('action', message, [...regularArgs, options]);
console.log(); // Extra newline for readability
}
/**
* Information messages - blue
*/
static info(message, ...args) {
console.log(chalk.blue('📋'), chalk.blue(message), ...args);
messageCollector.addMessage('info', message, args);
console.log(); // Extra newline for readability
}
/**
* Processing messages - cyan
*/
static process(message, ...args) {
console.log(chalk.cyan('🔄'), chalk.cyan(message), ...args);
messageCollector.addMessage('process', message, args);
console.log(); // Extra newline for readability
}
/**
* Debug messages - gray
*/
static debug(message, ...args) {
console.log(chalk.gray('🔍'), chalk.gray(message), ...args);
messageCollector.addMessage('debug', message, args);
console.log(); // Extra newline for readability
}
/**
* Highlight important data - magenta
*/
static highlight(message, ...args) {
console.log(chalk.blue('📋'), chalk.blue(message), ...args);
messageCollector.addMessage('highlight', message, args);
console.log(); // Extra newline for readability
}
/**
* Section separators
*/
static separator() {
console.log(chalk.gray('═'.repeat(60)));
messageCollector.addMessage('separator', '═'.repeat(60), []);
console.log(); // Extra newline for readability
}
/**
* Progress indicator with counts
*/
static progress(current, total, message) {
const percentage = Math.round((current / total) * 100);
const bar = '█'.repeat(Math.floor(percentage / 5)) + '░'.repeat(20 - Math.floor(percentage / 5));
const progressMessage = `[${bar}] ${percentage}% ${message}`;
console.log(chalk.cyan(`📊 ${progressMessage}`));
messageCollector.addMessage('progress', progressMessage, [current, total]);
console.log(); // Extra newline for readability
}
}
module.exports = Logger;
|