@@ -23,7 +23,7 @@ import { EventSourcePolyfill } from 'event-source-polyfill';
2323 ></v-btn >
2424 </div >
2525
26- <div id =" term" style = " background-color : #1e1e1e ; padding : 16 px ; border-radius : 8 px ; overflow-y : auto ; height : 100 % " >
26+ <div id =" term" class = " console-term " >
2727 </div >
2828 </div >
2929</template >
@@ -279,6 +279,36 @@ export default {
279279 this .isFullscreen = !! document .fullscreenElement ;
280280 },
281281
282+ appendLogContent (element , log ) {
283+ const levelMatch = log .match (/ \[ (DEBG| INFO| WARN| ERRO| CRIT| DEBUG| WARNING| ERROR| CRITICAL)\] / );
284+ if (! levelMatch) {
285+ element .innerText = ` ${ log} ` ;
286+ return ;
287+ }
288+
289+ const levelStart = levelMatch .index ;
290+ const levelEnd = levelStart + levelMatch[0 ].length ;
291+ const prefix = log .slice (0 , levelStart).trimEnd ();
292+ const message = log .slice (levelEnd).trimStart ();
293+
294+ const prefixSpan = document .createElement (' span' );
295+ prefixSpan .className = ' console-log-prefix' ;
296+ prefixSpan .innerText = prefix;
297+
298+ const levelSpan = document .createElement (' span' );
299+ levelSpan .className = ' console-log-level' ;
300+ levelSpan .innerText = levelMatch[0 ];
301+
302+ const messageSpan = document .createElement (' span' );
303+ messageSpan .className = ' console-log-message' ;
304+ messageSpan .innerText = message;
305+
306+ element .classList .add (' console-log-line--structured' );
307+ element .appendChild (prefixSpan);
308+ element .appendChild (levelSpan);
309+ element .appendChild (messageSpan);
310+ },
311+
282312 printLog (log ) {
283313 let ele = document .getElementById (' term' )
284314 if (! ele) {
@@ -297,7 +327,7 @@ export default {
297327
298328 span .style = style
299329 span .classList .add (' console-log-line' , ' fade-in' )
300- span . innerText = ` ${ log} ` ;
330+ this . appendLogContent (span, log) ;
301331 ele .appendChild (span)
302332 if (this .autoScroll ) {
303333 ele .scrollTop = ele .scrollHeight
@@ -328,18 +358,60 @@ export default {
328358 margin-left : 20px ;
329359}
330360
361+ .console-term {
362+ background-color : #1e1e1e ;
363+ border-radius : 8px ;
364+ height : 100% ;
365+ overflow-y : auto ;
366+ overflow-x : auto ;
367+ padding : 16px ;
368+ }
369+
331370.fullscreen-btn {
332371 color : rgba (255 , 255 , 255 , 0.7 ) !important ; /* 提高在深色背景下的对比度 */
333372}
334373
335374:deep(.console-log-line ) {
336375 display : block ;
337- margin-bottom : 2px ;
376+ margin : 0 0 2px ;
338377 font-family : SFMono-Regular, Menlo, Monaco, Consolas, var (--astrbot-font-cjk-mono ), monospace ;
339378 font-size : 12px ;
340379 white-space : pre-wrap ;
341380}
342381
382+ :deep(.console-log-line--structured ) {
383+ display : grid ;
384+ grid-template-columns : max-content max-content minmax (0 , 1fr );
385+ column-gap : 8px ;
386+ align-items : start ;
387+ white-space : normal ;
388+ }
389+
390+ :deep(.console-log-prefix ),
391+ :deep(.console-log-level ),
392+ :deep(.console-log-message ) {
393+ min-width : 0 ;
394+ white-space : pre-wrap ;
395+ }
396+
397+ :deep(.console-log-level ) {
398+ font-variant-numeric : tabular-nums ;
399+ }
400+
401+ :deep(.console-log-message ) {
402+ overflow-wrap : anywhere;
403+ }
404+
405+ @media (max-width : 768px ) {
406+ :deep(.console-log-line--structured ) {
407+ grid-template-columns : 1fr ;
408+ }
409+ :deep(.console-log-prefix :empty ),
410+ :deep(.console-log-level :empty ) {
411+ display : none ;
412+ }
413+ }
414+
343415:deep(.fade-in ) {
344416 animation : fadeIn 0.3s ;
345417}
0 commit comments