LoggerInterface API - reading all lines from the console



  • Based on a previous post, I implemented the example to read all the lines from the console.
    "This example accesses the default logger and gets all displayed lines".

    I changed the microsdk example to implement the function.
    Below the Execute() part of the command plugin.

    However, it does not show any lines in the console.

    Also, when I change DiagnosticOutput("Line: @", line._str); to ApplicationOutput("Line: @", line._str); cinema 'hangs' on the line above userLoggerType.Iterate([](maxon::LoggerLine& line) -> maxon::Result<void>

    Could it be that I did not activate the diagnostic output?

    Manual: "The output is visible in debug builds or in a release build when the debug console with diagnostic output is activated"

    	virtual Bool Execute(BaseDocument* doc)
    	{
    		iferr_scope_handler
    		{
    			// if an error occurred, show a pop-up message
    			const maxon::String errString = err.ToString(nullptr);
    			::MessageDialog(errString);
    			return false;
    		};
    
    		//###########################################
    		// This example accesses the default logger and gets all displayed lines.
    		// get default logger
    
    		ApplicationOutput("This example accesses the default logger and gets all displayed lines.");
    		
    		const maxon::LoggerRef defaultLogger = maxon::Loggers::Default();
    		for (const auto& logger : defaultLogger.GetLoggerTypes())
    		{
    			const maxon::LoggerTypeRef loggerType = logger.GetFirst();  // get first element of the pair
    			if (loggerType.IsInstanceOf<maxon::UserLoggerTypeRef>())
    			{
    				const maxon::UserLoggerTypeRef userLoggerType = maxon::Cast<maxon::UserLoggerTypeRef>(loggerType);
    				// iterate over all lines sent to the logger
    				userLoggerType.Iterate([](maxon::LoggerLine& line) -> maxon::Result<void>
    				{
    					DiagnosticOutput("Line: @", line._str);
    					//ApplicationOutput("Line: @", line._str);
    					return maxon::OK;
    				}) iferr_return;
    			}
    		}
    		
    
    		return true;
    	}
    


  • I guess I found some answers:

    DiagnosticOutput() uses the IDE Console, so I set 'g_alloc=debug', which then showed the information in the VS C++ output window.

    I am still struggling with outputting the the console lines to the application console or to a text file.

    When I add the the line ApplicationOutput("Line: @", line._str); after the DiagnosticOutput() line, I get the following message in the VC Output window (the IDE Console).

    "Socket closed without SSL shutdown handshake [network_ip_ssl_impl.cpp(854)]
    Was not able to create new user".


  • Global Moderator

    Hello,

    as you have discovered, ApplicationOutput() sends messages to the default (GUI) console window.

    DiagnosticOutput() sends messages to the IDE console window. This has nothing to do with g_alloc=debug.

    See "Printing Debug Messages".

    So what you want to do is to access the content of the default logger (Loggers::Default()) and write that content back into that very same default logger (ApplicationOutput()).

    When you use ApplicationOutput() in the iterator, you create new line every time your access a line. This is of course a perfect recipe for an recursive, infinite loop.

    If you want to print the content of the default logger back to the default logger, you have to store the content temporarily. Something like this:

    // temp array
    maxon::BaseArray<maxon::String> lines;
    
    // iterate over all lines of the logger
    userLoggerType.Iterate([&lines](maxon::LoggerLine& line) -> maxon::Result<void>
    {
      iferr_scope;
      // store line
      lines.Append(line._str) iferr_return;
      return maxon::OK;
    }) iferr_return;
    
    // print back to default logger
    for (const maxon::String& line : lines)
    {
      ApplicationOutput("Message: @", line);
    }
    

    best wishes,
    Sebastian



  • Great, thank you for the great explanation, especially of the loop!
    I will give it a try.

    -Pim