コード例 #1
0
ファイル: logging_test.go プロジェクト: hyperledger/fabric
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()
	}
}
コード例 #2
0
ファイル: logging_test.go プロジェクト: hyperledger/fabric
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()
	}
}
コード例 #3
0
ファイル: errors_test.go プロジェクト: hyperledger/fabric
// 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.")
	}
}
コード例 #4
0
ファイル: errors_test.go プロジェクト: hyperledger/fabric
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.
	}
}
コード例 #5
0
ファイル: errors_test.go プロジェクト: hyperledger/fabric
// 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
	}
}
コード例 #6
0
ファイル: logging_test.go プロジェクト: hyperledger/fabric
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)
}
コード例 #7
0
ファイル: logging_test.go プロジェクト: hyperledger/fabric
func TestSetModuleLoggingLevel(t *testing.T) {
	flogging.SetModuleLogLevel("peer", "WARNING")

	// ensure that the log level has changed to warning
	assertModuleLoggingLevel(t, "peer", logging.WARNING)
}
コード例 #8
0
ファイル: common.go プロジェクト: hyperledger/fabric
// 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
}
コード例 #9
0
ファイル: admin.go プロジェクト: hyperledger/fabric
// 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
}