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

6 Commits

Author SHA1 Message Date
147a8cb30b Merge pull request #10 from ethanholz/README
Added a README
2022-10-10 13:38:59 -07:00
Ethan Holz
8e044e3993 docs: Updated README to include running example. 2022-10-10 12:16:52 -05:00
Ethan Holz
e97d37012e docs: Added inital README 2022-10-10 12:09:29 -05:00
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
3 changed files with 52 additions and 32 deletions

15
README.md Normal file
View File

@@ -0,0 +1,15 @@
log-socket
==========
`log-socket` is a drop-in replacement for Go's `log` package that allows for streaming of logs via WebSockets.
## Installation
To install the library:
`go get github.com/taigrr/log-socket`
## Running
To run a demo of this library:
`go run main.go`
This demo will do a sample of every log type and push results to `0.0.0.0:8080`. Once running, you can open a browser and navigate to
`0.0.0.0:8080` to see an example implementation of how logs are streamed.

View File

@@ -7,13 +7,17 @@ import (
"time"
)
func (l *Logger) SetInfoDepth(depth int) {
l.FileInfoDepth = depth
}
// Trace prints out logs on trace level
func (_ Logger) Trace(args ...interface{}) {
func (l Logger) Trace(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "TRACE",
level: LTrace,
}
@@ -21,12 +25,12 @@ func (_ Logger) Trace(args ...interface{}) {
}
// Formatted print for Trace
func (_ Logger) Tracef(format string, args ...interface{}) {
func (l Logger) Tracef(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "TRACE",
level: LTrace,
}
@@ -34,12 +38,12 @@ func (_ Logger) Tracef(format string, args ...interface{}) {
}
// Debug prints out logs on debug level
func (_ Logger) Debug(args ...interface{}) {
func (l Logger) Debug(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "DEBUG",
level: LDebug,
}
@@ -47,12 +51,12 @@ func (_ Logger) Debug(args ...interface{}) {
}
// Formatted print for Debug
func (_ Logger) Debugf(format string, args ...interface{}) {
func (l Logger) Debugf(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "DEBUG",
level: LDebug,
}
@@ -60,12 +64,12 @@ func (_ Logger) Debugf(format string, args ...interface{}) {
}
// Info prints out logs on info level
func (_ Logger) Info(args ...interface{}) {
func (l Logger) Info(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "INFO",
level: LInfo,
}
@@ -73,12 +77,12 @@ func (_ Logger) Info(args ...interface{}) {
}
// Formatted print for Info
func (_ Logger) Infof(format string, args ...interface{}) {
func (l Logger) Infof(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "INFO",
level: LInfo,
}
@@ -86,12 +90,12 @@ func (_ Logger) Infof(format string, args ...interface{}) {
}
// Info prints out logs on info level
func (_ Logger) Notice(args ...interface{}) {
func (l Logger) Notice(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "NOTICE",
level: LNotice,
}
@@ -99,12 +103,12 @@ func (_ Logger) Notice(args ...interface{}) {
}
// Formatted print for Info
func (_ Logger) Noticef(format string, args ...interface{}) {
func (l Logger) Noticef(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "NOTICE",
level: LNotice,
}
@@ -112,12 +116,12 @@ func (_ Logger) Noticef(format string, args ...interface{}) {
}
// Warn prints out logs on warn level
func (_ Logger) Warn(args ...interface{}) {
func (l Logger) Warn(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "WARN",
level: LWarn,
}
@@ -125,12 +129,12 @@ func (_ Logger) Warn(args ...interface{}) {
}
// Formatted print for Warn
func (_ Logger) Warnf(format string, args ...interface{}) {
func (l Logger) Warnf(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "WARN",
level: LWarn,
}
@@ -138,12 +142,12 @@ func (_ Logger) Warnf(format string, args ...interface{}) {
}
// Error prints out logs on error level
func (_ Logger) Error(args ...interface{}) {
func (l Logger) Error(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "ERROR",
level: LError,
}
@@ -151,12 +155,12 @@ func (_ Logger) Error(args ...interface{}) {
}
// Formatted print for error
func (_ Logger) Errorf(format string, args ...interface{}) {
func (l Logger) Errorf(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "ERROR",
level: LError,
}
@@ -164,12 +168,12 @@ func (_ Logger) Errorf(format string, args ...interface{}) {
}
// Panic prints out logs on panic level
func (_ Logger) Panic(args ...interface{}) {
func (l Logger) Panic(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "PANIC",
level: LPanic,
}
@@ -187,12 +191,12 @@ func (_ Logger) Panic(args ...interface{}) {
}
// Formatted print for panic
func (_ Logger) Panicf(format string, args ...interface{}) {
func (l Logger) Panicf(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "PANIC",
level: LPanic,
}
@@ -210,12 +214,12 @@ func (_ Logger) Panicf(format string, args ...interface{}) {
}
// Fatal prints out logs on fatal level
func (_ Logger) Fatal(args ...interface{}) {
func (l Logger) Fatal(args ...interface{}) {
output := fmt.Sprint(args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "FATAL",
level: LFatal,
}
@@ -225,12 +229,12 @@ func (_ Logger) Fatal(args ...interface{}) {
}
// Formatted print for fatal
func (_ Logger) Fatalf(format string, args ...interface{}) {
func (l Logger) Fatalf(format string, args ...interface{}) {
output := fmt.Sprintf(format, args...)
e := Entry{
Timestamp: time.Now(),
Output: output,
File: fileInfo(2),
File: fileInfo(l.FileInfoDepth),
Level: "FATAL",
level: LFatal,
}

View File

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