This commit is contained in:
Chris 2025-05-10 07:16:46 +02:00 committed by GitHub
commit dd4f8474f0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 12 deletions

View file

@ -94,6 +94,10 @@ func Models() string {
return filepath.Join(home, ".ollama", "models")
}
func LogFormatJSON() bool {
return os.Getenv("OLLAMA_LOG_FORMAT_JSON") == "true"
}
// KeepAlive returns the duration that models stay loaded in memory. KeepAlive can be configured via the OLLAMA_KEEP_ALIVE environment variable.
// Negative values are treated as infinite. Zero is treated as no keep alive.
// Default is 5 minutes.

View file

@ -1231,19 +1231,38 @@ func Serve(ln net.Listener) error {
level = slog.LevelDebug
}
slog.Info("server config", "env", envconfig.Values())
handler := slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
Level: level,
AddSource: true,
ReplaceAttr: func(_ []string, attr slog.Attr) slog.Attr {
if attr.Key == slog.SourceKey {
source := attr.Value.Any().(*slog.Source)
source.File = filepath.Base(source.File)
}
// Vérifier si le format JSON est activé via une variable d'environnement
jsonLogging := os.Getenv("OLLAMA_LOG_FORMAT_JSON") == "true"
return attr
},
})
var handler slog.Handler
if jsonLogging {
// Créer un handler JSON
handler = slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
Level: level,
AddSource: true,
ReplaceAttr: func(_ []string, attr slog.Attr) slog.Attr {
// Personnaliser la source du log pour n'avoir que le nom du fichier
if attr.Key == slog.SourceKey {
source := attr.Value.Any().(*slog.Source)
source.File = filepath.Base(source.File)
}
return attr
},
})
} else {
// Conserver le format texte existant
handler = slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{
Level: level,
AddSource: true,
ReplaceAttr: func(_ []string, attr slog.Attr) slog.Attr {
if attr.Key == slog.SourceKey {
source := attr.Value.Any().(*slog.Source)
source.File = filepath.Base(source.File)
}
return attr
},
})
}
slog.SetDefault(slog.New(handler))