Debian Codegraph @

mauview-test/debug/debug.go

raw symbols SCIP
1 // gomuks - A terminal Matrix client written in Go.
2 // Copyright (C) 2018 Tulir Asokan
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 package debug
18
19 import (
20 "fmt"
21 "io"
22 "os"
23 "runtime/debug"
24 "time"
25 )
26
27 var writer io.Writer
28
29 func init() {
30 var err error
31 writer, err = os.OpenFile("/tmp/mauview-debug.log", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
32 if err != nil {
33 panic(err)
34 }
35 }
36
37 func Printf(text string, args ...interface{}) {
38 if writer != nil {
39 fmt.Fprintf(writer, time.Now().Format("[2006-01-02 15:04:05] "))
40 fmt.Fprintf(writer, text+"\n", args...)
41 }
42 }
43
44 func Print(text ...interface{}) {
45 if writer != nil {
46 fmt.Fprintf(writer, time.Now().Format("[2006-01-02 15:04:05] "))
47 fmt.Fprintln(writer, text...)
48 }
49 }
50
51 func PrintStack() {
52 if writer != nil {
53 data := debug.Stack()
54 writer.Write(data)
55 }
56 }