MCPcopy Create free account
hub / github.com/daodst/chat / setupFileHook

Function setupFileHook

internal/log.go:123–147  ·  view source on GitHub ↗

Add a new FSHook to the logger. Each component will log in its own file

(hook config.LogrusHook, level logrus.Level, componentName string)

Source from the content-addressed store, hash-verified

121
122// Add a new FSHook to the logger. Each component will log in its own file
123func setupFileHook(hook config.LogrusHook, level logrus.Level, componentName string) {
124 dirPath := (hook.Params["path"]).(string)
125 fullPath := filepath.Join(dirPath, componentName+".log")
126
127 if err := os.MkdirAll(path.Dir(fullPath), os.ModePerm); err != nil {
128 logrus.Fatalf("Couldn't create directory %s: %q", path.Dir(fullPath), err)
129 }
130
131 logrus.AddHook(&logLevelHook{
132 level,
133 dugong.NewFSHook(
134 fullPath,
135 &utcFormatter{
136 &logrus.TextFormatter{
137 TimestampFormat: "2006-01-02T15:04:05.000000000Z07:00",
138 DisableColors: true,
139 DisableTimestamp: false,
140 DisableSorting: false,
141 QuoteEmptyFields: true,
142 },
143 },
144 &dugong.DailyRotationSchedule{GZip: true},
145 ),
146 })
147}
148
149// CloseAndLogIfError Closes io.Closer and logs the error if any
150func CloseAndLogIfError(ctx context.Context, closer io.Closer, message string) {

Callers 2

SetupHookLoggingFunction · 0.85
SetupHookLoggingFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected