github.com/developest/gtm-core@v1.0.4-0.20220111132249-cc80a3372c3f/util/debug_on.go (about) 1 // +build debug 2 3 // Copyright 2016 Michael Schenk. All rights reserved. 4 // Use of this source code is governed by a MIT-style 5 // license that can be found in the LICENSE file. 6 7 package util 8 9 import ( 10 "io/ioutil" 11 "log" 12 "os" 13 "os/user" 14 "path/filepath" 15 ) 16 17 // Debug is a debug logger 18 var Debug = NewContextLogger(log.New(ioutil.Discard, "debug ", log.Lmicroseconds), 3) 19 20 func init() { 21 u, err := user.Current() 22 if err != nil { 23 return 24 } 25 26 w, err := os.OpenFile(filepath.Join(u.HomeDir, "gtm-debug.log"), os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644) 27 if err != nil { 28 return 29 } 30 31 Debug = NewContextLogger(log.New(w, "debug ", log.Lmicroseconds), 3) 32 }