Logging to a file - append



examples/logging-to-file-append/logging_to_file_append.go
package main

import (
    "log"
    "os"
)

func main() {
    var filename = "logging_to_file_append.log"
    var fh, err = os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
    if err != nil {
        log.Fatalf("Could not open file '%v': %v", filename, err)
    }
    log.SetOutput(fh)

    log.Print("Hello logfile")
    log.Fatal("This is bad")
}

examples/logging-to-file-append/logging_to_file_append.log
2020/04/10 09:20:00 Hello logfile
2020/04/10 09:20:00 This is bad
2020/04/10 09:20:07 Hello logfile
2020/04/10 09:20:07 This is bad