Commit cc9284e4 authored by Aaron Raddon's avatar Aaron Raddon

New log context logger methods

parent 9a11413a
......@@ -174,7 +174,8 @@ func LogLevelSet(levelWord string) {
}
}
// NewContext returns a new Context carrying Log context prefix.
// NewContext returns a new Context carrying contextual log message
// that gets prefixed to log statements.
func NewContext(ctx context.Context, msg string) context.Context {
return context.WithValue(ctx, logContextKey, msg)
}
......@@ -199,6 +200,17 @@ func Debugf(format string, v ...interface{}) {
}
}
// Debug log formatted context writer
func DebugCtx(format string, ctx context.Context, v ...interface{}) {
if LogLevel >= 4 {
lc := FromContext(ctx)
if len(lc) > 0 {
format = fmt.Sprintf("%s %s", lc, format)
}
DoLog(3, DEBUG, fmt.Sprintf(format, v...))
}
}
func DebugT(lineCt int) {
if LogLevel >= 4 {
DoLog(3, DEBUG, fmt.Sprint("\n", PrettyStack(lineCt)))
......@@ -219,6 +231,17 @@ func Infof(format string, v ...interface{}) {
}
}
// Info log formatted context writer
func InfoCtx(format string, ctx context.Context, v ...interface{}) {
if LogLevel >= 3 {
lc := FromContext(ctx)
if len(lc) > 0 {
format = fmt.Sprintf("%s %s", lc, format)
}
DoLog(3, INFO, fmt.Sprintf(format, v...))
}
}
// Info Trace
func InfoT(lineCt int) {
if LogLevel >= 3 {
......@@ -240,6 +263,17 @@ func Warnf(format string, v ...interface{}) {
}
}
// Warn log formatted context writer
func WarnCtx(format string, ctx context.Context, v ...interface{}) {
if LogLevel >= 2 {
lc := FromContext(ctx)
if len(lc) > 0 {
format = fmt.Sprintf("%s %s", lc, format)
}
DoLog(3, WARN, fmt.Sprintf(format, v...))
}
}
// Warn Trace
func WarnT(lineCt int) {
if LogLevel >= 2 {
......@@ -261,6 +295,17 @@ func Errorf(format string, v ...interface{}) {
}
}
// Error log formatted context writer
func ErrorCtx(format string, ctx context.Context, v ...interface{}) {
if LogLevel >= 1 {
lc := FromContext(ctx)
if len(lc) > 0 {
format = fmt.Sprintf("%s %s", lc, format)
}
DoLog(3, ERROR, fmt.Sprintf(format, v...))
}
}
// Log this error, and return error object
func LogErrorf(format string, v ...interface{}) error {
err := fmt.Errorf(format, v...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment