Browse Source

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

Thanks to @icedquinn@blob.cat for the suggestion.
master
Solderpunk 9 months ago
parent
commit
92cd40db12
  1. 6
      README.md
  2. 28
      main.go

6
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

28
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)

Loading…
Cancel
Save