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

fixed some bugs #167

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
15 changes: 13 additions & 2 deletions behavior_asynclooplogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,28 @@ func NewAsyncLoopLogger(config *logConfig) *asyncLoopLogger {

func (asnLoopLogger *asyncLoopLogger) processItem() (closed bool) {
asnLoopLogger.queueHasElements.L.Lock()
defer asnLoopLogger.queueHasElements.L.Unlock()

for asnLoopLogger.msgQueue.Len() == 0 && !asnLoopLogger.Closed() {
asnLoopLogger.queueHasElements.Wait()
}

element := asnLoopLogger.msgQueue.Front()

if element != nil {
asnLoopLogger.msgQueue.Remove(element)
}

asnLoopLogger.queueHasElements.L.Unlock()

if element != nil {
msg, _ := element.Value.(msgQueueItem)
asnLoopLogger.processLogMsg(msg.level, msg.message, msg.context)
}

if asnLoopLogger.Closed() {
return true
}

asnLoopLogger.processQueueElement()
return false
}

Expand Down
15 changes: 13 additions & 2 deletions behavior_asynctimerlogger.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,28 @@ func NewAsyncTimerLogger(config *logConfig, interval time.Duration) (*asyncTimer

func (asnTimerLogger *asyncTimerLogger) processItem() (closed bool) {
asnTimerLogger.queueHasElements.L.Lock()
defer asnTimerLogger.queueHasElements.L.Unlock()

for asnTimerLogger.msgQueue.Len() == 0 && !asnTimerLogger.Closed() {
asnTimerLogger.queueHasElements.Wait()
}

element := asnTimerLogger.msgQueue.Front()

if element != nil {
asnTimerLogger.msgQueue.Remove(element)
}

asnTimerLogger.queueHasElements.L.Unlock()

if element != nil {
msg, _ := element.Value.(msgQueueItem)
asnTimerLogger.processLogMsg(msg.level, msg.message, msg.context)
}

if asnTimerLogger.Closed() {
return true
}

asnTimerLogger.processQueueElement()
return false
}

Expand Down
2 changes: 1 addition & 1 deletion common_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func extractCallerInfo(skip int) (*logContext, error) {
}

var shortPath string
fullPath, line := funcInfo.FileLine(pc)
fullPath, line := funcInfo.FileLine(pc - 1)
if strings.HasPrefix(fullPath, workingDir) {
shortPath = fullPath[len(workingDir):]
} else {
Expand Down
2 changes: 1 addition & 1 deletion format.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (
// Time and date formats used for %Date and %Time aliases.
const (
DateDefaultFormat = "2006-01-02"
TimeFormat = "15:04:05"
TimeFormat = "15:04:05.000"
)

var DefaultMsgFormat = "%Ns [%Level] %Msg%n"
Expand Down
28 changes: 5 additions & 23 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,35 +336,17 @@ func (cLogger *commonLogger) isAllowed(level LogLevel, context LogContextInterfa
}

type logMessage struct {
params []interface{}
}

type logFormattedMessage struct {
format string
params []interface{}
str string
}

func newLogMessage(params []interface{}) fmt.Stringer {
message := new(logMessage)

message.params = params

return message
return &logMessage{ fmt.Sprint(params...) }
}

func newLogFormattedMessage(format string, params []interface{}) *logFormattedMessage {
message := new(logFormattedMessage)

message.params = params
message.format = format

return message
func newLogFormattedMessage(format string, params []interface{}) fmt.Stringer {
return &logMessage{ fmt.Sprintf(format, params...) }
}

func (message *logMessage) String() string {
return fmt.Sprint(message.params...)
}

func (message *logFormattedMessage) String() string {
return fmt.Sprintf(message.format, message.params...)
return message.str
}