Expose logging-level functions

- Added functions for setting per-session and environment-wide logging
   levels. This allows me to remove the stdout message when the test
   fails to load the OpenVINO library.
This commit is contained in:
yalue
2025-05-30 08:23:55 -04:00
parent f15b62b8d0
commit f2f88a05ab
2 changed files with 36 additions and 0 deletions

View File

@@ -254,6 +254,21 @@ func EnableTelemetry() error {
return nil
}
// Sets the environmnent-wide log severity level. The argument must be one of
// LoggingLevelVerbose, LoggingLevelInfo, LoggingLevelWarning,
// LoggingLevelError, or LoggingLevelFatal. Must only be used after the
// environment has been initialized.
func SetEnvironmentLogLevel(level LoggingLevel) error {
if !IsInitialized() {
return NotInitializedError
}
status := C.UpdateEnvWithCustomLogLevel(ortEnv, C.OrtLoggingLevel(level))
if status != nil {
return statusToError(status)
}
return nil
}
// The Shape type holds the shape of the tensors used by the network input and
// outputs.
type Shape []int64
@@ -1307,6 +1322,17 @@ func (o *SessionOptions) SetGraphOptimizationLevel(
return nil
}
// Sets the sessions log severity level. Must be one of LoggingLevelVerbose,
// LoggingLevelInfo, LoggingLevelWarning, LoggingLevelError, or
// LoggingLevelFatal.
func (o *SessionOptions) SetLogSeverityLevel(level LoggingLevel) error {
status := C.SetSessionLogSeverityLevel(o.o, C.int(level))
if status != nil {
return statusToError(status)
}
return nil
}
// Returns true, nil if the SessionOptions has a configuration entry with the
// given key. Returns false if the key isn't defined. Returns an error if
// onnxruntime indicates an error, though it isn't clear from the docs what

View File

@@ -1745,6 +1745,10 @@ func TestSessionOptions(t *testing.T) {
if e != nil {
t.Fatalf("Error setting memory pattern: %s\n", e)
}
e = options.SetLogSeverityLevel(LoggingLevelWarning)
if e != nil {
t.Fatalf("Error setting log severity level: %s\n", e)
}
testBigSessionWithOptions(t, options)
}
@@ -2181,6 +2185,12 @@ func getOpenVINOSessionOptions(t testing.TB) *SessionOptions {
if e != nil {
t.Fatalf("Error creating session options: %s\n", e)
}
// OpenVINO prints messages to stdout simply for missing libraries. We
// don't want to clutter the test output, so reduce the logging level.
e = SetEnvironmentLogLevel(LoggingLevelFatal)
if e != nil {
t.Fatalf("Error reducing log severity level for OpenVINO: %s\n", e)
}
e = options.AppendExecutionProviderOpenVINO(map[string]string{})
if e != nil {
options.Destroy()