MCPcopy Create free account
hub / github.com/charmbracelet/bubbletea / LogToFileWith

Function LogToFileWith

logging.go:36–54  ·  view source on GitHub ↗

LogToFileWith does allows to call LogToFile with a custom LogOptionsSetter.

(path string, prefix string, log LogOptionsSetter)

Source from the content-addressed store, hash-verified

34
35// LogToFileWith does allows to call LogToFile with a custom LogOptionsSetter.
36func LogToFileWith(path string, prefix string, log LogOptionsSetter) (*os.File, error) {
37 f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o600) //nolint:mnd
38 if err != nil {
39 return nil, fmt.Errorf("error opening file for logging: %w", err)
40 }
41 log.SetOutput(f)
42
43 // Add a space after the prefix if a prefix is being specified and it
44 // doesn't already have a trailing space.
45 if len(prefix) > 0 {
46 finalRune, _ := utf8.DecodeLastRuneInString(prefix)
47 if !unicode.IsSpace(finalRune) {
48 prefix += " "
49 }
50 }
51 log.SetPrefix(prefix)
52
53 return f, nil
54}

Callers 2

LogToFileFunction · 0.85

Calls 2

SetOutputMethod · 0.80
SetPrefixMethod · 0.80

Tested by 1