Skip to content
This repository was archived by the owner on Nov 21, 2023. It is now read-only.

Commit 325cc23

Browse files
Merge pull request #22 from goinsane/develop
v1.2.4
2 parents 677f0f1 + cba477f commit 325cc23

File tree

4 files changed

+45
-32
lines changed

4 files changed

+45
-32
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/goinsane/xlog
22

33
go 1.13
44

5-
require github.com/goinsane/erf v1.3.0
5+
require github.com/goinsane/erf v1.3.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ github.com/goinsane/erf v1.2.3 h1:cEEG7wj0gIsdvRJ8nGqqlUgd8tGvcVXv9nPaXLRwxzI=
2222
github.com/goinsane/erf v1.2.3/go.mod h1:KIGOu4SVAUGC5gHe3Q/uCswZN40wwPFJ9MS924nA/AI=
2323
github.com/goinsane/erf v1.3.0 h1:gpRutecrDaZWwAk2h3AHMCZcXMQO+rlrN9j/nkm1bdA=
2424
github.com/goinsane/erf v1.3.0/go.mod h1:KIGOu4SVAUGC5gHe3Q/uCswZN40wwPFJ9MS924nA/AI=
25+
github.com/goinsane/erf v1.3.1 h1:Ubf1sRztbnHeYc5URgKUcpqjC/DyCV0lN7OoZnpjFxE=
26+
github.com/goinsane/erf v1.3.1/go.mod h1:KIGOu4SVAUGC5gHe3Q/uCswZN40wwPFJ9MS924nA/AI=
2527
gopkg.in/Graylog2/go-gelf.v2 v2.0.0-20191017102106-1550ee647df0 h1:Xg23ydYYJLmb9AK3XdcEpplHZd1MpN3X2ZeeMoBClmY=
2628
gopkg.in/Graylog2/go-gelf.v2 v2.0.0-20191017102106-1550ee647df0/go.mod h1:CeDeqW4tj9FrgZXF/dQCWZrBdcZWWBenhJtxLH4On2g=

