• 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: When I don't want NSLog() for normal use?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: When I don't want NSLog() for normal use?


  • Subject: Re: When I don't want NSLog() for normal use?
  • From: Bob Frank <email@hidden>
  • Date: Fri, 25 Oct 2002 00:16:19 -0500

Hi,

Can I toss in my 2 cents about Log4Cocoa. It is a port of the popular java logging package Log4J and if anyone is interested (*hint* *hint* if you want to help out and send us a patch or something, that'd be cool) its available at:

http://sourceforge.net/projects/log4cocoa (currently pre-alpha, but has core functionality)

Log4Cocoa allows you to leave your logging code in your compiled code and turn it on & off easily at run time. This can be useful for debugging released code in the wild or on a server or anywhere you don't have gdb. Also, it allows you to have multiple levels of logging (you can have one class at Error, another at Off, and another at Debug).

The usage is based on a few high level macros, that allow easy logging at various levels. By default these macros log on a per class basis and will get flexible formatting options just like the java version.

L4Debug(message);
L4Info(message);
L4Warn(message);
L4Error(message);
L4Fatal(message);

L4DebugWithException(message, e);
L4InfoWithException(message, e);
L4WarnWithException(message, e);
L4ErrorWithException(message, e);
L4FatalWithException(message, e);

L4Assert(assertion, message); // failed assertions log at Error level

Right now we are working towards our alpha release. We will focus on performance issues in upcoming releases. However, deciding not to log a message can be determined fairly efficiently. The cost of logging is much much higher than the cost of evaluating whether or not to log.

Also, if you've got performance critical sections, you can, of course, still use #ifdef to take the logging code out of there or just keep your logging statements outside the critical sections.


-Bob

PS: in case anyone cares, here are the macros in full & what they expand out to. The first one gathers location info from the gcc preprocessor. Each should be on only one line, but the mailer might munge them. Also, [self logger] is a category on NSObject. The Logger is one the central objects in Log4Cocoa.

#define L4_LOCATION lineNumber: __LINE__ fileName: __FILE__ methodName: __PRETTY_FUNCTION__

#define L4LogDebug L4_LOCATION debug
#define L4LogInfo L4_LOCATION info
#define L4LogWarn L4_LOCATION warn
#define L4LogError L4_LOCATION error
#define L4LogFatal L4_LOCATION fatal
#define L4LogAssert L4_LOCATION assert

#define L4Debug(message) if([[self logger] isDebugEnabled]) [[self logger] L4LogDebug: message]
#define L4Info(message) if([[self logger] isInfoEnabled]) [[self logger] L4LogInfo: message]
#define L4Warn(message) [[self logger] L4LogWarn: message]
#define L4Error(message) [[self logger] L4LogError: message]
#define L4Fatal(message) [[self logger] L4LogFatal: message]

#define L4DebugWithException(message, e) if([[self logger] isDebugEnabled]) [[self logger] L4LogDebug: message exception: e]
#define L4InfoWithException(message, e) if([[self logger] isInfoEnabled]) [[self logger] L4LogInfo: message exception: e]
#define L4WarnWithException(message, e) [[self logger] L4LogWarn: message exception: e]
#define L4ErrorWithException(message, e) [[self logger] L4LogError: message exception: e]
#define L4FatalWithException(message, e) [[self logger] L4LogFatal: message exception: e]

#define L4Assert(assertion, message) [[self logger] L4LogAssert: assertion log: message]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
References: 
 >When I don't want NSLog() for normal use? (From: Hisaoki Nishida <email@hidden>)

  • Prev by Date: Re: Security framework refuses to work at all
  • Next by Date: Re: Updating Minimized Windows
  • Previous by thread: Re: When I don't want NSLog() for normal use?
  • Next by thread: Re: When I don't want NSLog() for normal use?
  • Index(es):
    • Date
    • Thread