• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSLog() and stderr
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSLog() and stderr


  • Subject: Re: NSLog() and stderr
  • From: Aleksandr Skobelev <email@hidden>
  • Date: Mon, 03 Jul 2006 14:06:07 +0400

Damien Sorresso <email@hidden> writes:
> I'm trying to redirect NSLog()'s output to a file. Since it writes to
> stderr, I should be able to do this with
>
> stderr->_write = my_stderr_write ,
>
> where `my_stderr_write' is a pointer to one of my functions. This
> works just fine if I use fprintf() to write to stderr, but NSLog()
> stubbornly refuses to call my function. What exactly is NSLog() doing
> here that is so special?


You can try to do something like this in your main() function:

#ifndef USE_STDOUT_LOG
    char fullpath[MAXPATHLEN+1];
    sprintf(fullpath, "/Users/%s/Library/Logs/MyProgram.log", getlogin());

    int fd = open(fullpath, O_WRONLY | O_APPEND | O_CREAT | O_TRUNC, 0664);
    if (fd > 0) {
        dup2(fd, STDOUT_FILENO);
        dup2(fd, STDERR_FILENO);
        close(fd);
    }
#endif


All the best,
Aleksandr Skobelev
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Prev by Date: RE: Information Regarding LoginWindows Process
  • Next by Date: Re: Shiny little square buttons
  • Previous by thread: Re: Re: NSLog() and stderr
  • Next by thread: Shiny little square buttons
  • Index(es):
    • Date
    • Thread