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.

Revisions

  1. border revised this gist Aug 30, 2012. 2 changed files with 24 additions and 18 deletions.
    21 changes: 3 additions & 18 deletions log.go
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,12 @@
    package main
    package utils

    import (
    "flag"
    "log"
    "os"
    "time"
    )

    var (
    lg *log.Logger
    logpath = flag.String("logpath", "/tmp/weather.log", "Log Path")
    Log *log.Logger
    )

    func NewLog(logpath string) {
    @@ -18,17 +15,5 @@ func NewLog(logpath string) {
    if err != nil {
    panic(err)
    }
    lg = log.New(file, "", log.LstdFlags|log.Lshortfile)
    Log = log.New(file, "", log.LstdFlags|log.Lshortfile)
    }

    func main() {
    flag.Parse()
    NewLog(*logpath)
    go func() {
    lg.Println("hello")
    for i := 0; i < 10; i++ {
    lg.Println(i)
    }
    }()
    time.Sleep(3 * time.Second)
    }
    21 changes: 21 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    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)
    }
  2. border renamed this gist Aug 30, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. border created this gist Aug 30, 2012.
    34 changes: 34 additions & 0 deletions log.log
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    package main

    import (
    "flag"
    "log"
    "os"
    "time"
    )

    var (
    lg *log.Logger
    logpath = flag.String("logpath", "/tmp/weather.log", "Log Path")
    )

    func NewLog(logpath string) {
    println("LogFile: " + logpath)
    file, err := os.Create(logpath)
    if err != nil {
    panic(err)
    }
    lg = log.New(file, "", log.LstdFlags|log.Lshortfile)
    }

    func main() {
    flag.Parse()
    NewLog(*logpath)
    go func() {
    lg.Println("hello")
    for i := 0; i < 10; i++ {
    lg.Println(i)
    }
    }()
    time.Sleep(3 * time.Second)
    }