Esempio n. 1
0
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()
	}
}
Esempio n. 2
0
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()
	}
}
Esempio n. 3
0
// 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.")
	}
}
Esempio n. 4
0
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.
	}
}
Esempio n. 5
0
// 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
	}
}
Esempio n. 6
0
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)
}
Esempio n. 7
0
func TestSetModuleLoggingLevel(t *testing.T) {
	flogging.SetModuleLogLevel("peer", "WARNING")

	// ensure that the log level has changed to warning
	assertModuleLoggingLevel(t, "peer", logging.WARNING)
}
Esempio n. 8
0
// 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
}
Esempio n. 9
0
// 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
}