Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDTTYLogger: Allow to set default color profiles for all contexts at once #146

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lumberjack/DDTTYLogger.h
Expand Up @@ -7,6 +7,8 @@

#import "DDLog.h"

#define LOG_CONTEXT_ALL NSIntegerMax
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of declaring and additional LOG_CONTEXT_ALL a negative context value could be used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should define a new constant/macro (I personally prefer constants because of the compiler can type check them).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about negative values? @robbiehanson ?

I like to have to remember as few constants as possible;)


/**
* Welcome to Cocoa Lumberjack!
*
Expand Down Expand Up @@ -117,6 +119,8 @@
* A logging context is often used to identify log messages coming from a 3rd party framework,
* although logging context's can be used for many different functions.
*
* Use LOG_CONTEXT_ALL to set the deafult color for all contexts that have no specific color set defined.
*
* Logging context's are explained in further detail here:
* https://github.com/robbiehanson/CocoaLumberjack/wiki/CustomContext
**/
Expand Down
20 changes: 17 additions & 3 deletions Lumberjack/DDTTYLogger.m
Expand Up @@ -1182,10 +1182,24 @@ - (void)logMessage:(DDLogMessage *)logMessage
{
for (DDTTYLoggerColorProfile *cp in colorProfilesArray)
{
if ((logMessage->logFlag & cp->mask) && (logMessage->logContext == cp->context))
if (logMessage->logFlag & cp->mask)
{
colorProfile = cp;
break;
// Color profile set for this context?
if (logMessage->logContext == cp->context)
{
colorProfile = cp;

// Stop searching
break;
}

// Check if LOG_CONTEXT_ALL was specified as a default color for this flag
if (cp->context == LOG_CONTEXT_ALL)
{
colorProfile = cp;

// We don't break to keep searching for more specific color profiles for the context
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allows setting more specific color profiles on top.

}
}
}
}
Expand Down