golang.org/x/playground@v0.0.0-20230418134305-14ebe15bcd59/logger.go (about)

     1  // Copyright 2017 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	stdlog "log"
     9  	"os"
    10  )
    11  
    12  type logger interface {
    13  	Printf(format string, args ...interface{})
    14  	Errorf(format string, args ...interface{})
    15  	Fatalf(format string, args ...interface{})
    16  }
    17  
    18  // stdLogger implements the logger interface using the log package.
    19  // There is no need to specify a date/time prefix since stdout and stderr
    20  // are logged in StackDriver with those values already present.
    21  type stdLogger struct {
    22  	stderr *stdlog.Logger
    23  	stdout *stdlog.Logger
    24  }
    25  
    26  func newStdLogger() *stdLogger {
    27  	return &stdLogger{
    28  		stdout: stdlog.New(os.Stdout, "", 0),
    29  		stderr: stdlog.New(os.Stderr, "", 0),
    30  	}
    31  }
    32  
    33  func (l *stdLogger) Printf(format string, args ...interface{}) {
    34  	l.stdout.Printf(format, args...)
    35  }
    36  
    37  func (l *stdLogger) Errorf(format string, args ...interface{}) {
    38  	l.stderr.Printf(format, args...)
    39  }
    40  
    41  func (l *stdLogger) Fatalf(format string, args ...interface{}) {
    42  	l.stderr.Fatalf(format, args...)
    43  }