Skip to content

Commit 284223d

Browse files
authored
Added more tracing methods (#162)
* Changes to logger, adding tracing capabilities v1 * Started changing Logr struct to incorporate log.entry + cleaning * Updated * Integrated tracing with Debug, Info, and Trace * Updated Start Context and End Context * Cleaning up code on logger.go and logger_test.go * Changes made to support ending and restarting a span * Removed log line * removed test.log * Added tracing capabilities to logger methods * Changed to tracef and took away import statement in logger_test.go
1 parent 7509075 commit 284223d

File tree

1 file changed

+145
-1
lines changed

1 file changed

+145
-1
lines changed

logger/logger.go

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"sync"
1717
"time"
1818

19+
"github.com/jaegertracing/jaeger-client-go/config"
1920
"github.com/opentracing/opentracing-go"
2021
otLog "github.com/opentracing/opentracing-go/log"
2122
log "github.com/sirupsen/logrus"
@@ -258,7 +259,7 @@ func InitLogging(logName string, params *LogParams, alsoLogToStderr bool, initTr
258259

259260
//Span Initialized with default context
260261
span := tracer.StartSpan("CSI-Driver")
261-
log.Printf("Span Context --- Traceid:Spanid:ParentSpanid:Flags : %v", span.Context())
262+
log.Tracef("Span Context --- Traceid:Spanid:ParentSpanid:Flags : %v", span.Context())
262263
ctx := opentracing.ContextWithSpan(context.Background(), span)
263264
logEntry := sourced()
264265
l := Logr{ctx, logEntry, closer}
@@ -622,6 +623,12 @@ func Print(args ...interface{}) {
622623
sourced().Print(args...)
623624
}
624625

626+
func (lg *Logr) Print(args ...interface{}) {
627+
lg.logEntry.Print(args...)
628+
str := fmt.Sprintf("%v", args)
629+
lg.LogToTrace("Print", str)
630+
}
631+
625632
func Info(args ...interface{}) {
626633
sourced().Trace(args...)
627634
}
@@ -638,112 +645,249 @@ func Warn(args ...interface{}) {
638645
sourced().Warn(args...)
639646
}
640647

648+
func (lg *Logr) Warn(args ...interface{}) {
649+
lg.logEntry.Warn(args...)
650+
str := fmt.Sprintf("%v", args)
651+
lg.LogToTrace("Warn", str)
652+
}
653+
641654
// Warning logs a message at level Warn on the standard logger.
642655
func Warning(args ...interface{}) {
643656
sourced().Warning(args...)
644657
}
645658

659+
func (lg *Logr) Warning(args ...interface{}) {
660+
lg.logEntry.Warning(args...)
661+
str := fmt.Sprintf("%v", args)
662+
lg.LogToTrace("Warning", str)
663+
}
664+
646665
// Error logs a message at level Error on the standard logger.
647666
func Error(args ...interface{}) {
648667
sourced().Error(args...)
649668
}
650669

670+
func (lg *Logr) Error(args ...interface{}) {
671+
lg.logEntry.Error(args...)
672+
str := fmt.Sprintf("%v", args)
673+
lg.LogToTrace("Error", str)
674+
}
675+
651676
// Panic logs a message at level Panic on the standard logger.
652677
func Panic(args ...interface{}) {
653678
sourced().Panic(args...)
654679
}
655680

681+
func (lg *Logr) Panic(args ...interface{}) {
682+
lg.logEntry.Panic(args...)
683+
str := fmt.Sprintf("%v", args)
684+
lg.LogToTrace("Panic", str)
685+
}
686+
656687
// Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
657688
func Fatal(args ...interface{}) {
658689
sourced().Fatal(args...)
659690
}
691+
func (lg *Logr) Fatal(args ...interface{}) {
692+
lg.logEntry.Fatal(args...)
693+
str := fmt.Sprintf("%v", args)
694+
lg.LogToTrace("Fatal", str)
695+
}
660696

661697
// Tracef logs a message at level Trace on the standard logger.
662698
func Tracef(format string, args ...interface{}) {
663699
sourced().Tracef(format, args...)
664700
}
665701

702+
func (lg *Logr) Tracef(format string, args ...interface{}) {
703+
lg.logEntry.Tracef(format, args...)
704+
str := fmt.Sprintf("%v", args)
705+
lg.LogToTrace("Tracef", str)
706+
}
707+
666708
// Debugf logs a message at level Debug on the standard logger.
667709
func Debugf(format string, args ...interface{}) {
668710
sourced().Debugf(format, args...)
669711
}
670712

713+
func (lg *Logr) Debugf(format string, args ...interface{}) {
714+
lg.logEntry.Debugf(format, args...)
715+
str := fmt.Sprintf("%v", args)
716+
lg.LogToTrace("Debugf", str)
717+
}
718+
671719
// Printf logs a message at level Info on the standard logger.
672720
func Printf(format string, args ...interface{}) {
673721
sourced().Printf(format, args...)
674722
}
675723

724+
func (lg *Logr) Printf(format string, args ...interface{}) {
725+
lg.logEntry.Printf(format, args...)
726+
str := fmt.Sprintf("%v", args)
727+
lg.LogToTrace("Printf", str)
728+
}
729+
676730
// Infof logs a message at level Info on the standard logger.
677731
func Infof(format string, args ...interface{}) {
678732
sourced().Infof(format, args...)
679733
}
680734

735+
func (lg *Logr) Infof(format string, args ...interface{}) {
736+
lg.logEntry.Infof(format, args...)
737+
str := fmt.Sprintf("%v", args)
738+
lg.LogToTrace("Infof", str)
739+
}
740+
681741
// Warnf logs a message at level Warn on the standard logger.
682742
func Warnf(format string, args ...interface{}) {
683743
sourced().Warnf(format, args...)
684744
}
685745

746+
func (lg *Logr) Warnf(format string, args ...interface{}) {
747+
lg.logEntry.Warnf(format, args...)
748+
str := fmt.Sprintf("%v", args)
749+
lg.LogToTrace("Warnf", str)
750+
}
751+
686752
// Warningf logs a message at level Warn on the standard logger.
687753
func Warningf(format string, args ...interface{}) {
688754
sourced().Warningf(format, args...)
689755
}
690756

757+
func (lg *Logr) Warningf(format string, args ...interface{}) {
758+
lg.logEntry.Warningf(format, args...)
759+
str := fmt.Sprintf("%v", args)
760+
lg.LogToTrace("Warningf", str)
761+
}
762+
691763
// Errorf logs a message at level Error on the standard logger.
692764
func Errorf(format string, args ...interface{}) {
693765
sourced().Errorf(format, args...)
694766
}
695767

768+
func (lg *Logr) Errorf(format string, args ...interface{}) {
769+
lg.logEntry.Errorf(format, args...)
770+
str := fmt.Sprintf("%v", args)
771+
lg.LogToTrace("Errorf", str)
772+
}
773+
696774
// Panicf logs a message at level Panic on the standard logger.
697775
func Panicf(format string, args ...interface{}) {
698776
sourced().Panicf(format, args...)
699777
}
700778

779+
func (lg *Logr) Panicf(format string, args ...interface{}) {
780+
lg.logEntry.Panicf(format, args...)
781+
str := fmt.Sprintf("%v", args)
782+
lg.LogToTrace("Panicf", str)
783+
}
784+
701785
// Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
702786
func Fatalf(format string, args ...interface{}) {
703787
sourced().Fatalf(format, args...)
704788
}
705789

790+
func (lg *Logr) Fatalf(format string, args ...interface{}) {
791+
lg.logEntry.Fatalf(format, args...)
792+
str := fmt.Sprintf("%v", args)
793+
lg.LogToTrace("Fatalf", str)
794+
}
795+
706796
// Traceln logs a message at level Trace on the standard logger.
707797
func Traceln(args ...interface{}) {
708798
sourced().Traceln(args...)
709799
}
710800

801+
func (lg *Logr) Traceln(args ...interface{}) {
802+
lg.logEntry.Traceln(args...)
803+
str := fmt.Sprintf("%v", args)
804+
lg.LogToTrace("Traceln", str)
805+
}
806+
711807
// Debugln logs a message at level Debug on the standard logger.
712808
func Debugln(args ...interface{}) {
713809
sourced().Debugln(args...)
714810
}
715811

812+
func (lg *Logr) Debugln(args ...interface{}) {
813+
lg.logEntry.Debugln(args...)
814+
str := fmt.Sprintf("%v", args)
815+
lg.LogToTrace("Debugln", str)
816+
}
817+
716818
// Println logs a message at level Info on the standard logger.
717819
func Println(args ...interface{}) {
718820
sourced().Println(args...)
719821
}
720822

823+
func (lg *Logr) Println(args ...interface{}) {
824+
lg.logEntry.Println(args...)
825+
str := fmt.Sprintf("%v", args)
826+
lg.LogToTrace("Println", str)
827+
}
828+
721829
// Infoln logs a message at level Info on the standard logger.
722830
func Infoln(args ...interface{}) {
723831
sourced().Infoln(args...)
724832
}
725833

834+
func (lg *Logr) Infoln(args ...interface{}) {
835+
lg.logEntry.Infoln(args...)
836+
str := fmt.Sprintf("%v", args)
837+
lg.LogToTrace("Infoln", str)
838+
}
839+
726840
// Warnln logs a message at level Warn on the standard logger.
727841
func Warnln(args ...interface{}) {
728842
sourced().Warnln(args...)
729843
}
730844

845+
func (lg *Logr) Warnln(args ...interface{}) {
846+
lg.logEntry.Warnln(args...)
847+
str := fmt.Sprintf("%v", args)
848+
lg.LogToTrace("Warnln", str)
849+
}
850+
731851
// Warningln logs a message at level Warn on the standard logger.
732852
func Warningln(args ...interface{}) {
733853
sourced().Warningln(args...)
734854
}
735855

856+
func (lg *Logr) Warningln(args ...interface{}) {
857+
lg.logEntry.Warningln(args...)
858+
str := fmt.Sprintf("%v", args)
859+
lg.LogToTrace("Warningln", str)
860+
}
861+
736862
// Errorln logs a message at level Error on the standard logger.
737863
func Errorln(args ...interface{}) {
738864
sourced().Errorln(args...)
739865
}
740866

867+
func (lg *Logr) Errorln(args ...interface{}) {
868+
lg.logEntry.Errorln(args...)
869+
str := fmt.Sprintf("%v", args)
870+
lg.LogToTrace("Errorln", str)
871+
}
872+
741873
// Panicln logs a message at level Panic on the standard logger.
742874
func Panicln(args ...interface{}) {
743875
sourced().Panicln(args...)
744876
}
745877

878+
func (lg *Logr) Panicln(args ...interface{}) {
879+
lg.logEntry.Panicln(args...)
880+
str := fmt.Sprintf("%v", args)
881+
lg.LogToTrace("Panicln", str)
882+
}
883+
746884
// Fatalln logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
747885
func Fatalln(args ...interface{}) {
748886
sourced().Fatalln(args...)
749887
}
888+
889+
func (lg *Logr) Fatalln(args ...interface{}) {
890+
lg.logEntry.Fatalln(args...)
891+
str := fmt.Sprintf("%v", args)
892+
lg.LogToTrace("Fatalln", str)
893+
}

0 commit comments

Comments
 (0)