MCPcopy
hub / github.com/stackblitz/bolt.new / log

Function log

app/utils/logger.ts:47–85  ·  view source on GitHub ↗
(level: DebugLevel, scope: string | undefined, messages: any[])

Source from the content-addressed store, hash-verified

45}
46
47function log(level: DebugLevel, scope: string | undefined, messages: any[]) {
48 const levelOrder: DebugLevel[] = ['trace', 'debug', 'info', 'warn', 'error'];
49
50 if (levelOrder.indexOf(level) < levelOrder.indexOf(currentLevel)) {
51 return;
52 }
53
54 const allMessages = messages.reduce((acc, current) => {
55 if (acc.endsWith('\n')) {
56 return acc + current;
57 }
58
59 if (!acc) {
60 return current;
61 }
62
63 return `${acc} ${current}`;
64 }, '');
65
66 if (!supportsColor) {
67 console.log(`[${level.toUpperCase()}]`, allMessages);
68
69 return;
70 }
71
72 const labelBackgroundColor = getColorForLevel(level);
73 const labelTextColor = level === 'warn' ? 'black' : 'white';
74
75 const labelStyles = getLabelStyles(labelBackgroundColor, labelTextColor);
76 const scopeStyles = getLabelStyles('#77828D', 'white');
77
78 const styles = [labelStyles];
79
80 if (typeof scope === 'string') {
81 styles.push('', scopeStyles);
82 }
83
84 console.log(`%c${level.toUpperCase()}${scope ? `%c %c${scope}` : ''}`, ...styles, allMessages);
85}
86
87function getLabelStyles(color: string, textColor: string) {
88 return `background-color: ${color}; color: white; border: 4px solid ${color}; color: ${textColor};`;

Callers 2

logger.tsFile · 0.85
createScopedLoggerFunction · 0.85

Calls 2

getColorForLevelFunction · 0.85
getLabelStylesFunction · 0.85

Tested by

no test coverage detected