aboutsummaryrefslogtreecommitdiff
path: root/opts/logs.go
blob: 9d568f7645460f8682e7bcde0822eae77eaa421f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2021 SNIX LLC sina@snix.ir
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// version 2 as published by the Free Software Foundation.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

package opts

import (
	"log"
	"os"
)

// logging format: prefix after date and time, seems to be fine for me
const logform = log.LstdFlags | log.Lmsgprefix

type loggersrv struct {
	tcplog, conlog *log.Logger
	sysplg, osexit *log.Logger
	config, mysqld *log.Logger
	apisrv         *log.Logger
}

func newLogger() *loggersrv {
	lg := new(loggersrv)
	lg.tcplog = log.New(os.Stdout, "NETLOG:\x20", logform)
	lg.conlog = log.New(os.Stdout, "CONNEC:\x20", logform)
	lg.sysplg = log.New(os.Stdout, "SYSLOG:\x20", logform)
	lg.osexit = log.New(os.Stdout, "OSEXIT:\x20", logform)
	lg.config = log.New(os.Stdout, "CONFIG:\x20", logform)
	lg.mysqld = log.New(os.Stdout, "MYSQLD:\x20", logform)
	lg.apisrv = log.New(os.Stdout, "APISRV:\x20", logform)
	return lg
}

var (
	TLSLOG func(...interface{}) // TLSLOG logs tls server stuff
	SYSLOG func(...interface{})
	OSEXIT func(...interface{}) // EXIT APP
	CONFIG func(...interface{})
	MYSQLD func(...interface{})
	MYSQLO func(...interface{}) // Mysql info
	APISRV func(...interface{})
	APIERR func(...interface{})
        // Debug functions, no-op func non-nil
	APIDBG = func(...interface{}){}
        CONNEC = func(...interface{}){}
)

func (lg *loggersrv) initOptsLogs() {
	// new loggers for server handlers, with custom prefix
	TLSLOG = func(l ...interface{}) { lg.tcplog.Println(l...) }
	SYSLOG = func(l ...interface{}) { lg.sysplg.Println(l...) }
	OSEXIT = func(l ...interface{}) { lg.osexit.Fatalln(l...) }
	CONFIG = func(l ...interface{}) { lg.config.Fatalln(l...) }
	MYSQLD = func(l ...interface{}) { lg.mysqld.Fatalln(l...) }
	MYSQLO = func(l ...interface{}) { lg.mysqld.Println(l...) }
	APIERR = func(l ...interface{}) { lg.apisrv.Fatalln(l...) }
	APISRV = func(l ...interface{}) { lg.apisrv.Println(l...) }
}

func (lg *loggersrv) debugging() {
	// do something if debug is true, default is not true
	CONNEC = func(l ...interface{}) { lg.conlog.Println(l...) }
	APIDBG = func(l ...interface{}) { lg.apisrv.Println(l...) }

}

Snix LLC Git Repository Holder Copyright(C) 2022 All Rights Reserved Email To Snix.IR