Created
August 30, 2012 10:04
-
-
Save border/3525344 to your computer and use it in GitHub Desktop.
Log Example For Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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