1
0
mirror of https://github.com/taigrr/log-socket synced 2025-01-18 04:53:14 -08:00

4 Commits

Author SHA1 Message Date
ebef59a9a8 actually set value for depth 2021-08-23 21:58:05 -07:00
b3ceb12277 fixes fileinfo reflection issue 2021-08-23 21:45:08 -07:00
45cad34fdc fixes fileinfo reflection issue 2021-08-23 21:44:56 -07:00
f0c16a0c56 fixes fileinfo reflection issue 2021-08-23 21:36:49 -07:00
2 changed files with 214 additions and 33 deletions

View File

@@ -1,64 +1,244 @@
package log package log
func (_ Logger) Trace(args ...interface{}) { import (
Trace(args...) "errors"
} "fmt"
func (_ Logger) Tracef(format string, args ...interface{}) { "os"
Tracef(format, args...) "time"
)
func (l *Logger) SetInfoDepth(depth int) {
l.FileInfoDepth = depth
} }
func (_ Logger) Debug(args ...interface{}) { // Trace prints out logs on trace level
Debug(args...) func (l Logger) Trace(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "TRACE",
level: LTrace,
}
createLog(e)
} }
func (_ Logger) Debugf(format string, args ...interface{}) { // Formatted print for Trace
Debugf(format, args...) func (l Logger) Tracef(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "TRACE",
level: LTrace,
}
createLog(e)
} }
func (_ Logger) Info(args ...interface{}) { // Debug prints out logs on debug level
Info(args...) func (l Logger) Debug(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "DEBUG",
level: LDebug,
}
createLog(e)
} }
func (_ Logger) Infof(format string, args ...interface{}) { // Formatted print for Debug
Infof(format, args...) func (l Logger) Debugf(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "DEBUG",
level: LDebug,
}
createLog(e)
} }
func (_ Logger) Notice(args ...interface{}) { // Info prints out logs on info level
Notice(args...) func (l Logger) Info(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "INFO",
level: LInfo,
}
createLog(e)
} }
func (_ Logger) Noticef(format string, args ...interface{}) { // Formatted print for Info
Noticef(format, args...) func (l Logger) Infof(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "INFO",
level: LInfo,
}
createLog(e)
} }
func (_ Logger) Warn(args ...interface{}) { // Info prints out logs on info level
Warn(args...) func (l Logger) Notice(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "NOTICE",
level: LNotice,
}
createLog(e)
} }
func (_ Logger) Warnf(format string, args ...interface{}) { // Formatted print for Info
Warnf(format, args...) func (l Logger) Noticef(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "NOTICE",
level: LNotice,
}
createLog(e)
} }
func (_ Logger) Error(args ...interface{}) { // Warn prints out logs on warn level
Error(args...) func (l Logger) Warn(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "WARN",
level: LWarn,
}
createLog(e)
} }
func (_ Logger) Errorf(format string, args ...interface{}) { // Formatted print for Warn
Errorf(format, args...) func (l Logger) Warnf(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "WARN",
level: LWarn,
}
createLog(e)
} }
func (_ Logger) Panic(args ...interface{}) { // Error prints out logs on error level
Panic(args...) func (l Logger) Error(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "ERROR",
level: LError,
}
createLog(e)
} }
func (_ Logger) Panicf(format string, args ...interface{}) { // Formatted print for error
Panicf(format, args...) func (l Logger) Errorf(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "ERROR",
level: LError,
}
createLog(e)
} }
func (_ Logger) Fatal(args ...interface{}) { // Panic prints out logs on panic level
Fatal(args...) func (l Logger) Panic(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "PANIC",
level: LPanic,
}
createLog(e)
if len(args) >= 0 {
switch args[0].(type) {
case error:
panic(args[0])
default:
// falls through to default below
}
}
Flush()
panic(errors.New(output))
} }
func (_ Logger) Fatalf(format string, args ...interface{}) { // Formatted print for panic
Fatalf(format, args...) func (l Logger) Panicf(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "PANIC",
level: LPanic,
}
createLog(e)
if len(args) >= 0 {
switch args[0].(type) {
case error:
panic(args[0])
default:
// falls through to default below
}
}
Flush()
panic(errors.New(output))
}
// Fatal prints out logs on fatal level
func (l Logger) Fatal(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "FATAL",
level: LFatal,
}
createLog(e)
Flush()
os.Exit(1)
}
// Formatted print for fatal
func (l Logger) Fatalf(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(l.FileInfoDepth),
Level: "FATAL",
level: LFatal,
}
createLog(e)
Flush()
os.Exit(1)
} }

View File

@@ -31,4 +31,5 @@ type Entry struct {
} }
type Logger struct { type Logger struct {
FileInfoDepth int
} }