Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #515 from jeanregisser/fix_asl_logger_duplicates_w…
…ith_asl_capture_active

Prevent duplicate log entries when both DDASLLogCapture and DDASLLogger are used
  • Loading branch information
rivera-ernesto committed May 22, 2015
2 parents 08f7fa0 + 16b13d6 commit 3e7bdd6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Classes/DDASLLogCapture.m
Expand Up @@ -95,6 +95,9 @@ + (void)configureAslQuery:(aslmsg)query {
const char param[] = "7"; // ASL_LEVEL_DEBUG, which is everything. We'll rely on regular DDlog log level to filter

asl_set_query(query, ASL_KEY_LEVEL, param, ASL_QUERY_OP_LESS_EQUAL | ASL_QUERY_OP_NUMERIC);

// Don't retrieve logs from our own DDASLLogger
asl_set_query(query, kDDASLKeyDDLog, kDDASLDDLogValue, ASL_QUERY_OP_NOT_EQUAL);

#if !TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
int processId = [[NSProcessInfo processInfo] processIdentifier];
Expand Down
6 changes: 6 additions & 0 deletions Classes/DDASLLogger.h
Expand Up @@ -22,6 +22,12 @@

#import "DDLog.h"

// Custom key set on messages sent to ASL
extern const char* const kDDASLKeyDDLog;

// Value set for kDDASLKeyDDLog
extern const char* const kDDASLDDLogValue;

/**
* This class provides a logger for the Apple System Log facility.
*
Expand Down
7 changes: 6 additions & 1 deletion Classes/DDASLLogger.m
Expand Up @@ -20,6 +20,10 @@
#error This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

const char* const kDDASLKeyDDLog = "DDLog";

const char* const kDDASLDDLogValue = "1";

static DDASLLogger *sharedInstance;

@interface DDASLLogger () {
Expand Down Expand Up @@ -100,7 +104,8 @@ - (void)logMessage:(DDLogMessage *)logMessage {
if (m != NULL) {
if (asl_set(m, ASL_KEY_LEVEL, level_strings[aslLogLevel]) == 0 &&
asl_set(m, ASL_KEY_MSG, msg) == 0 &&
asl_set(m, ASL_KEY_READ_UID, readUIDString) == 0) {
asl_set(m, ASL_KEY_READ_UID, readUIDString) == 0 &&
asl_set(m, kDDASLKeyDDLog, kDDASLDDLogValue) == 0) {
asl_send(_client, m);
}
asl_free(m);
Expand Down

0 comments on commit 3e7bdd6

Please sign in to comment.