Skip to content

Instantly share code, notes, and snippets.

@border
Created August 30, 2012 10:04
Show Gist options
  • Save border/3525344 to your computer and use it in GitHub Desktop.
Save border/3525344 to your computer and use it in GitHub Desktop.
Log Example For Go
package utils
import (
"log"
"os"
)
var (
Log *log.Logger
)
func NewLog(logpath string) {
println("LogFile: " + logpath)
file, err := os.Create(logpath)
if err != nil {
panic(err)
}
Log = log.New(file, "", log.LstdFlags|log.Lshortfile)
}
package main
import (
"./utils"
"flag"
"time"
)
var (
logpath = flag.String("logpath", "/tmp/weather.log", "Log Path")
)
func main() {
flag.Parse()
utils.NewLog(*logpath)
utils.Log.Println("hello")
for i := 0; i < 10; i++ {
utils.Log.Println(i)
}
time.Sleep(3 * time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment