NSLog() to both console and file

后端 未结 2 1052
感动是毒
感动是毒 2020-12-08 20:20

I would like to redirect NSog() to file, but still to see the output in console. I am aware that stderr can be redirected to file using:

         


        
2条回答
  •  旧巷少年郎
    2020-12-08 20:36

    The way we have implemented is:

    if (!isatty(STDERR_FILENO)) {
        // Redirection code
    }
    

    This is based on general assumption that if a console is attached, you do not need to store those logs in the file since you are already debugging. So whenever the console is attached, logs will be printed there, otherwise saved to a file.

提交回复
热议问题