Skip to content

Instantly share code, notes, and snippets.

@apokalyptik apokalyptik/ts.go
Last active Sep 11, 2015

Embed
What would you like to do?
Stupid simple program to add timestampt to a programs output...
package main
import (
"bufio"
"io"
"log"
"os"
)
func main() {
log.SetOutput(os.Stdout)
log.SetFlags(log.Ldate | log.Lmicroseconds)
stdin := bufio.NewReader(os.Stdin)
for {
if line, err := stdin.ReadString('\n'); err == nil {
log.Print(line)
} else {
if line != "" {
log.Print(line)
}
if err != io.EOF {
log.Fatal(err)
}
return
}
}
}
@apokalyptik

This comment has been minimized.

Copy link
Owner Author

commented Sep 10, 2015

$ go build ts.go && cat ts.go | ./ts
2015/09/11 18:56:31.144857 package main
2015/09/11 18:56:31.145169
2015/09/11 18:56:31.145186 import (
2015/09/11 18:56:31.145200  "bufio"
2015/09/11 18:56:31.145217  "io"
2015/09/11 18:56:31.145232  "log"
2015/09/11 18:56:31.145247  "os"
2015/09/11 18:56:31.145264 )
2015/09/11 18:56:31.145280
2015/09/11 18:56:31.145296 func main() {
2015/09/11 18:56:31.145311  log.SetOutput(os.Stdout)
2015/09/11 18:56:31.145327  log.SetFlags(log.Ldate | log.Lmicroseconds)
2015/09/11 18:56:31.145346  stdin := bufio.NewReader(os.Stdin)
2015/09/11 18:56:31.145362  for {
2015/09/11 18:56:31.145378      if line, err := stdin.ReadString('\n'); err == nil {
2015/09/11 18:56:31.145396          log.Print(line)
2015/09/11 18:56:31.145413      } else {
2015/09/11 18:56:31.145429          if line != "" {
2015/09/11 18:56:31.145448              log.Print(line)
2015/09/11 18:56:31.145465          }
2015/09/11 18:56:31.145483          if err != io.EOF {
2015/09/11 18:56:31.145502              log.Fatal(err)
2015/09/11 18:56:31.145523          }
2015/09/11 18:56:31.145542          return
2015/09/11 18:56:31.145560      }
2015/09/11 18:56:31.145578  }
2015/09/11 18:56:31.145595 }
$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.