• 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: Log4Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Log4Cocoa


  • Subject: Re: Log4Cocoa
  • From: Chris Hanson <email@hidden>
  • Date: Mon, 3 Feb 2003 22:13:01 -0600

At 4:46 PM +0100 2/3/03, Jacques wrote:
Is there any body who have succesfully used Log4Cocoa in a project ?

Are you having problems using it in your application? I've built a couple of internal projects that use it.

For those who don't know, Log4Cocoa is an Open Source logging framework that Bob Frank wrote modeled on Log4J. It's at <http://log4cocoa.sourceforge.net/>. Everyone should check it out. (I have commit access to the CVS repository, so I may be biased...)

I haven't integrated the Log4Cocoa framework into the projects I've built. Instead I build the framework with an install path of /Library/Frameworks, put it at that location, and then have my projects link against that.

I also put the following boilerplate in my application's controller class:

- (void)configureLogging
{
#if defined(DEBUG)
[[L4Logger rootLogger] setLevel:[L4Level all]];
#else
[[L4Logger rootLogger] setLevel:[L4Level fatal]];
#endif

[[L4Logger rootLogger] addAppender:
[[[L4ConsoleAppender alloc] initStandardOutWithLayout:
[L4Layout simpleLayout]] autorelease]];

L4Info(@"Logging configured.");
}

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
// Configure Log4Cocoa

[self configureLogging];

// do other stuff
}

(I have additional compile switches on these projects to define DEBUG when I build the project using the Development build style, and to define both DEBUG and TESTING when I build the project using the Test build style I set up to use the OCUnit framework. No, I haven't integrated OCUnit with Log4Cocoa.)

There's one other caveat to using Log4Cocoa: If you want to use a format string with one of the logging macros, you need to use it as so:

L4Info(([NSString stringWithFormat:@"%@", someMessage]));

Trying it without the doubled set of parentheses will confuse the C preprocessor and you'll get some odd error about passing too many arguments to a macro. The inner set of parentheses convinces the preprocessor to treat the Objective-C message send as a single argument.

Hope this helps. If you have more questions, feel free to ask here or on the Log4Cocoa mailing list.

-- Chris

--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Application Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
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.

  • Prev by Date: Re: Cocoa ? XML ? NSDictionary
  • Next by Date: Re: IB palettes and [NSBezierPath setDefaultLineWidth:]
  • Previous by thread: Re: Cocoa ? XML ? NSDictionary
  • Next by thread: Allocation and disposal inside a loop
  • Index(es):
    • Date
    • Thread