Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes needed form original fork #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "ConsoleLogWriter_Manual",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceRoot}/examples/ConsoleLogWriter_Manual/ConsoleLogWriter_Manual.go",
},
{
"name": "FileLogWriter_Manual",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceRoot}/examples/FileLogWriter_Manual/FileLogWriter_Manual.go",
},
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package main

import (
"time"
)

import l4g "code.google.com/p/log4go"
l4g "github.com/wvkehoe/log4go"
)

func main() {
log := l4g.NewLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"io"
"os"
"time"
)

import l4g "code.google.com/p/log4go"
l4g "github.com/wvkehoe/log4go"
)

const (
filename = "flw.log"
Expand All @@ -19,17 +19,17 @@ func main() {
log := l4g.NewLogger()

// Create a default logger that is logging messages of FINE or higher
log.AddFilter("file", l4g.FINE, l4g.NewFileLogWriter(filename, false))
log.AddFilter("file", l4g.FINE, l4g.NewFileLogWriter(filename, false, false))
log.Close()

/* Can also specify manually via the following: (these are the defaults) */
flw := l4g.NewFileLogWriter(filename, false)
flw.SetFormat("[%D %T] [%L] (%S) %M")
flw := l4g.NewFileLogWriter(filename, false, false)
flw.SetFormat("[%D %T] [%L] (%C) (%S) %M")
flw.SetRotate(false)
flw.SetRotateSize(0)
flw.SetRotateLines(0)
flw.SetRotateDaily(false)
log.AddFilter("file", l4g.FINE, flw)
log.AddFilter("file", l4g.FINE, flw, "com.foobar")

// Log some experimental messages
log.Finest("Everything is created now (notice that I will not be printing to the file)")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
log "github.com/jeanphorn/log4go"
log "github.com/wvkehoe/log4go"
)

func main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"io"
"os"
"time"
)

import l4g "log4go"
l4g "github.com/wvkehoe/log4go"
)

const (
filename = "loginjection.log"
Expand Down Expand Up @@ -39,7 +39,7 @@ func main() {
log.AddFilter("file", l4g.FINE, flw)

// Log some experimental messages
for _,message := range(user_input) {
for _, message := range user_input {
log.Info(message)
}

Expand All @@ -51,7 +51,7 @@ func main() {
// Close the log
log.Close()

// Print what was logged to the file
// Print what was logged to the file
fd, err := os.Open(filename)
if err != nil {
fmt.Printf("Error reopening file: %s", filename)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package main

import (
"time"
)

import l4g "code.google.com/p/log4go"
l4g "github.com/wvkehoe/log4go"
)

func main() {
log := l4g.NewLogger()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
l4g "github.com/jeanphorn/log4go"
l4g "github.com/wvkehoe/log4go"
)

func main() {
Expand Down
1 change: 1 addition & 0 deletions examples/example.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

<logging>
<filter enabled="true">
<tag>stdout</tag>
Expand Down
9 changes: 5 additions & 4 deletions filelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ package log4go
import (
"fmt"
"os"
"time"
"strings"
"time"
)

// This log writer sends output to a file
Expand Down Expand Up @@ -41,7 +41,7 @@ type FileLogWriter struct {
maxbackup int

// Sanitize newlines to prevent log injection
sanitize bool
sanitize bool
}

// This is the FileLogWriter's output method
Expand All @@ -52,6 +52,7 @@ func (w *FileLogWriter) LogWrite(rec *LogRecord) {
func (w *FileLogWriter) Close() {
close(w.rec)
w.file.Sync()
w.file.Close()
}

// NewFileLogWriter creates a new LogWriter which writes to the given file and
Expand Down Expand Up @@ -169,7 +170,7 @@ func (w *FileLogWriter) intRotate() error {
// Rename the file to its newfound home
err = os.Rename(w.filename, fname)
if err != nil {
return fmt.Errorf("Rotate: %s\n", err)
return fmt.Errorf("Rotate: %s", err)
}
} else if !w.daily {
num = w.maxbackup - 1
Expand All @@ -186,7 +187,7 @@ func (w *FileLogWriter) intRotate() error {
err = os.Rename(w.filename, fname)
// return error if the last file checked still existed
if err != nil {
return fmt.Errorf("Rotate: %s\n", err)
return fmt.Errorf("Rotate: %s", err)
}
}

Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/wvkehoe/log4go

go 1.18

require github.com/toolkits/file v0.0.0-20160325033739-a5b3c5147e07
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github.com/toolkits/file v0.0.0-20160325033739-a5b3c5147e07 h1:d/VUIMNTk65Xz69htmRPNfjypq2uNRqVsymcXQu6kKk=
github.com/toolkits/file v0.0.0-20160325033739-a5b3c5147e07/go.mod h1:FbXpUxsx5in7z/OrWFDdhYetOy3/VGIJsVHN9G7RUPA=
2 changes: 1 addition & 1 deletion jsonconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (log Logger) LoadJsonConfiguration(filename string) {
os.Exit(1)
}
} else {
content = string(dst.Bytes())
content = dst.String()
}

err = json.Unmarshal([]byte(content), &lc)
Expand Down
49 changes: 27 additions & 22 deletions log4go.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,21 @@ func (log Logger) intLogf(lvl Level, format string, args ...interface{}) {
msg = fmt.Sprintf(format, args...)
}

// Make the log record
rec := &LogRecord{
Level: lvl,
Created: time.Now(),
Source: src,
Message: msg,
}
now := time.Now()

// Dispatch the logs
for _, filt := range log {
if lvl < filt.Level {
continue
}
// Make the log record
rec := &LogRecord{
Level: lvl,
Created: now,
Source: src,
Message: msg,
Category: filt.Category,
}
filt.LogWrite(rec)
}
}
Expand All @@ -254,20 +256,21 @@ func (log Logger) intLogc(lvl Level, closure func() string) {
if ok {
src = fmt.Sprintf("%s:%d", runtime.FuncForPC(pc).Name(), lineno)
}

// Make the log record
rec := &LogRecord{
Level: lvl,
Created: time.Now(),
Source: src,
Message: closure(),
}
now := time.Now()

// Dispatch the logs
for _, filt := range log {
if lvl < filt.Level {
continue
}
// Make the log record
rec := &LogRecord{
Level: lvl,
Created: now,
Source: src,
Category: filt.Category,
Message: closure(),
}
filt.LogWrite(rec)
}
}
Expand All @@ -287,19 +290,21 @@ func (log Logger) Log(lvl Level, source, message string) {
return
}

// Make the log record
rec := &LogRecord{
Level: lvl,
Created: time.Now(),
Source: source,
Message: message,
}
now := time.Now()

// Dispatch the logs
for _, filt := range log {
if lvl < filt.Level {
continue
}
// Make the log record
rec := &LogRecord{
Level: lvl,
Created: now,
Source: source,
Message: message,
Category: filt.Category,
}
filt.LogWrite(rec)
}
}
Expand Down
Loading