func TestGetModuleLoggingLevelDebug(t *testing.T) { flogging.SetModuleLogLevel("peer", "DEBUG") level, _ := flogging.GetModuleLogLevel("peer") // ensure that the log level has changed to debug if level != "DEBUG" { t.FailNow() } }
func TestGetModuleLoggingLevelInvalid(t *testing.T) { flogging.SetModuleLogLevel("peer", "invalid") level, _ := flogging.GetModuleLogLevel("peer") // ensure that the log level didn't change after invalid log level specified if level != "DEBUG" { t.FailNow() } }
// TestErrorWithCallstackMessage tests the output for a logging error where // and an invalid log level has been provided and the stack trace should be // displayed with the error message func TestErrorWithCallstackMessage(t *testing.T) { // when the 'error' module is set to debug, the callstack will be appended // to the error message flogging.SetModuleLogLevel("error", "debug") e := ErrorWithCallstack(Utility, UtilityUnknownError) s := e.GetStack() if s == "" { t.Fatalf("No error stack was recorded.") } // check that the error message contains this part of the stack trace, which // is non-platform specific if !strings.Contains(e.Error(), "github.com/hyperledger/fabric/core/errors.TestErrorWithCallstackMessage") { t.Fatalf("Error message does not have stack trace appended.") } }
func ExampleError() { // when the 'error' module is set to anything but debug, the callstack will // not be appended to the error message flogging.SetModuleLogLevel("error", "warning") err := ErrorWithCallstack(Utility, UtilityUnknownError) if err != nil { fmt.Printf("%s\n", err.Error()) fmt.Printf("%s\n", err.GetErrorCode()) fmt.Printf("%s\n", err.GetComponentCode()) fmt.Printf("%s\n", err.GetReasonCode()) fmt.Printf("%s\n", err.Message()) fmt.Printf("%s\n", err.MessageIn("en")) // Output: // An unknown error occurred. // Utility-UtilityUnknownError // Utility // UtilityUnknownError // An unknown error occurred. // An unknown error occurred. } }
// ExampleLoggingInvalidLogLevel tests the output for a logging error where // and an invalid log level has been provided func ExampleLoggingInvalidLogLevel() { // when the 'error' module is set to anything but debug, the callstack will // not be appended to the error message flogging.SetModuleLogLevel("error", "warning") err := ErrorWithCallstack(Logging, LoggingInvalidLogLevel, "invalid") if err != nil { fmt.Printf("%s\n", err.Error()) fmt.Printf("%s\n", err.GetErrorCode()) fmt.Printf("%s\n", err.GetComponentCode()) fmt.Printf("%s\n", err.GetReasonCode()) fmt.Printf("%s\n", err.Message()) fmt.Printf("%s\n", err.MessageIn("en")) // Output: // Invalid log level provided - invalid // Logging-LoggingInvalidLogLevel // Logging // LoggingInvalidLogLevel // Invalid log level provided - invalid // Invalid log level provided - invalid } }
func TestSetModuleLoggingLevelInvalid(t *testing.T) { flogging.SetModuleLogLevel("peer", "invalid") // ensure that the log level didn't change after invalid log level specified assertModuleLoggingLevel(t, "peer", logging.WARNING) }
func TestSetModuleLoggingLevel(t *testing.T) { flogging.SetModuleLogLevel("peer", "WARNING") // ensure that the log level has changed to warning assertModuleLoggingLevel(t, "peer", logging.WARNING) }
// SetErrorLoggingLevel sets the 'error' module's logger to the value in // core.yaml func SetErrorLoggingLevel() error { viperErrorLoggingLevel := viper.GetString("logging.error") _, err := flogging.SetModuleLogLevel("error", viperErrorLoggingLevel) return err }
// SetModuleLogLevel sets the logging level for the specified module func (*ServerAdmin) SetModuleLogLevel(ctx context.Context, request *pb.LogLevelRequest) (*pb.LogLevelResponse, error) { logLevelString, err := flogging.SetModuleLogLevel(request.LogModule, request.LogLevel) logResponse := &pb.LogLevelResponse{LogModule: request.LogModule, LogLevel: logLevelString} return logResponse, err }