Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Add log channels to Aleth command-line help output #5549

@halfalicious

Description

@halfalicious

Aleth logs messages to various Boost log channels and has 4 levels of logging which increase in verbosity from level 0 (no logging) to 4 (verbose logging). The log level can be set at runtime (via -v<level>), and similarly log channels can be enabled or disabled via the --log-channels and --log-exclude-channels args. Aleth's command-line help output (aleth -h) lists all of these args, but it doesn't include the list of available channels which can make it difficult for one to determine which channels to enable / disable.

To address this, the command-line help output for Aleth should be updated to include the list of log channels. The logging command line help output is built here:

po::options_description createLoggingProgramOptions(unsigned _lineLength, LoggingOptions& _options)
{
po::options_description optionsDescr("LOGGING OPTIONS", _lineLength);
auto addLoggingOption = optionsDescr.add_options();
addLoggingOption("log-verbosity,v", po::value<int>(&_options.verbosity)->value_name("<0 - 4>"),
"Set the log verbosity from 0 to 4 (default: 2).");
addLoggingOption("log-channels",
po::value<std::vector<std::string>>(&_options.includeChannels)
->value_name("<channel_list>")
->multitoken(),
"Space-separated list of the log channels to show (default: show all channels).");
addLoggingOption("log-exclude-channels",
po::value<std::vector<std::string>>(&_options.excludeChannels)
->value_name("<channel_list>")
->multitoken(),
"Space-separated list of the log channels to hide.\n");
return optionsDescr;
}

Aleth calls the function here:

aleth/aleth/main.cpp

Lines 325 to 326 in ad7204c

po::options_description loggingProgramOptions(
createLoggingProgramOptions(c_lineWidth, loggingOptions));

A log channel is defined when a Logger object is created - for example, the following Logger writes messages to the "net" channel:

Logger m_logger{createLogger(VerbosityDebug, "net")};

You can build a list of all channels by searching the codebase for instances of Logger m_logger. Don't include loggers defined in test files (i.e. files under aleth\tools)

Also, createLoggingProgramOptions is used by multiple Aleth tools (e.g. aleth-bootnode) and these tools don't use the same set of log channels as Aleth, but we still want createLoggingOptions to be general purpose. To address this, you should build the list of log channels in Aleth's main.cpp and pass it into createLoggingProgramOptions where you include it in the boost::program_options:options_description being built. You can pass in empty strings in the other tools. These tools are:

  • aleth-bootnode:
    po::options_description loggingProgramOptions(
    createLoggingProgramOptions(c_lineWidth, loggingOptions));
  • aleth-vm:

    aleth/aleth-vm/main.cpp

    Lines 124 to 125 in ad7204c

    po::options_description loggingProgramOptions(
    createLoggingProgramOptions(c_lineWidth, loggingOptions));
  • aleth-key:

    aleth/aleth-key/main.cpp

    Lines 41 to 42 in ad7204c

    po::options_description loggingProgramOptions(createLoggingProgramOptions(
    po::options_description::m_default_line_length, loggingOptions));

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions