This handler redirects stderr output to a pipe and gathers logs from the read end. The handler is called from main loop, therefore, if a function prints logs to stderr they will be put to log file only after function returns.