Skip to content

Instantly share code, notes, and snippets.

@dfer
Created July 3, 2015 09:16
Show Gist options
  • Select an option

  • Save dfer/8fec6a5548b27d8767d7 to your computer and use it in GitHub Desktop.

Select an option

Save dfer/8fec6a5548b27d8767d7 to your computer and use it in GitHub Desktop.
Example with log to file
package main
import (
"log"
"os"
)
var Error *log.Logger
var Info *log.Logger
func init() {
file, err := os.OpenFile("log.txt", os.O_APPEND | os.O_CREATE | os.O_RDWR, 0666)
if err != nil {
log.Fatalf("Failed to open log file: %v", err)
}
//defer file.Close()
//Error = log.New(file, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
Info = log.New(file, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
//logger = log.New(os.Stdout, "Info: ", log.Ldate|log.Ltime|log.Lshortfile)
}
func log_error(err interface{}) {
Error.Printf("%s\n", err)
}
func log_info(text string){
Info.Printf("Value is %s \n", text)
}
func main() {
log_info("Some text")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment