feat: initial commit
This commit is contained in:
commit
693724d3b8
7 changed files with 116 additions and 0 deletions
21
cmd/logger/debug.go
Normal file
21
cmd/logger/debug.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log"
|
||||
)
|
||||
|
||||
var debug bool
|
||||
|
||||
// Enables debug logging if set to true. Default is false.
|
||||
func SetDebug(debugSetting bool) {
|
||||
debug = debugSetting
|
||||
if !debug {
|
||||
log.SetOutput(io.Discard)
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the current debug value as a boolean.
|
||||
func GetDebug() bool {
|
||||
return debug
|
||||
}
|
||||
25
cmd/logger/logging.go
Normal file
25
cmd/logger/logging.go
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
package logging
|
||||
|
||||
import (
|
||||
"log"
|
||||
)
|
||||
|
||||
// Prints the formatted log, taking both a message (string) and optionally
|
||||
// an error as inputs.
|
||||
func Print(message string, err error) {
|
||||
if debug {
|
||||
log.Printf(applicationName+" | LOG: %v\n", message)
|
||||
if err != nil {
|
||||
log.Printf(applicationName+" | ERROR: %v\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Prints the fatal error and exits the application. Takes both the message and
|
||||
// optionally an error as inputs.
|
||||
func Fatal(message string, err error) {
|
||||
log.Fatalf(applicationName+" | FATAL: %v\n", message)
|
||||
if err != nil {
|
||||
log.Fatalf(applicationName+" | ERROR: %v\n", err)
|
||||
}
|
||||
}
|
||||
14
cmd/logger/prefix.go
Normal file
14
cmd/logger/prefix.go
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package logging
|
||||
|
||||
var applicationName = "MyApp"
|
||||
|
||||
// Sets the application name prefix used in the logoutput. Example:
|
||||
// <applicationName> | ...
|
||||
func SetAppName(name string) {
|
||||
applicationName = name
|
||||
}
|
||||
|
||||
// Returns the logging prefix name as string.
|
||||
func GetAppName() string {
|
||||
return applicationName
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue