diff --git a/README.md b/README.md index fcffc8a..ce4ba02 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/main.go b/main.go index 7f4d48f..a616351 100644 --- a/main.go +++ b/main.go @@ -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)