foundationkit / FoundationKit

Everything that really should be in Foundation, but isn't. Future-proof with ARC
Other
80 stars 9 forks source link

Add NKLog function #7

Closed MSch closed 13 years ago

MSch commented 13 years ago

This will become the ultimative logging method:

https://gist.github.com/1062703 and https://github.com/steipete/PSFoundation/blob/master/Lumberjack/VTPG_Common.h

PLEASE DON'T MERGE THIS, THIS PULL REQUEST IS FOR DISCUSSING THE BRANCH

steipete commented 13 years ago

Lucky for you, it can't be automatically merged anyway ;)

MSch commented 13 years ago

Also it's currently only a collection of snippets :)

myell0w commented 13 years ago

Have we decided on a logging-framework yet?

As I saw @eaigner likes a very lightweight solution using printf, therefore his NKShow - macro. While this definitely has some advantages I still like a full-fledged solution using log levels, different log locations etc. and am pretty happy with CocoaLumberJack in comination with VTPG_Common. I haven't really had time to look into your branch in detail @MSch.

So maybe we should support both ways, full-fledged and lightweight.

MSch commented 13 years ago

My branch is currently only a collection of snippets, but I'm going the @eaigner route. I think if people are happy with CocoaLumberJack they should use CocoaLumberJack.

eaigner commented 13 years ago

@myell0w log levels are no problem. The NKShow macro shouldn't replace a log function in the first place, but it's just the equivalent of a CFShow or -description for plain types/structs like CGRect, CGPoint.

steipete commented 13 years ago

We definitely will support both - sometimes lightweigt is enough, sth file-based logger+controllable levels at runtime are really handy...

MSch commented 13 years ago

@steipete Don't close (unfinished) pull requests

MSch commented 13 years ago

Ok, now I'd need some serious C help /cc @steipete, @eaigner, @myell0w

See here: https://github.com/foundationkit/FoundationKit/blob/ccdeca33976ba92eba3677783f599b53d172b6ad/Sources/NKLog.m#L24

&object, *object didn't work.

steipete commented 13 years ago

@MSch sorry for closing, pressed the wrong button yesterday w/o thinking.

steipete commented 13 years ago

Hmm - this is already pretty advanced code. How do you get the sentinel? Will i have to terminate the va_args myself?

e.g. NKLog(a,b,c,NULL) .. (or your token)

Can you clarify your plans? And what kNRInternalEndVarArgs will do exactly?

steipete commented 13 years ago

This compiler trick seems pretty good - but does it work for clang? You referenced it in the header, are you using sth like N_ARGS(...)?

http://stackoverflow.com/questions/2632300/looping-through-macro-varargs-values

MSch commented 13 years ago

It is standard C99 and works on GCC, Clang with and without GCC extensions.

My plans are to make it work like https://gist.github.com/1062704

I'm also adding NKLogStr which returns a NSString* for integrating in logging frameworks.

MSch commented 13 years ago

Sorry this took so long. Got a working implementation in 6999ea7f4f7e1132e490258fd96a9b60a0162a52 now.

Supports FKLogToString which returns an NSString and FKLog which NSLogs that string.

The idea is for users of FoundationKit to define their own Log macro that's conditional on the DEBUG macro, like this:

#ifdef DEBUG
  #define Log(...) FKLog(__VA_ARGS__)
#else
  #define Log(...)
#endif
MSch commented 13 years ago

We're currently using this:

#define Log(...) FKLog(__VA_ARGS__)

#ifdef DEBUG
    #define DebugLog(...) FKLog(__VA_ARGS__)
    #define DebugNSLog(...) NSLog(__VA_ARGS__)
#else
    #define DebugLog(...)
    #define DebugNSLog(...)
#endif