Added functions to logging library

Added Logf() and WithFields() functions.
Logf() for logging formatted messages.
WithFields() for handling optional log fields.
This commit is contained in:
balandi1 2019-12-04 13:16:48 -05:00
parent b9592ed31c
commit bedfa52d7a
18 changed files with 319 additions and 260 deletions

View file

@ -47,9 +47,7 @@ func Start(quit chan struct{}, logging *bool, pcpConfigFile string) {
scanner.Scan()
// Write to logfile
elekLog.ElektronLogger.Log(elekLogTypes.PCP,
log.InfoLevel,
log.Fields{}, scanner.Text())
elekLog.ElektronLogger.Log(elekLogTypes.PCP, log.InfoLevel, scanner.Text())
// Throw away first set of results
scanner.Scan()
@ -60,18 +58,14 @@ func Start(quit chan struct{}, logging *bool, pcpConfigFile string) {
text := scanner.Text()
if *logging {
elekLog.ElektronLogger.Log(elekLogTypes.PCP,
log.InfoLevel,
log.Fields{}, text)
elekLog.ElektronLogger.Log(elekLogTypes.PCP, log.InfoLevel, text)
}
seconds++
}
}(logging)
elekLog.ElektronLogger.Log(elekLogTypes.CONSOLE,
log.InfoLevel,
log.Fields{}, "PCP logging started")
elekLog.ElektronLogger.Log(elekLogTypes.CONSOLE, log.InfoLevel, "PCP logging started")
if err := cmd.Start(); err != nil {
log.Fatal(err)
@ -81,9 +75,7 @@ func Start(quit chan struct{}, logging *bool, pcpConfigFile string) {
select {
case <-quit:
elekLog.ElektronLogger.Log(elekLogTypes.CONSOLE,
log.InfoLevel,
log.Fields{}, "Stopping PCP logging in 5 seconds")
elekLog.ElektronLogger.Log(elekLogTypes.CONSOLE, log.InfoLevel, "Stopping PCP logging in 5 seconds")
time.Sleep(5 * time.Second)
// http://stackoverflow.com/questions/22470193/why-wont-go-kill-a-child-process-correctly