@@ -28,21 +28,15 @@ import (
2828)
2929
3030func main () {
31- ctx := context .Background ()
32-
3331 var opts struct {
3432 ProjectID string `short:"p" long:"project" description:"Google Cloud Platform Project ID" required:"true"`
3533 LogName string `short:"l" long:"logname" description:"The name of the log to write to" default:"default"`
3634 }
37-
3835 _ , err := flags .Parse (& opts )
3936 if err != nil {
4037 os .Exit (2 )
4138 }
4239
43- projectID := & opts .ProjectID
44- logName := & opts .LogName
45-
4640 // Check if Standard In is coming from a pipe
4741 fi , err := os .Stdin .Stat ()
4842 if err != nil {
@@ -53,13 +47,14 @@ func main() {
5347 }
5448
5549 // Creates a client.
56- client , err := logging .NewClient (ctx , * projectID )
50+ ctx := context .Background ()
51+ client , err := logging .NewClient (ctx , opts .ProjectID )
5752 if err != nil {
5853 errorf ("Failed to create client: %v" , err )
5954 }
6055
6156 // Selects the log to write to.
62- logger := client .Logger (* logName )
57+ logger := client .Logger (opts . LogName )
6358
6459 // Read from Stdin and log it to Stdout and Stackdriver
6560 s := bufio .NewScanner (os .Stdin )
@@ -74,7 +69,6 @@ func main() {
7469 if err := client .Close (); err != nil {
7570 errorf ("Failed to close client: %v" , err )
7671 }
77-
7872 if err := s .Err (); err != nil {
7973 errorf ("Failed to scan input: %v" , err )
8074 }
0 commit comments