tirkarthi commented on issue #37443: URL: https://github.com/apache/airflow/issues/37443#issuecomment-1968575313
Changes were made in https://github.com/apache/airflow/issues/35280 to log tab to allow links which also allows html instead of a code block. I tried a rough attempt patch like below which applies green to info and red to error. Note files in the logs don't have ANSI color codes stored so this has to be done in frontend based on the log level for the statement. I can go ahead with a PR if okay, ```diff diff --git a/airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts b/airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts index c3c4084044..3e805dab45 100644 --- a/airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts +++ b/airflow/www/static/js/dag/details/taskInstance/Logs/utils.ts @@ -101,9 +101,10 @@ export const parseLogs = ( ) { // sanitize the lines to remove any tags that may cause HTML injection const sanitizedLine = sanitizeHtml(parsedLine, { - allowedTags: ["a"], + allowedTags: ["a", "span"], allowedAttributes: { - a: ["href", "target", "style"], + a: ["href", "target", "style"], + span: ["style"], }, transformTags: { a: (tagName, attribs) => { @@ -113,6 +114,13 @@ export const parseLogs = ( attribs, }; }, + span: (tagName, attribs) => { + attribs.style = "color: red; text-decoration: none;"; + return { + tagName: "span", + attribs, + }; + } }, }); @@ -122,7 +130,14 @@ export const parseLogs = ( '<a href="$1" target="_blank" style="color: blue; text-decoration: underline;">$1</a>' ); - parsedLines.push(lineWithHyperlinks); + let lineWithColor = sanitizedLine; + if (sanitizedLine.includes("INFO")) { + lineWithColor = `<span style="color: green; text-decoration: none;"> ${sanitizedLine} </span>` + } else if (sanitizedLine.includes("ERROR")) { + lineWithColor = `<span style="color: red; text-decoration: none;"> ${sanitizedLine} </span>` + } + + parsedLines.push(lineWithColor); } }); ```  -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
