Skip to content

Commit

Permalink
logging: add EnvoyLogLevel enum to iOS interface (#195)
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: JP Simard <jp@jpsim.com>
  • Loading branch information
goaway authored and jpsim committed Nov 28, 2022
1 parent 1a917ae commit cc2cd33
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
13 changes: 12 additions & 1 deletion mobile/library/objective-c/Envoy.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#import <Foundation/Foundation.h>

/// Available logging levels for an Envoy instance. Note some levels may be compiled out.
typedef NS_ENUM(NSInteger, EnvoyLogLevel) {
EnvoyLogLevelTrace,
EnvoyLogLevelDebug,
EnvoyLogLevelInfo,
EnvoyLogLevelWarn,
EnvoyLogLevelError,
EnvoyLogLevelCritical,
EnvoyLogLevelOff
};

@interface Envoy : NSObject

/// Indicates whether this Envoy instance is currently active and running.
Expand All @@ -14,6 +25,6 @@

/// Create a new Envoy instance. The Envoy runner NSThread is started as part of instance
/// initialization with the configuration provided.
- (instancetype)initWithConfig:(NSString *)config logLevel:(NSString *)logLevel;
- (instancetype)initWithConfig:(NSString *)config logLevel:(EnvoyLogLevel)logLevel;

@end
16 changes: 13 additions & 3 deletions mobile/library/objective-c/Envoy.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
static NSString *const kConfig = @"config";
static NSString *const kLogLevel = @"logLevel";

static NSString *const kLogLevelToString[] = {
[EnvoyLogLevelTrace] = @"trace",
[EnvoyLogLevelDebug] = @"debug",
[EnvoyLogLevelInfo] = @"info",
[EnvoyLogLevelWarn] = @"warn",
[EnvoyLogLevelError] = @"error",
[EnvoyLogLevelCritical] = @"critical",
[EnvoyLogLevelOff] = @"off"
};

@interface Envoy ()
@property (nonatomic, strong) NSThread *runner;
@end
Expand All @@ -14,16 +24,16 @@ @implementation Envoy
@synthesize runner;

- (instancetype)initWithConfig:(NSString *)config {
self = [self initWithConfig:config logLevel:@"info"];
self = [self initWithConfig:config logLevel:EnvoyLogLevelInfo];
return self;
}

- (instancetype)initWithConfig:(NSString *)config logLevel:(NSString *) logLevel {
- (instancetype)initWithConfig:(NSString *)config logLevel:(EnvoyLogLevel)logLevel {
self = [super init];
if (self) {
NSDictionary *args = @{
kConfig: config,
kLogLevel: logLevel,
kLogLevel: kLogLevelToString[logLevel],
};
self.runner = [[NSThread alloc] initWithTarget:self selector:@selector(run:) object:args];
[self.runner start];
Expand Down

0 comments on commit cc2cd33

Please sign in to comment.