@@ -205,41 +205,56 @@ namespace Utils
205205 " <log level>" ,
206206 " The logging level to use. Choices are 'Trace', 'Debug', 'Info', 'Warn', 'Error', 'Fatal', and 'None'. "
207207 " (optional, default='none')" );
208+ RegisterCommand (
209+ m_cmd_log_file,
210+ " <str>" ,
211+ " File to write logs to. If not provided, logs will be written to stdout. "
212+ " (optional, default='none')" );
208213 }
209214
210215 void CommandLineUtils::StartLoggingBasedOnCommand (Aws::Crt::ApiHandle *apiHandle)
211216 {
212217 // Process logging command
213218 if (HasCommand (" verbosity" ))
214219 {
220+ Aws::Crt::LogLevel logLevel = Aws::Crt::LogLevel::None;
215221 Aws::Crt::String verbosity = GetCommand (m_cmd_verbosity);
216222 if (verbosity == " Fatal" )
217223 {
218- apiHandle-> InitializeLogging ( Aws::Crt::LogLevel::Fatal, stderr) ;
224+ logLevel = Aws::Crt::LogLevel::Fatal;
219225 }
220226 else if (verbosity == " Error" )
221227 {
222- apiHandle-> InitializeLogging ( Aws::Crt::LogLevel::Error, stderr) ;
228+ logLevel = Aws::Crt::LogLevel::Error;
223229 }
224230 else if (verbosity == " Warn" )
225231 {
226- apiHandle-> InitializeLogging ( Aws::Crt::LogLevel::Warn, stderr) ;
232+ logLevel = Aws::Crt::LogLevel::Warn;
227233 }
228234 else if (verbosity == " Info" )
229235 {
230- apiHandle-> InitializeLogging ( Aws::Crt::LogLevel::Info, stderr) ;
236+ logLevel = Aws::Crt::LogLevel::Info;
231237 }
232238 else if (verbosity == " Debug" )
233239 {
234- apiHandle-> InitializeLogging ( Aws::Crt::LogLevel::Debug, stderr) ;
240+ logLevel = Aws::Crt::LogLevel::Debug;
235241 }
236242 else if (verbosity == " Trace" )
237243 {
238- apiHandle->InitializeLogging (Aws::Crt::LogLevel::Trace, stderr);
244+ logLevel = Aws::Crt::LogLevel::Trace;
245+ }
246+ else
247+ {
248+ logLevel = Aws::Crt::LogLevel::None;
249+ }
250+
251+ if (HasCommand (" log_file" ))
252+ {
253+ apiHandle->InitializeLogging (logLevel, GetCommand (m_cmd_log_file).c_str ());
239254 }
240255 else
241256 {
242- // If none or unknown, then do nothing
257+ apiHandle-> InitializeLogging (logLevel, stderr);
243258 }
244259 }
245260 }
0 commit comments