in src/KernelApplication.cs [254:294]
public KernelApplication AddKernelCommand(Action<CommandLineApplication>? configure = null)
{
var kernelCmd = this.Command(
"kernel",
cmd =>
{
var logEnvVarName = $"{properties.KernelName.ToUpperInvariant()}_LOG_LEVEL";
cmd.HelpOption();
cmd.Description = $"Runs the {properties.FriendlyName} kernel. Typically only run by a Jupyter client.";
var connectionFileArg = cmd.Argument(
"connection-file", "Connection file used to connect to a Jupyter client."
);
var logLevelOpt = cmd.Option<LogLevel>(
"-l|--log-level <LEVEL>",
"Level of logging messages to emit to the console. Defaults to Error." +
$"Can also be set with the {logEnvVarName} environment variable.",
CommandOptionType.SingleValue
);
cmd.OnExecute(() =>
{
var connectionFile = connectionFileArg.Value;
// Check if there is an environment variable set that
// overrides logging level, then check the command line
// option, and finally fall back to a reasonable default.
var logLevelFromEnv =
System.Environment.GetEnvironmentVariable(logEnvVarName);
var logLevel =
logLevelFromEnv == null
? logLevelOpt.HasValue()
? logLevelOpt.ParsedValue
: LogLevel.Error
: (LogLevel)Enum.Parse(typeof(LogLevel), logLevelFromEnv);
return ReturnExitCode(() => Run(connectionFile, logLevel));
});
}
);
configure?.Invoke(kernelCmd);
return this;
}