github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/web/src/logs.ts (about)

     1  // Helper functions for dealing with logs
     2  
     3  import { LogLine, ResourceName } from "./types"
     4  
     5  export function logLinesFromString(
     6    log: string,
     7    manifestName?: string
     8  ): LogLine[] {
     9    let lines = log.split("\n")
    10    return lines.map((text) => {
    11      return {
    12        text: text,
    13        manifestName: manifestName ?? "",
    14        level: "INFO",
    15        spanId: "",
    16        storedLineIndex: 0,
    17      }
    18    })
    19  }
    20  
    21  export function logLinesToString(
    22    lines: LogLine[],
    23    showManifestPrefix: boolean
    24  ): string {
    25    return lines
    26      .map((line) => {
    27        let text = line.text
    28        if (showManifestPrefix) {
    29          text = sourcePrefix(line.manifestName) + text
    30        }
    31        return text
    32      })
    33      .join("\n")
    34  }
    35  
    36  export function sourcePrefix(n: string) {
    37    if (n === "" || n === ResourceName.tiltfile) {
    38      return ""
    39    }
    40    let max = 12
    41    let spaces = ""
    42    if (n.length > max) {
    43      n = n.substring(0, max - 1) + "…"
    44    } else {
    45      spaces = " ".repeat(max - n.length)
    46    }
    47    return n + spaces + "┊ "
    48  }
    49  
    50  export function isBuildSpanId(spanId: string): boolean {
    51    return spanId.indexOf("build:") !== -1
    52  }