Skip to content

Commit

Permalink
Merge pull request #293 from rollbar/log_level_order
Browse files Browse the repository at this point in the history
Fixed log level ordering to standard
  • Loading branch information
matux authored Jun 6, 2023
2 parents 49757c9 + ecb1133 commit ef7a934
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 48 deletions.
4 changes: 2 additions & 2 deletions RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarData.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ -(void)setBody:(nonnull RollbarBody *)value {

-(RollbarLevel)level {
NSString *result = [self safelyGetStringByKey:DFK_LEVEL];
return [RollbarLevelUtil RollbarLevelFromString:result];
return [RollbarLevelUtil rollbarLevelFromString:result];
}

-(void)setLevel:(RollbarLevel)value {
[self setData:[RollbarLevelUtil RollbarLevelToString:value]
[self setData:[RollbarLevelUtil rollbarLevelToString:value]
byKey:DFK_LEVEL];
}

Expand Down
44 changes: 17 additions & 27 deletions RollbarNotifier/Sources/RollbarNotifier/DTOs/RollbarLevel.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,39 @@

@implementation RollbarLevelUtil

+ (NSString *) RollbarLevelToString:(RollbarLevel)value; {

+ (NSString *)rollbarLevelToString:(RollbarLevel)value {
switch (value) {
case RollbarLevel_Debug:
return @"debug";
case RollbarLevel_Info:
return @"info";
case RollbarLevel_Warning:
return @"warning";
case RollbarLevel_Critical:
return @"critical";
case RollbarLevel_Error:
return @"error";
case RollbarLevel_Critical:
return @"critical";
default:
return @"info";
}
}

+ (RollbarLevel) RollbarLevelFromString:(nullable NSString *)value {

if (nil == value) {

return RollbarLevel_Info; // default case...
}
else if (NSOrderedSame == [value caseInsensitiveCompare:@"debug"]) {

+ (RollbarLevel)rollbarLevelFromString:(nullable NSString *)value {
if (value == nil) {
return RollbarLevel_Info;
} else if ([value caseInsensitiveCompare:@"debug"] == NSOrderedSame) {
return RollbarLevel_Debug;
}
else if (NSOrderedSame == [value caseInsensitiveCompare:@"warning"]) {

} else if ([value caseInsensitiveCompare:@"info"] == NSOrderedSame) {
return RollbarLevel_Info;
} else if ([value caseInsensitiveCompare:@"warning"] == NSOrderedSame) {
return RollbarLevel_Warning;
}
else if (NSOrderedSame == [value caseInsensitiveCompare:@"critical"]) {

return RollbarLevel_Critical;
}
else if (NSOrderedSame == [value caseInsensitiveCompare:@"error"]) {

} else if ([value caseInsensitiveCompare:@"error"] == NSOrderedSame) {
return RollbarLevel_Error;
}
else {

return RollbarLevel_Info; // default case...
} else if ([value caseInsensitiveCompare:@"critical"] == NSOrderedSame) {
return RollbarLevel_Critical;
} else {
return RollbarLevel_Info;
}
}

@end

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#pragma mark - constants

static RollbarLevel const DEFAULT_LOG_LEVEL = RollbarLevel_Info;
static RollbarLevel const DEFAULT_LOG_LEVEL = RollbarLevel_Debug;
static RollbarLevel const DEFAULT_CRASH_LEVEL = RollbarLevel_Error;
static NSUInteger const DEFAULT_MAX_REPORTS_PER_MINUTE = 60;
static RollbarRateLimitBehavior const DEFAULT_RATE_LIMIT_BEHAVIOR = RollbarRateLimitBehavior_Drop;
Expand Down Expand Up @@ -41,8 +41,8 @@ - (instancetype)initWithLogLevel:(RollbarLevel)logLevel
requestId:(nullable NSString *)requestId
{
self = [super initWithDictionary:@{
DFK_LOG_LEVEL: [RollbarLevelUtil RollbarLevelToString:logLevel],
DFK_CRASH_LEVEL: [RollbarLevelUtil RollbarLevelToString:crashLevel],
DFK_LOG_LEVEL: [RollbarLevelUtil rollbarLevelToString:logLevel],
DFK_CRASH_LEVEL: [RollbarLevelUtil rollbarLevelToString:crashLevel],
DFK_MAX_REPORTS_PER_MINUTE: [NSNumber numberWithUnsignedInteger:maximumReportsPerMinute],
DFK_RATE_LIMIT_BEHAVIOR: [NSNumber numberWithBool:rateLimitBehavior],
DFK_IP_CAPTURE_TYPE: [RollbarCaptureIpTypeUtil CaptureIpTypeToString:DEFAULT_IP_CAPTURE_TYPE],
Expand Down Expand Up @@ -142,12 +142,12 @@ - (instancetype)init {

- (RollbarLevel)logLevel {
NSString *logLevelString = [self safelyGetStringByKey:DFK_LOG_LEVEL];
return [RollbarLevelUtil RollbarLevelFromString:logLevelString];
return [RollbarLevelUtil rollbarLevelFromString:logLevelString];
}

- (RollbarLevel)crashLevel {
NSString *logLevelString = [self safelyGetStringByKey:DFK_CRASH_LEVEL];
return [RollbarLevelUtil RollbarLevelFromString:logLevelString];
return [RollbarLevelUtil rollbarLevelFromString:logLevelString];
}

- (NSUInteger)maximumReportsPerMinute {
Expand Down Expand Up @@ -202,12 +202,12 @@ - (instancetype)init {
@dynamic requestId;

- (void)setLogLevel:(RollbarLevel)level {
NSString *levelString = [RollbarLevelUtil RollbarLevelToString:level];
NSString *levelString = [RollbarLevelUtil rollbarLevelToString:level];
[self setString:levelString forKey:DFK_LOG_LEVEL];
}

- (void)setCrashLevel:(RollbarLevel)level {
NSString *levelString = [RollbarLevelUtil RollbarLevelToString:level];
NSString *levelString = [RollbarLevelUtil rollbarLevelToString:level];
[self setString:levelString forKey:DFK_CRASH_LEVEL];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ - (instancetype)initWithLevel:(RollbarLevel)level
RollbarTelemetryBody *body = [RollbarTelemetryEvent createTelemetryBodyWithType:type
data:nil];
self = [self initWithDictionary:@{
DFK_LEVEL:[RollbarLevelUtil RollbarLevelToString:level],
DFK_LEVEL:[RollbarLevelUtil rollbarLevelToString:level],
DFK_TYPE:[RollbarTelemetryTypeUtil RollbarTelemetryTypeToString:type],
DFK_SOURCE:[RollbarSourceUtil RollbarSourceToString:source],
DFK_TIMESTAMP:[NSNumber numberWithDouble:round(timestamp)],
Expand All @@ -48,7 +48,7 @@ - (instancetype)initWithLevel:(RollbarLevel)level
NSTimeInterval timestamp = NSDate.date.timeIntervalSince1970 * 1000.0;
RollbarTelemetryType type = [RollbarTelemetryEvent deriveTypeFromBody:body];
self = [self initWithDictionary:@{
DFK_LEVEL:[RollbarLevelUtil RollbarLevelToString:level],
DFK_LEVEL:[RollbarLevelUtil rollbarLevelToString:level],
DFK_TYPE:[RollbarTelemetryTypeUtil RollbarTelemetryTypeToString:type],
DFK_SOURCE:[RollbarSourceUtil RollbarSourceToString:source],
DFK_TIMESTAMP:[NSNumber numberWithDouble:round(timestamp)],
Expand All @@ -69,7 +69,7 @@ - (instancetype)initWithDictionary:(NSDictionary<NSString *, id> *)data {
-(RollbarLevel)level {

NSString *result = [self getDataByKey:DFK_LEVEL];
return [RollbarLevelUtil RollbarLevelFromString:result];
return [RollbarLevelUtil rollbarLevelFromString:result];
}

#pragma mark type
Expand Down
4 changes: 2 additions & 2 deletions RollbarNotifier/Sources/RollbarNotifier/RollbarTelemetry.m
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ - (void)recordEventForLevel:(RollbarLevel)level
}

NSTimeInterval timestamp = NSDate.date.timeIntervalSince1970 * 1000.0;
NSString *telemetryLvl = [RollbarLevelUtil RollbarLevelToString:level];
NSString *telemetryLvl = [RollbarLevelUtil rollbarLevelToString:level];
NSString *telemetryType = [RollbarTelemetryTypeUtil RollbarTelemetryTypeToString:type];
NSDictionary *info = @{@"level": telemetryLvl,
@"type": telemetryType,
Expand Down Expand Up @@ -336,7 +336,7 @@ - (void)recordLogEventForLevel:(RollbarLevel)level
[RollbarTelemetryEvent createTelemetryBodyWithType:eventType data:dataItem[@"body"]];
if (nil != eventBody) {

RollbarLevel eventLevel = [RollbarLevelUtil RollbarLevelFromString:dataItem[@"level"]];
RollbarLevel eventLevel = [RollbarLevelUtil rollbarLevelFromString:dataItem[@"level"]];
RollbarSource eventSource = [RollbarSourceUtil RollbarSourceFromString:dataItem[@"source"]];
RollbarTelemetryEvent *event = [[RollbarTelemetryEvent alloc] initWithLevel:eventLevel
source:eventSource
Expand Down
10 changes: 5 additions & 5 deletions RollbarNotifier/Sources/RollbarNotifier/include/RollbarLevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#pragma mark - RollbarLevel

typedef NS_ENUM(NSUInteger, RollbarLevel) {
RollbarLevel_Info,
RollbarLevel_Debug,
RollbarLevel_Info,
RollbarLevel_Warning,
RollbarLevel_Critical,
RollbarLevel_Error
RollbarLevel_Error,
RollbarLevel_Critical
};

#pragma mark - RollbarLevel utility
Expand All @@ -22,11 +22,11 @@ NS_ASSUME_NONNULL_BEGIN

/// Converts RollbarLevel enum value to its string equivalent or default string.
/// @param value RollbarLevel enum value
+ (NSString *) RollbarLevelToString:(RollbarLevel)value;
+ (NSString *)rollbarLevelToString:(RollbarLevel)value;

/// Converts string value into its RollbarLevel enum value equivalent or default enum value.
/// @param value input string
+ (RollbarLevel) RollbarLevelFromString:(nullable NSString *)value;
+ (RollbarLevel)rollbarLevelFromString:(nullable NSString *)value;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ - (void)testRollbarLoggingOptionsDTO {
);

dto = [[RollbarMutableLoggingOptions alloc] init];
XCTAssertTrue(dto.logLevel == RollbarLevel_Info,
XCTAssertTrue(dto.logLevel == RollbarLevel_Debug,
@"Proper default log level"
);
XCTAssertTrue(dto.crashLevel == RollbarLevel_Error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ final class RollbarNotifierDTOsTests: XCTestCase {
);

dto = RollbarMutableLoggingOptions();
XCTAssertTrue(dto.logLevel == .info,
XCTAssertTrue(dto.logLevel == .debug,
"Proper default log level"
);
XCTAssertTrue(dto.crashLevel == .error,
Expand Down

0 comments on commit ef7a934

Please sign in to comment.