mirror of
https://github.com/taigrr/log-socket
synced 2025-01-18 04:53:14 -08:00
Compare commits
No commits in common. "ebef59a9a8246026a82674e0603da9a5b8b82c63" and "d21c91379ea3b7ff7b091e1511e9a4da217812ec" have entirely different histories.
ebef59a9a8
...
d21c91379e
244
log/logger.go
244
log/logger.go
@ -1,244 +0,0 @@
|
|||||||
package log
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (l *Logger) SetInfoDepth(depth int) {
|
|
||||||
l.FileInfoDepth = depth
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trace prints out logs on trace level
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Formatted print for Trace
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debug prints out logs on debug level
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Formatted print for Debug
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info prints out logs on info level
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Formatted print for Info
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info prints out logs on info level
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Formatted print for Info
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warn prints out logs on warn level
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Formatted print for Warn
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Error prints out logs on error level
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Formatted print for error
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Panic prints out logs on panic level
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Formatted print for panic
|
|
||||||
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)
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package log
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
@ -199,32 +199,6 @@ func Infof(format string, args ...interface{}) {
|
|||||||
createLog(e)
|
createLog(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info prints out logs on info level
|
|
||||||
func Notice(args ...interface{}) {
|
|
||||||
output := fmt.Sprint(args...)
|
|
||||||
e := Entry{
|
|
||||||
Timestamp: time.Now(),
|
|
||||||
Output: output,
|
|
||||||
File: fileInfo(2),
|
|
||||||
Level: "NOTICE",
|
|
||||||
level: LNotice,
|
|
||||||
}
|
|
||||||
createLog(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Formatted print for Info
|
|
||||||
func Noticef(format string, args ...interface{}) {
|
|
||||||
output := fmt.Sprintf(format, args...)
|
|
||||||
e := Entry{
|
|
||||||
Timestamp: time.Now(),
|
|
||||||
Output: output,
|
|
||||||
File: fileInfo(2),
|
|
||||||
Level: "NOTICE",
|
|
||||||
level: LNotice,
|
|
||||||
}
|
|
||||||
createLog(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Warn prints out logs on warn level
|
// Warn prints out logs on warn level
|
||||||
func Warn(args ...interface{}) {
|
func Warn(args ...interface{}) {
|
||||||
output := fmt.Sprint(args...)
|
output := fmt.Sprint(args...)
|
@ -1,4 +1,4 @@
|
|||||||
package log
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
@ -1,4 +1,4 @@
|
|||||||
package log
|
package logger
|
||||||
|
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
@ -9,7 +9,6 @@ const (
|
|||||||
LTrace Level = iota
|
LTrace Level = iota
|
||||||
LDebug
|
LDebug
|
||||||
LInfo
|
LInfo
|
||||||
LNotice
|
|
||||||
LWarn
|
LWarn
|
||||||
LError
|
LError
|
||||||
LPanic
|
LPanic
|
||||||
@ -29,7 +28,3 @@ type Entry struct {
|
|||||||
Level string `json:"level"`
|
Level string `json:"level"`
|
||||||
level Level
|
level Level
|
||||||
}
|
}
|
||||||
|
|
||||||
type Logger struct {
|
|
||||||
FileInfoDepth int
|
|
||||||
}
|
|
2
main.go
2
main.go
@ -6,7 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/taigrr/log-socket/browser"
|
"github.com/taigrr/log-socket/browser"
|
||||||
logger "github.com/taigrr/log-socket/log"
|
"github.com/taigrr/log-socket/logger"
|
||||||
"github.com/taigrr/log-socket/ws"
|
"github.com/taigrr/log-socket/ws"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
logger "github.com/taigrr/log-socket/log"
|
"github.com/taigrr/log-socket/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
// var addr = flag.String("addr", "localhost:8080", "http service address")
|
// var addr = flag.String("addr", "localhost:8080", "http service address")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user