github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/updater/service/logger.go (about) 1 // Copyright 2016 Keybase, Inc. All rights reserved. Use of 2 // this source code is governed by the included BSD license. 3 4 package main 5 6 import ( 7 "fmt" 8 "log" 9 "os" 10 "path/filepath" 11 12 "github.com/keybase/client/go/updater/keybase" 13 ) 14 15 type logger struct{} 16 17 // Debug is log implementation 18 func (l logger) Debug(s ...interface{}) { 19 log.Printf("DEBG %s\n", s) 20 } 21 22 // Info is log implementation 23 func (l logger) Info(s ...interface{}) { 24 log.Printf("INFO %s\n", s) 25 } 26 27 // Debugf is log implementation 28 func (l logger) Debugf(s string, args ...interface{}) { 29 log.Printf("DEBG %s\n", fmt.Sprintf(s, args...)) 30 } 31 32 // Infof is log implementation 33 func (l logger) Infof(s string, args ...interface{}) { 34 log.Printf("INFO %s\n", fmt.Sprintf(s, args...)) 35 } 36 37 // Warning is log implementation 38 func (l logger) Warning(s ...interface{}) { 39 log.Printf("WARN %s\n", s) 40 } 41 42 // Warningf is log implementation 43 func (l logger) Warningf(s string, args ...interface{}) { 44 log.Printf("WARN %s\n", fmt.Sprintf(s, args...)) 45 } 46 47 // Error is log implementation 48 func (l logger) Error(s ...interface{}) { 49 log.Printf("ERR %s\n", s) 50 } 51 52 // Errorf is log implementation 53 func (l logger) Errorf(s string, args ...interface{}) { 54 log.Printf("ERR %s\n", fmt.Sprintf(s, args...)) 55 } 56 57 func (l logger) setLogToFile(appName string, fileName string) (*os.File, string, error) { 58 dir, err := keybase.LogDir(appName) 59 if err != nil { 60 return nil, "", err 61 } 62 logPath := filepath.Join(dir, fileName) 63 logFile, err := os.OpenFile(logPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600) 64 if err != nil { 65 return nil, "", err 66 } 67 log.Printf("Logging to %s", logPath) 68 log.SetOutput(logFile) 69 return logFile, logPath, nil 70 }