mirror of
https://github.com/ollama/ollama.git
synced 2025-05-11 18:36:41 +02:00
Merge 93f3048104
into 3fa78598a1
This commit is contained in:
commit
dd4f8474f0
2 changed files with 35 additions and 12 deletions
|
@ -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.
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue