Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Modify logging behavior when explicitly adding NullLogger with custom config #2594

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

filzrev
Copy link

@filzrev filzrev commented Jul 22, 2024

This PR intended to fix problem no console log is outputted when following conditions met.

  • Using custom config that adding NullLogger explicitly
  • Using custom config as Global Config (passing config as BenchmarkSwitcher::Run parameters)..

Currently BenchmarkDotNet use ConsoleLogger to print errors and list of benchmarks if logger is not enabled.
But when explicitly set NullLogger it's not works and no console logs are outputted.

Background

I'm trying to write custom progress logger that resolve #190 issue.
And it'll be implemented by using custom EventProcessor that is added from v0.13.9.

So It need to suppress default ConsoleLogger by adding NullLogger.
Because when no logger specified following error is recorded.

No loggers defined, you will not see any progress!

It works almost as intended.
But when passing custom config to BenchmarkSwitcher::Run argument. console log is not outputted.

@AndreyAkinshin
Copy link
Member

@filzrev Sorry, but I do not understand the original problem. If we pass a custom config with NullLogger to BenchmarkRunner or BenchmarkSwitcher, it is expected that we will not see the output. What's wrong with this behavior?

@filzrev
Copy link
Author

filzrev commented Aug 31, 2024

If we pass a custom config with NullLogger to BenchmarkRunner or BenchmarkSwitcher, it is expected that we will not see the output. What's wrong with this behavior?

The logger that is returned from GetNonNullCompositeLogger is used for following purpose.

  • Print config parse errors
  • Pring HostEnvironmentInfo
  • Print --list outputs

var logger = notNullConfig.GetNonNullCompositeLogger();
var (isParsingSuccess, parsedConfig, options) = ConfigParser.Parse(notNullArgs, logger, notNullConfig);
if (!isParsingSuccess) // invalid console args, the ConfigParser printed the error
return Array.Empty<Summary>();
if (args == null && Environment.GetCommandLineArgs().Length > 1) // The first element is the executable file name
logger.WriteLineHint("You haven't passed command line arguments to BenchmarkSwitcher.Run method. Running with default configuration.");
if (options.PrintInformation)
{
logger.WriteLine(HostEnvironmentInfo.GetInformation());
return Array.Empty<Summary>();
}
var effectiveConfig = ManualConfig.Union(notNullConfig, parsedConfig);
var (allTypesValid, allAvailableTypesWithRunnableBenchmarks) = TypeFilter.GetTypesWithRunnableBenchmarks(types, assemblies, logger);
if (!allTypesValid) // there were some invalid and TypeFilter printed errors
return Array.Empty<Summary>();
if (allAvailableTypesWithRunnableBenchmarks.IsEmpty())
{
userInteraction.PrintNoBenchmarksError(logger);
return Array.Empty<Summary>();
}
if (options.ListBenchmarkCaseMode != ListBenchmarkCaseMode.Disabled)
{
PrintList(logger, effectiveConfig, allAvailableTypesWithRunnableBenchmarks, options);
return Array.Empty<Summary>();
}

And this logger is not used for running actual benchmarks.

I'm output console logs by using ConsoleLogger.Default (via custom EventProcessor).
So default console logs should be suppressed by setting NullLogger.

But when setting NullLogger to global config.
Above type of logs are also suppressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: quiet mode
2 participants