Skip to content

Instantly share code, notes, and snippets.

@bcho
Created June 21, 2015 12:09
Show Gist options
  • Select an option

  • Save bcho/ef5f3f08d05447c54e50 to your computer and use it in GitHub Desktop.

Select an option

Save bcho/ef5f3f08d05447c54e50 to your computer and use it in GitHub Desktop.
package main
import (
"flag"
"log"
"math/rand"
"os"
"time"
)
var logFile string
var poems = []string{
"FROM far, from eve and morning",
"And yon twelve-winded sky",
"The stuff of life to knit me",
"Blew hither: here am I.",
"Now—for a breath I tarry",
"Nor yet disperse apart—",
"Take my hand quick and tell me",
"What have you in your heart.",
"Speak now, and I will answer",
"How shall I help you, say",
"Ere to the wind’s twelve quarters",
"I take my endless way.",
}
func line() string {
return poems[rand.Intn(len(poems))]
}
func main() {
flag.Parse()
logWriter, err := os.OpenFile(
logFile,
os.O_RDWR|os.O_CREATE|os.O_APPEND,
0666,
)
if err != nil {
log.Fatal(err)
}
defer logWriter.Close()
log.SetOutput(logWriter)
log.SetFlags(log.LstdFlags | log.Lshortfile)
c := time.Tick(1 * time.Second)
for range c {
log.Printf(line())
}
}
func init() {
flag.StringVar(&logFile, "log-file", "poem.log", "log file")
rand.Seed(time.Now().Unix())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment