How to write log to file

后端 未结 11 1298
抹茶落季
抹茶落季 2020-12-07 08:06

I\'m trying to write to a log file with Go.

I have tried several approaches, all of which have failed. This is what I have tried:

func TestLogging(t          


        
11条回答
  •  心在旅途
    2020-12-07 08:47

    Declare up top in your global var so all your processes can access if needed.

    package main
    
    import (
        "log"
        "os"
    )
    var (
        outfile, _ = os.Create("path/to/my.log") // update path for your needs
        l      = log.New(outfile, "", 0)
    )
    
    func main() {
        l.Println("hello, log!!!")
    }
    

提交回复
热议问题