mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: update logline prefix to use timestamp (#23966)
This change replaces the line number display in agent logs with formatted timestamps. The `AgentLogLine` component now shows timestamps in `HH:mm:ss.SSS` format using dayjs instead of sequential line numbers. The component no longer requires `number` and `maxLineNumber` props, and the associated styling for line number formatting has been removed. This is a global change.. but I don't think its one that will do much damage.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { Interpolation, Theme } from "@emotion/react";
|
||||
import AnsiToHTML from "ansi-to-html";
|
||||
import dayjs from "dayjs";
|
||||
import { type FC, type ReactNode, useMemo } from "react";
|
||||
import { type Line, LogLine, LogLinePrefix } from "#/components/Logs/LogLine";
|
||||
// Approximate height of a log line. Used to control virtualized list height.
|
||||
@@ -9,34 +9,26 @@ const convert = new AnsiToHTML();
|
||||
|
||||
interface AgentLogLineProps {
|
||||
line: Line;
|
||||
number: number;
|
||||
style: React.CSSProperties;
|
||||
sourceIcon: ReactNode;
|
||||
maxLineNumber: number;
|
||||
}
|
||||
|
||||
export const AgentLogLine: FC<AgentLogLineProps> = ({
|
||||
line,
|
||||
number,
|
||||
maxLineNumber,
|
||||
sourceIcon,
|
||||
style,
|
||||
}) => {
|
||||
const output = useMemo(() => {
|
||||
return convert.toHtml(line.output.split(/\r/g).pop() as string);
|
||||
}, [line.output]);
|
||||
const timestamp = useMemo(() => {
|
||||
return dayjs(line.time).format("HH:mm:ss.SSS");
|
||||
}, [line.time]);
|
||||
|
||||
return (
|
||||
<LogLine className="pl-4" level={line.level} style={style}>
|
||||
{sourceIcon}
|
||||
<LogLinePrefix
|
||||
css={styles.number}
|
||||
style={{
|
||||
minWidth: `${maxLineNumber.toString().length - 1}em`,
|
||||
}}
|
||||
>
|
||||
{number}
|
||||
</LogLinePrefix>
|
||||
<LogLinePrefix>{timestamp}</LogLinePrefix>
|
||||
<span
|
||||
// biome-ignore lint/security/noDangerouslySetInnerHtml: Output contains HTML to represent ANSI-code formatting
|
||||
dangerouslySetInnerHTML={{
|
||||
@@ -46,12 +38,3 @@ export const AgentLogLine: FC<AgentLogLineProps> = ({
|
||||
</LogLine>
|
||||
);
|
||||
};
|
||||
|
||||
const styles = {
|
||||
number: (theme) => ({
|
||||
width: 32,
|
||||
textAlign: "right",
|
||||
flexShrink: 0,
|
||||
color: theme.palette.text.disabled,
|
||||
}),
|
||||
} satisfies Record<string, Interpolation<Theme>>;
|
||||
|
||||
@@ -124,8 +124,6 @@ export const AgentLogs: React.FC<AgentLogsProps> = ({
|
||||
return (
|
||||
<AgentLogLine
|
||||
line={log}
|
||||
number={index + 1}
|
||||
maxLineNumber={logs.length}
|
||||
style={style}
|
||||
sourceIcon={
|
||||
<Tooltip>
|
||||
|
||||
Reference in New Issue
Block a user