onnxruntime icon indicating copy to clipboard operation
onnxruntime copied to clipboard

User-provided session logging function is not used for every log

Open JulienTheron opened this issue 1 year ago • 4 comments

Describe the issue

Since ORT 1.17, we have the ability to assign a logging function to the session options. However, the feature seems to be incomplete as it only affects some logs where it should affect all of them.

To reproduce

Just create a session with a user-defined logging function. While the session is created, you'll notice a lot of logs to the console (the environment's default logger), while some others are passed to the session logging function.

Here's an (incomplete) example:

const Ort::Env env(ORT_LOGGING_LEVEL_VERBOSE);

Ort::SessionOptions options;
Ort::GetApi().SetUserLoggingFunction(options, MyLoggingFunction, MyLoggingFunctionParam);
options.SetLogSeverityLevel(ORT_LOGGING_LEVEL_VERBOSE);

Ort::Session session(env, ModelFilePath, options);

Urgency

Not urgent.

Platform

Windows

OS Version

Windows 11 23H2

ONNX Runtime Installation

Built from Source

ONNX Runtime Version or Commit ID

1.17.3 and 1.18.0 RC

ONNX Runtime API

C++

Architecture

X64

Execution Provider

Default CPU, CUDA, DirectML, TensorRT

Execution Provider Library Version

No response

JulienTheron avatar May 14 '24 18:05 JulienTheron

Many of the log calls that occur even after a session has been created do not go through the session logger. E.g., you can find many uses of LOGS_DEFAULT in the code.

Consider using the Ort::Env constructor which takes a custom logging function to use a custom logger for more of the logs. https://github.com/microsoft/onnxruntime/blob/113aa2992fdf05ff3c871ef722ee1bc2e9462eca/include/onnxruntime/core/session/onnxruntime_cxx_api.h#L703-L704

edgchen1 avatar May 14 '24 21:05 edgchen1

Many of the log calls that occur even after a session has been created do not go through the session logger. E.g., you can find many uses of LOGS_DEFAULT in the code.

Shouldn't that be considered a bug then?

Consider using the Ort::Env constructor which takes a custom logging function to use a custom logger for more of the logs.

That's what we did before 1.17. But having all logs going to the same place can be a mess when you have multiple sessions being used at the same time.

JulienTheron avatar May 15 '24 13:05 JulienTheron

Many of the log calls that occur even after a session has been created do not go through the session logger. E.g., you can find many uses of LOGS_DEFAULT in the code.

Shouldn't that be considered a bug then?

@pranavsharma what do you think?

edgchen1 avatar May 16 '24 17:05 edgchen1

In the Run() function, we create a separate run logger. This is different from the session logger. We may not have access (or difficult to get access) to the run logger in all the places during the Run call. Hence, we resort to using LOGS_DEFAULT. Your case is different. If you've overridden a session with your own logger, it should be used during session init. If not, it's a bug.

pranavsharma avatar May 16 '24 19:05 pranavsharma

This issue has been automatically marked as stale due to inactivity and will be closed in 30 days if no further activity occurs. If further support is needed, please provide an update and/or more details.

github-actions[bot] avatar Jun 16 '24 15:06 github-actions[bot]

Any news about this issue? Thanks.

JulienTheron avatar Jun 17 '24 12:06 JulienTheron

I agree with Julien, it is confusing to keep seeing warnings after setting the log severity level for a session.

gntoni avatar Jan 31 '25 02:01 gntoni