github.com/blend/go-sdk@v1.20220411.3/examples/db/prevent-deadlock/log.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package main
     9  
    10  import (
    11  	"fmt"
    12  	"time"
    13  )
    14  
    15  type logWriter struct {
    16  	Start time.Time
    17  }
    18  
    19  func (lw logWriter) Write(bytes []byte) (int, error) {
    20  	d := time.Since(lw.Start)
    21  	s := float64(d) / float64(time.Second)
    22  	return fmt.Printf("%f %s", s, string(bytes))
    23  }
    24  
    25  func newLogWriter() logWriter {
    26  	return logWriter{Start: time.Now().UTC()}
    27  }