logger.go

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,13 @@ func (l *Logger) out(severity Severity, message string, err error) {
9393
if l.stackTraceSeverity >= severity {
9494
log.StackTrace = e.StackTrace()
9595
}
96-
log.Error = e.Unwrap()
96+
/*e2 := e.Unwrap()
97+
if _, ok := e2.(*erf.Erf); ok {
98+
log.Error = e2
99+
} else {
100+
log.Error = e.CopyByTop(e.PCLen())
101+
}*/
102+
log.Error = e.CopyByTop(e.PCLen())
97103
} else {
98104
log.StackCaller = erf.NewStackTrace(erf.PC(1, 5)...).Caller(0)
99105
if l.stackTraceSeverity >= severity {
@@ -405,22 +411,22 @@ func (l *Logger) WithFieldMap(fieldMap map[string]interface{}) *Logger {
405411
return l.WithFields(fields...)
406412
}
407413

408-
// ErfError creates a new *erf.Erf by the given argument. It logs to the ERROR severity logs and returns the *erf.Erf.
414+
// ErfError creates a new *erf.Erf by the given argument. It logs to the ERROR severity logs and returns the new *erf.Erf.
409415
func (l *Logger) ErfError(arg interface{}) *erf.Erf {
410416
return l.erfError(SeverityError, arg)
411417
}
412418

413-
// ErfErrorf creates a new *erf.Erf by given arguments. It logs to the ERROR severity logs and returns the result to call Attach method of *erf.Erf.
419+
// ErfErrorf creates a new *erf.Erf by given arguments. It logs to the ERROR severity logs and returns the result to get the new *erf.Erf.
414420
func (l *Logger) ErfErrorf(format string, args ...interface{}) *loggerErfResult {
415421
return l.erfErrorf(SeverityError, format, args...)
416422
}
417423

418-
// ErfWarning creates a new *erf.Erf by the given argument. It logs to the WARNING severity logs and returns the *erf.Erf.
424+
// ErfWarning creates a new *erf.Erf by the given argument. It logs to the WARNING severity logs and returns the new *erf.Erf.
419425
func (l *Logger) ErfWarning(arg interface{}) *erf.Erf {
420426
return l.erfError(SeverityWarning, arg)
421427
}
422428

423-
// ErfWarningf creates a new *erf.Erf by given arguments. It logs to the WARNING severity logs and returns the result to call Attach method of *erf.Erf.
429+
// ErfWarningf creates a new *erf.Erf by given arguments. It logs to the WARNING severity logs and returns the result to get the new *erf.Erf.
424430
func (l *Logger) ErfWarningf(format string, args ...interface{}) *loggerErfResult {
425431
return l.erfErrorf(SeverityWarning, format, args...)
426432
}
@@ -436,7 +442,7 @@ func (l *Logger) erfError(severity Severity, arg interface{}) *erf.Erf {
436442
} else {
437443
result.e = erf.New(fmt.Sprint(arg)).CopyByTop(2)
438444
}
439-
return result.Attach()
445+
return result.Log()
440446
}
441447

442448
func (l *Logger) erfErrorf(severity Severity, format string, args ...interface{}) *loggerErfResult {
@@ -454,29 +460,34 @@ type loggerErfResult struct {
454460
e *erf.Erf
455461
}
456462

463+
// Attach calls Attach method of *erf.Erf.
464+
// It returns result of Log method, and logs to the underlying Logger that using Log method.
457465
func (r *loggerErfResult) Attach(tags ...string) *erf.Erf {
458-
e := r.e
459-
if len(tags) > 0 {
460-
e = e.Attach(tags...)
461-
}
462-
if r.l != nil {
463-
r.l.erfStackTrace = true
464-
for idx, e2 := range e.UnwrapAll() {
465-
if e3, ok := e2.(*erf.Erf); ok {
466-
for _, tag := range e3.Tags() {
467-
tagIdx := e3.TagIndex(tag)
468-
r.l.fields = append(r.l.fields, Field{
469-
Key: tag,
470-
Value: e3.Arg(tagIdx),
471-
mark: &FieldMarkErf{
472-
No: idx,
473-
Index: tagIdx,
474-
},
475-
})
476-
}
466+
r.e = r.e.Attach(tags...)
467+
return r.Log()
468+
}
469+
470+
// Log logs to the underlying Logger, and returns the new *erf.Erf.
471+
func (r *loggerErfResult) Log() *erf.Erf {
472+
if r.l == nil {
473+
return r.e
474+
}
475+
r.l.erfStackTrace = true
476+
for idx, e := range r.e.UnwrapAll() {
477+
if e2, ok := e.(*erf.Erf); ok {
478+
for _, tag := range e2.Tags() {
479+
tagIdx := e2.TagIndex(tag)
480+
r.l.fields = append(r.l.fields, Field{
481+
Key: tag,
482+
Value: e2.Arg(tagIdx),
483+
mark: &FieldMarkErf{
484+
No: idx,
485+
Index: tagIdx,
486+
},
487+
})
477488
}
478489
}
479-
r.l.log(r.s, e)
480490
}
481-
return e
491+
r.l.log(r.s, r.e)
492+
return r.e
482493
}

xlog.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,22 +209,22 @@ func SetOutputFlags(flags Flag) *TextOutput {
209209
return defaultOutput.SetFlags(flags)
210210
}
211211

212-
// ErfError creates a new *erf.Erf by the given argument. It logs to the ERROR severity logs to the default Logger and returns the *erf.Erf.
212+
// ErfError creates a new *erf.Erf by the given argument. It logs to the ERROR severity logs to the default Logger and returns the new *erf.Erf.
213213
func ErfError(arg interface{}) *erf.Erf {
214214
return defaultLogger.erfError(SeverityError, arg)
215215
}
216216

217-
// ErfErrorf creates a new *erf.Erf by given arguments. It logs to the ERROR severity logs to the default Logger and the result to call Attach method of *erf.Erf.
217+
// ErfErrorf creates a new *erf.Erf by given arguments. It logs to the ERROR severity logs to the default Logger and the result to get the new *erf.Erf.
218218
func ErfErrorf(format string, args ...interface{}) *loggerErfResult {
219219
return defaultLogger.erfErrorf(SeverityError, format, args...)
220220
}
221221

222-
// ErfWarning creates a new *erf.Erf by the given argument. It logs to the WARNING severity logs to the default Logger and returns the *erf.Erf.
222+
// ErfWarning creates a new *erf.Erf by the given argument. It logs to the WARNING severity logs to the default Logger and returns the new *erf.Erf.
223223
func ErfWarning(arg interface{}) *erf.Erf {
224224
return defaultLogger.erfError(SeverityWarning, arg)
225225
}
226226

227-
// ErfWarningf creates a new *erf.Erf by given arguments. It logs to the WARNING severity logs to the default Logger and returns the result to call Attach method of *erf.Erf.
227+
// ErfWarningf creates a new *erf.Erf by given arguments. It logs to the WARNING severity logs to the default Logger and returns the result to get the new *erf.Erf.
228228
func ErfWarningf(format string, args ...interface{}) *loggerErfResult {
229229
return defaultLogger.erfErrorf(SeverityWarning, format, args...)
230230
}

0 commit comments

Comments
 (0)