• 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: Frode <email@hidden>
  • Date: Sun, 2 Jul 2006 10:51:49 +0200

Hi!

1 jul 2006 kl. 03.09 skrev Damien Sorresso:

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?

What exaclty capability or behaviour are you expecting from the logging function and what will it be use for?


It sounds that you will need replace NSLog() with your own logging function "MyLog()".

void MyFLog(FILE *fp, NSString *format, ...) {
	va_list argList;
	va_start(argList, format);
	MyFLogv(fp, format, argList);
	va_end(argList);
}

void MyFLogv(FILE *fp, NSString *format, va_list argList) {
	int old_fd = dup(fileno(stderr));
	int new_fd = dup2(fileno(fp), fileno(stderr));

	NSLogv(format, argList);

	(void)dup2(old_fd, fileno(stderr));
}


FYI, you can use syslog(3) or perhaps asl(3). Logging is tuned by / etc/syslog.conf and written to /var/log/*


Regards,
Rog
_______________________________________________
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


  • Follow-Ups:
    • Re: Re: NSLog() and stderr
      • From: "Michael Ash" <email@hidden>
  • Prev by Date: Re: Selected range in bound text view
  • Next by Date: Re: Changing file & directory names
  • Previous by thread: Deleting ManagedObject with no undo... (fails testing)
  • Next by thread: Re: Re: NSLog() and stderr
  • Index(es):
    • Date
    • Thread