No logging output in console (offscreen rendering)

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

No logging output in console (offscreen rendering)

Postby dmKO » Thu Mar 24, 2016 6:56 am

Hi all,

I try to get some feedback from some renderer methods, but they do not seem to be able to write to a Windows console by using printf or std::cout. Using LOG(INFO) works in cefsimple when command line flags "enable-logging" and "no-sandbox" are set, but it doesn't in our offscreen rendering project. We are using OpenGL (and GLFW for IO) to render in a separate window. Under Windows 10, a console is opened by using the following lines:
Code: Select all
AllocConsole();
freopen("conin$", "r", stdin);
freopen("conout$", "w", stdout);
freopen("conout$", "w", stderr);

Of course, LOG(INFO) can't write to this console, but without those lines no console opens at all - although command line flags were used.
Any ideas what to do to get some printed output from renderer methods on a console while executing the program? Checking the log files is really annoying for real-time testing.
Thanks!
Daniel
Working on EU project MAMEM, developing GazeTheWeb - a gaze controlled web browser, based on (you'll guess it) CEF3. ;)
dmKO
Newbie
 
Posts: 5
Joined: Sat Mar 12, 2016 1:32 pm

Re: No logging output in console (offscreen rendering)

Postby stibot » Wed May 11, 2016 3:27 am

I am also frustrated with the console behavior when CEF is initialized. I have found a partial workaround, but would be much happier if it is fixed within CEF (i.e. if CEF doesn't interfere with the console).

I also did find that I have to turn the console ON/OFF rather from Windows message loop to prevent showing two consoles and another weird stuff to happen.

Code: Select all
class CGUIConsole {
  bool m_bConsole;
  HANDLE m_hOut;
public:
  CGUIConsole() : m_hOut(NULL) {
    m_bConsole = ::AllocConsole();
    if (m_bConsole) {
      m_hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    }
  }
  void out(const char *pStr, int iLen) {
    DWORD dwRet;
    m_hOut && pStr && WriteConsoleA(m_hOut, pStr, iLen, &dwRet, NULL);
  }
  ~CGUIConsole() {
    if (m_bConsole) {
      CloseHandle(m_hOut);
      m_hOut = NULL;
      ::FreeConsole();
    }
  }
};
stibot
Newbie
 
Posts: 1
Joined: Wed May 11, 2016 3:09 am

Re: No logging output in console (offscreen rendering)

Postby iboB » Thu Nov 10, 2016 6:18 am

Actually AllocConsole works for me. printf and fprintf(stdout...) both work fine. It's std::cout that somehow doesn't work. Apparently CEF redirects std::cout for some reason. (and not std::cerr which also works with redirecting stderr to the console)

After adding these lines, however, everything works fine:

Code: Select all
   
    // curiously CEF redirects cout somewhere...
    auto leakedStream = new std::ofstream("CONOUT$");
    // yes, we created a leak... but that's the easiest way to do this (plus this happens just once)
    std::cout.rdbuf(leakedStream->rdbuf());
iboB
Newbie
 
Posts: 1
Joined: Thu Nov 10, 2016 6:15 am


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 62 guests