1
0
Fork 0

Allow access and error logging to stdout by configuring a path of "-".

Thanks to @icedquinn@blob.cat for the suggestion.
This commit is contained in:
Solderpunk 2021-01-24 17:09:47 +01:00
parent e06f8bddbc
commit 92cd40db12
2 changed files with 23 additions and 11 deletions

View file

@ -198,10 +198,12 @@ examples of the appropriate syntax.
`/var/gemini/users/gus/` to `/home/gus/public_gemini/` if you want.
* `AccessLog`: Path to access log file (default value `access.log`,
i.e. in the current wrorking directory). Note that all intermediate
directories must exist, Molly Brown won't create them for you.
directories must exist, Molly Brown won't create them for you. Set
to `-` for logging to `stdout`.
* `ErrorLog`: Path to error log file (default value `error.log`, i.e.
in the current wrorking directory). Note that all intermediate
directories must exist, Molly Brown won't create them for you.
directories must exist, Molly Brown won't create them for you. Set
to `-` for logging to `stdout`.
* `GeminiExt`: Files with this extension will be served with a MIME
type of `text/gemini` (default value `gmi`).
* `MimeOverrides`: In this section of the config file, keys are path

28
main.go
View file

@ -26,19 +26,29 @@ func main() {
}
// Open log files
errorLogFile, err := os.OpenFile(config.ErrorLog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
var errorLogFile *os.File
if config.ErrorLog == "-" {
errorLogFile = os.Stdout
} else {
errorLogFile, err = os.OpenFile(config.ErrorLog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal(err)
}
defer errorLogFile.Close()
}
defer errorLogFile.Close()
errorLog := log.New(errorLogFile, "", log.Ldate | log.Ltime)
accessLogFile, err := os.OpenFile(config.AccessLog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
errorLog.Println("Error opening access log file: " + err.Error())
log.Fatal(err)
var accessLogFile *os.File
if config.AccessLog == "-" {
accessLogFile = os.Stdout
} else {
accessLogFile, err = os.OpenFile(config.AccessLog, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
errorLog.Println("Error opening access log file: " + err.Error())
log.Fatal(err)
}
defer accessLogFile.Close()
}
defer accessLogFile.Close()
// Read TLS files, create TLS config
cert, err := tls.LoadX509KeyPair(config.CertPath, config.KeyPath)