summaryrefslogtreecommitdiff
path: root/SmartDeviceLink/SDLLogConfiguration.m
blob: 3ef5526dfb5c42c5b154f941e016046c23ac1a68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
//  SDLLogConfiguration.m
//  SmartDeviceLink-iOS
//
//  Created by Joel Fischer on 2/27/17.
//  Copyright © 2017 smartdevicelink. All rights reserved.
//

#import "SDLLogConfiguration.h"

#import "SDLLogFileModule.h"
#import "SDLLogFileModuleMap.h"
#import "SDLLogTargetAppleSystemLog.h"
#import "SDLLogTargetOSLog.h"


NS_ASSUME_NONNULL_BEGIN

@implementation SDLLogConfiguration

- (instancetype)init {
    self = [super init];
    if (!self) { return nil; }

    _modules = [NSSet set];
    _targets = [NSSet set];
    _filters = [NSSet set];
    _formatType = SDLLogFormatTypeDefault;
    _asynchronous = YES;
    _errorsAsynchronous = NO;
    _globalLogLevel = SDLLogLevelError;

    return self;
}

- (instancetype)initWithDefaultConfiguration {
    self = [self init];
    if (!self) {
        return nil;
    }

    NSOperatingSystemVersion osVersion = [NSProcessInfo processInfo].operatingSystemVersion;

    if (osVersion.majorVersion >= 10) {
        _targets = [NSSet setWithArray:@[[SDLLogTargetOSLog logger]]];
    } else {
        _targets = [NSSet setWithArray:@[[SDLLogTargetAppleSystemLog logger]]];
    }

    _modules = [SDLLogFileModuleMap sdlModuleMap];

    return self;
}

+ (instancetype)defaultConfiguration {
    return [[self.class alloc] initWithDefaultConfiguration];
}

- (instancetype)initWithDebugConfiguration {
    self = [self initWithDefaultConfiguration];
    if (!self) { return nil; }

    _formatType = SDLLogFormatTypeDetailed;
    _globalLogLevel = SDLLogLevelDebug;

    return self;
}

+ (instancetype)debugConfiguration {
    return [[self.class alloc] initWithDebugConfiguration];
}

#pragma mark - NSCopying

- (id)copyWithZone:(nullable NSZone *)zone {
    SDLLogConfiguration *newConfig = [[self.class allocWithZone:zone] init];
    newConfig.modules = self.modules;
    newConfig.targets = self.targets;
    newConfig.filters = self.filters;
    newConfig.formatType = self.formatType;
    newConfig.asynchronous = self.asynchronous;
    newConfig.errorsAsynchronous = self.errorsAsynchronous;
    newConfig.globalLogLevel = self.globalLogLevel;

    return newConfig;
}

@end

NS_ASSUME_NONNULL_END