Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@apokalyptik
Last active September 11, 2015 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apokalyptik/a208f32552a5a54cff5b to your computer and use it in GitHub Desktop.
Save apokalyptik/a208f32552a5a54cff5b to your computer and use it in GitHub Desktop.
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
Copy link
Author

$ 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