motion-logger 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -0
- data/Gemfile +3 -0
- data/README.md +48 -0
- data/Rakefile +15 -0
- data/app/app_delegate.rb +5 -0
- data/lib/logger/log.rb +85 -0
- data/lib/logger/version.rb +5 -0
- data/lib/motion-logger.rb +14 -0
- data/motion-logger.gemspec +19 -0
- data/spec/log_spec.rb +41 -0
- data/vendor/Podfile.lock +6 -0
- data/vendor/Pods/CocoaLumberjack/.gitignore +24 -0
- data/vendor/Pods/CocoaLumberjack/.hgignore +6 -0
- data/vendor/Pods/CocoaLumberjack/CocoaLumberjack.podspec +18 -0
- data/vendor/Pods/CocoaLumberjack/LICENSE.txt +18 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.h +41 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDASLLogger.m +99 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.h +102 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDAbstractDatabaseLogger.m +618 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.h +334 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDFileLogger.m +1346 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.h +498 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDLog.m +979 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.h +49 -0
- data/vendor/Pods/CocoaLumberjack/Lumberjack/DDTTYLogger.m +186 -0
- data/vendor/Pods/CocoaLumberjack/README.markdown +37 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDASLLogger.h +41 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDAbstractDatabaseLogger.h +102 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDFileLogger.h +334 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDLog.h +498 -0
- data/vendor/Pods/Headers/CocoaLumberjack/DDTTYLogger.h +49 -0
- data/vendor/Pods/Pods-prefix.pch +3 -0
- data/vendor/Pods/Pods-resources.sh +15 -0
- data/vendor/Pods/Pods.bridgesupport +462 -0
- data/vendor/Pods/Pods.xcconfig +4 -0
- data/vendor/Pods/build-iPhoneSimulator/libPods.a +0 -0
- metadata +104 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# motion-logger
|
2
|
+
|
3
|
+
A thin wrapper of CocoaLumberjack for RubyMotion.
|
4
|
+
|
5
|
+
Status: Basic features working
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
file_logger = DDFileLogger.new
|
11
|
+
file_logger.rollingFrequency = 60 * 60 * 24
|
12
|
+
file_logger.logFileManager.maximumNumberOfLogFiles = 1
|
13
|
+
Log.addLogger file_logger
|
14
|
+
|
15
|
+
tty_logger = DDTTYLogger.sharedInstance
|
16
|
+
Log.addLogger tty_logger
|
17
|
+
|
18
|
+
Log.level = :warn
|
19
|
+
|
20
|
+
Log.info "Hello World"
|
21
|
+
Log.warn "WARNING!"
|
22
|
+
Log.debug "Lah"
|
23
|
+
Log.flush
|
24
|
+
```
|
25
|
+
|
26
|
+
## Setup
|
27
|
+
|
28
|
+
Install the gem:
|
29
|
+
|
30
|
+
```
|
31
|
+
gem install motion-logger
|
32
|
+
```
|
33
|
+
|
34
|
+
Require the gem in Rakefile:
|
35
|
+
|
36
|
+
```
|
37
|
+
require 'rubygems'
|
38
|
+
require 'motion-logger'
|
39
|
+
|
40
|
+
Motion::Project::App.setup do |app|
|
41
|
+
app.name = 'MyApp'
|
42
|
+
|
43
|
+
# Only needed if you are not already using pods
|
44
|
+
app.pods do
|
45
|
+
dependency 'CocoaLumberjack'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
$:.unshift("/Library/RubyMotion/lib")
|
3
|
+
require 'motion/project'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'motion-cocoapods'
|
6
|
+
require 'motion-redgreen'
|
7
|
+
require './lib/motion-logger'
|
8
|
+
|
9
|
+
Motion::Project::App.setup do |app|
|
10
|
+
app.name = 'logger'
|
11
|
+
|
12
|
+
app.pods do
|
13
|
+
dependency 'CocoaLumberjack'
|
14
|
+
end
|
15
|
+
end
|
data/app/app_delegate.rb
ADDED
data/lib/logger/log.rb
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
module LoggerClassMethods
|
2
|
+
FLAGS = {
|
3
|
+
:error => (1<<0), # 0...0001
|
4
|
+
:warn => (1<<1), # 0...0010
|
5
|
+
:info => (1<<2), # 0...0100
|
6
|
+
:verbose => (1<<3), # 0...1000
|
7
|
+
:debug => (1<<3) # 0...1000
|
8
|
+
}
|
9
|
+
|
10
|
+
LEVELS = {
|
11
|
+
:off => 0,
|
12
|
+
:error => FLAGS[:error],
|
13
|
+
:warn => FLAGS[:error] | FLAGS[:warn],
|
14
|
+
:info => FLAGS[:error] | FLAGS[:warn] | FLAGS[:info],
|
15
|
+
:verbose => FLAGS[:error] | FLAGS[:warn] | FLAGS[:info] | FLAGS[:verbose],
|
16
|
+
:debug => FLAGS[:error] | FLAGS[:warn] | FLAGS[:info] | FLAGS[:verbose]
|
17
|
+
}
|
18
|
+
|
19
|
+
def level=(level)
|
20
|
+
@level = level
|
21
|
+
end
|
22
|
+
|
23
|
+
def level
|
24
|
+
@level
|
25
|
+
end
|
26
|
+
|
27
|
+
def async=(async)
|
28
|
+
@async = async
|
29
|
+
end
|
30
|
+
|
31
|
+
def async
|
32
|
+
@async
|
33
|
+
end
|
34
|
+
|
35
|
+
def error(message)
|
36
|
+
__log(:error, message)
|
37
|
+
end
|
38
|
+
|
39
|
+
def warn(message)
|
40
|
+
__log(:warn, message)
|
41
|
+
end
|
42
|
+
|
43
|
+
def info(message)
|
44
|
+
__log(:info, message)
|
45
|
+
end
|
46
|
+
|
47
|
+
def debug(message)
|
48
|
+
__log(:verbose, message)
|
49
|
+
end
|
50
|
+
alias_method :verbose, :debug
|
51
|
+
|
52
|
+
def logging?(flag)
|
53
|
+
(LEVELS[level] & FLAGS[flag]) > 0
|
54
|
+
end
|
55
|
+
|
56
|
+
protected
|
57
|
+
def __log(flag, message)
|
58
|
+
return unless logging?(flag)
|
59
|
+
raise ArgumentError, "flag must be one of #{FLAGS.keys}" unless FLAGS.keys.include?(flag)
|
60
|
+
async_enabled = self.async || (self.level == :error)
|
61
|
+
|
62
|
+
log(async_enabled,
|
63
|
+
level:LEVELS[level],
|
64
|
+
flag:FLAGS[flag],
|
65
|
+
context:0,
|
66
|
+
file:__FILE__,
|
67
|
+
function:__method__,
|
68
|
+
line:__LINE__,
|
69
|
+
tag:0,
|
70
|
+
format:message)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
module Motion
|
75
|
+
class Log < DDLog
|
76
|
+
class << self
|
77
|
+
alias_method :flush, :flushLog
|
78
|
+
end
|
79
|
+
|
80
|
+
extend LoggerClassMethods
|
81
|
+
|
82
|
+
@async = true
|
83
|
+
@level = :info
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
require 'motion-cocoapods'
|
6
|
+
|
7
|
+
Motion::Project::App.setup do |app|
|
8
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'logger/*.rb')).each do |file|
|
9
|
+
app.files.unshift file
|
10
|
+
end
|
11
|
+
|
12
|
+
app.pods ||= Motion::Project::CocoaPods.new(app)
|
13
|
+
app.pods.dependency 'CocoaLumberjack'
|
14
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/logger/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Francis Chong"]
|
6
|
+
gem.email = ["francis@ignition.hk"]
|
7
|
+
gem.description = "A thin wrapper of CocoaLumberjack for RubyMotion."
|
8
|
+
gem.summary = "A thin wrapper of CocoaLumberjack for RubyMotion."
|
9
|
+
gem.homepage = "https://github.com/siuying/motion-logger"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "motion-logger"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = Motion::Logger::VERSION
|
16
|
+
|
17
|
+
gem.add_dependency 'motion-cocoapods', '>= 1.0.3'
|
18
|
+
gem.add_development_dependency 'motion-redgreen'
|
19
|
+
end
|
data/spec/log_spec.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
describe "Motion::Log" do
|
2
|
+
Log = Motion::Log
|
3
|
+
|
4
|
+
before do
|
5
|
+
@file_logger = DDFileLogger.new
|
6
|
+
@file_logger.rollingFrequency = 60 * 60 * 24
|
7
|
+
@file_logger.logFileManager.maximumNumberOfLogFiles = 1
|
8
|
+
Log.addLogger @file_logger
|
9
|
+
end
|
10
|
+
|
11
|
+
after do
|
12
|
+
Log.flush
|
13
|
+
@file_logger.logFileManager.unsortedLogFilePaths.each do |file|
|
14
|
+
File.delete(file)
|
15
|
+
end
|
16
|
+
Log.removeAllLoggers
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "FileLogger" do
|
20
|
+
it "should log with specific levels" do
|
21
|
+
Log.level = :warn
|
22
|
+
|
23
|
+
Log.info "Hello World"
|
24
|
+
Log.warn "WARNING!"
|
25
|
+
|
26
|
+
Log.level = :info
|
27
|
+
Log.info "Foo"
|
28
|
+
Log.debug "Lah"
|
29
|
+
Log.flush
|
30
|
+
|
31
|
+
file = @file_logger.logFileManager.sortedLogFilePaths.first
|
32
|
+
logs = open(file).read
|
33
|
+
logs.should.not.be.nil
|
34
|
+
logs.should.not.include "Hello World"
|
35
|
+
logs.should.include "WARNING!"
|
36
|
+
logs.should.include "Foo"
|
37
|
+
logs.should.not.include "Lah"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
data/vendor/Podfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# Xcode
|
2
|
+
build/*
|
3
|
+
*.pbxuser
|
4
|
+
!default.pbxuser
|
5
|
+
*.mode1v3
|
6
|
+
!default.mode1v3
|
7
|
+
*.mode2v3
|
8
|
+
!default.mode2v3
|
9
|
+
*.perspectivev3
|
10
|
+
!default.perspectivev3
|
11
|
+
*.xcworkspace
|
12
|
+
!default.xcworkspace
|
13
|
+
xcuserdata
|
14
|
+
profile
|
15
|
+
*.moved-aside
|
16
|
+
.DS_Store?
|
17
|
+
Icon?
|
18
|
+
|
19
|
+
# Thumbnails
|
20
|
+
._*
|
21
|
+
|
22
|
+
# Files that might appear on external disk
|
23
|
+
.Spotlight-V100
|
24
|
+
.Trashes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Pod::Spec.new do |s|
|
2
|
+
s.name = 'CocoaLumberjack'
|
3
|
+
s.version = '1.3.1'
|
4
|
+
s.license = 'BSD'
|
5
|
+
s.summary = 'A fast & simple, yet powerful & flexible logging framework for Mac and iOS.'
|
6
|
+
s.homepage = 'https://github.com/robbiehanson/CocoaLumberjack'
|
7
|
+
s.author = { 'Robbie Hanson' => 'robbiehanson@deusty.com' }
|
8
|
+
s.source = { :git => 'https://github.com/robbiehanson/CocoaLumberjack.git',
|
9
|
+
:tag => '1.3.1' }
|
10
|
+
|
11
|
+
s.description = 'It is similar in concept to other popular logging frameworks such as log4j, ' \
|
12
|
+
'yet is designed specifically for objective-c, and takes advantage of features ' \
|
13
|
+
'such as multi-threading, grand central dispatch (if available), lockless ' \
|
14
|
+
'atomic operations, and the dynamic nature of the objective-c runtime.'
|
15
|
+
|
16
|
+
s.source_files = 'Lumberjack'
|
17
|
+
s.clean_paths = 'Benchmarking', 'Xcode'
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Software License Agreement (BSD License)
|
2
|
+
|
3
|
+
Copyright (c) 2010, Deusty, LLC
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use of this software in source and binary forms,
|
7
|
+
with or without modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
* Redistributions of source code must retain the above
|
10
|
+
copyright notice, this list of conditions and the
|
11
|
+
following disclaimer.
|
12
|
+
|
13
|
+
* Neither the name of Deusty nor the names of its
|
14
|
+
contributors may be used to endorse or promote products
|
15
|
+
derived from this software without specific prior
|
16
|
+
written permission of Deusty, LLC.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#import <Foundation/Foundation.h>
|
2
|
+
#import <asl.h>
|
3
|
+
|
4
|
+
#import "DDLog.h"
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Welcome to Cocoa Lumberjack!
|
8
|
+
*
|
9
|
+
* The project page has a wealth of documentation if you have any questions.
|
10
|
+
* https://github.com/robbiehanson/CocoaLumberjack
|
11
|
+
*
|
12
|
+
* If you're new to the project you may wish to read the "Getting Started" wiki.
|
13
|
+
* https://github.com/robbiehanson/CocoaLumberjack/wiki/GettingStarted
|
14
|
+
*
|
15
|
+
*
|
16
|
+
* This class provides a logger for the Apple System Log facility.
|
17
|
+
*
|
18
|
+
* As described in the "Getting Started" page,
|
19
|
+
* the traditional NSLog() function directs it's output to two places:
|
20
|
+
*
|
21
|
+
* - Apple System Log
|
22
|
+
* - StdErr (if stderr is a TTY) so log statements show up in Xcode console
|
23
|
+
*
|
24
|
+
* To duplicate NSLog() functionality you can simply add this logger and a tty logger.
|
25
|
+
* However, if you instead choose to use file logging (for faster performance),
|
26
|
+
* you may choose to use a file logger and a tty logger.
|
27
|
+
**/
|
28
|
+
|
29
|
+
@interface DDASLLogger : DDAbstractLogger <DDLogger>
|
30
|
+
{
|
31
|
+
aslclient client;
|
32
|
+
}
|
33
|
+
|
34
|
+
+ (DDASLLogger *)sharedInstance;
|
35
|
+
|
36
|
+
// Inherited from DDAbstractLogger
|
37
|
+
|
38
|
+
// - (id <DDLogFormatter>)logFormatter;
|
39
|
+
// - (void)setLogFormatter:(id <DDLogFormatter>)formatter;
|
40
|
+
|
41
|
+
@end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#import "DDASLLogger.h"
|
2
|
+
|
3
|
+
#import <libkern/OSAtomic.h>
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Welcome to Cocoa Lumberjack!
|
7
|
+
*
|
8
|
+
* The project page has a wealth of documentation if you have any questions.
|
9
|
+
* https://github.com/robbiehanson/CocoaLumberjack
|
10
|
+
*
|
11
|
+
* If you're new to the project you may wish to read the "Getting Started" wiki.
|
12
|
+
* https://github.com/robbiehanson/CocoaLumberjack/wiki/GettingStarted
|
13
|
+
**/
|
14
|
+
|
15
|
+
#if ! __has_feature(objc_arc)
|
16
|
+
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
|
17
|
+
#endif
|
18
|
+
|
19
|
+
|
20
|
+
@implementation DDASLLogger
|
21
|
+
|
22
|
+
static DDASLLogger *sharedInstance;
|
23
|
+
|
24
|
+
/**
|
25
|
+
* The runtime sends initialize to each class in a program exactly one time just before the class,
|
26
|
+
* or any class that inherits from it, is sent its first message from within the program. (Thus the
|
27
|
+
* method may never be invoked if the class is not used.) The runtime sends the initialize message to
|
28
|
+
* classes in a thread-safe manner. Superclasses receive this message before their subclasses.
|
29
|
+
*
|
30
|
+
* This method may also be called directly (assumably by accident), hence the safety mechanism.
|
31
|
+
**/
|
32
|
+
+ (void)initialize
|
33
|
+
{
|
34
|
+
static BOOL initialized = NO;
|
35
|
+
if (!initialized)
|
36
|
+
{
|
37
|
+
initialized = YES;
|
38
|
+
|
39
|
+
sharedInstance = [[DDASLLogger alloc] init];
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
+ (DDASLLogger *)sharedInstance
|
44
|
+
{
|
45
|
+
return sharedInstance;
|
46
|
+
}
|
47
|
+
|
48
|
+
- (id)init
|
49
|
+
{
|
50
|
+
if (sharedInstance != nil)
|
51
|
+
{
|
52
|
+
return nil;
|
53
|
+
}
|
54
|
+
|
55
|
+
if ((self = [super init]))
|
56
|
+
{
|
57
|
+
// A default asl client is provided for the main thread,
|
58
|
+
// but background threads need to create their own client.
|
59
|
+
|
60
|
+
client = asl_open(NULL, "com.apple.console", 0);
|
61
|
+
}
|
62
|
+
return self;
|
63
|
+
}
|
64
|
+
|
65
|
+
- (void)logMessage:(DDLogMessage *)logMessage
|
66
|
+
{
|
67
|
+
NSString *logMsg = logMessage->logMsg;
|
68
|
+
|
69
|
+
if (formatter)
|
70
|
+
{
|
71
|
+
logMsg = [formatter formatLogMessage:logMessage];
|
72
|
+
}
|
73
|
+
|
74
|
+
if (logMsg)
|
75
|
+
{
|
76
|
+
const char *msg = [logMsg UTF8String];
|
77
|
+
|
78
|
+
int aslLogLevel;
|
79
|
+
switch (logMessage->logLevel)
|
80
|
+
{
|
81
|
+
// Note: By default ASL will filter anything above level 5 (Notice).
|
82
|
+
// So our mappings shouldn't go above that level.
|
83
|
+
|
84
|
+
case 1 : aslLogLevel = ASL_LEVEL_CRIT; break;
|
85
|
+
case 2 : aslLogLevel = ASL_LEVEL_ERR; break;
|
86
|
+
case 3 : aslLogLevel = ASL_LEVEL_WARNING; break;
|
87
|
+
default : aslLogLevel = ASL_LEVEL_NOTICE; break;
|
88
|
+
}
|
89
|
+
|
90
|
+
asl_log(client, NULL, aslLogLevel, "%s", msg);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
- (NSString *)loggerName
|
95
|
+
{
|
96
|
+
return @"cocoa.lumberjack.aslLogger";
|
97
|
+
}
|
98
|
+
|
99
|
+
@end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#import <Foundation/Foundation.h>
|
2
|
+
|
3
|
+
#import "DDLog.h"
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Welcome to Cocoa Lumberjack!
|
7
|
+
*
|
8
|
+
* The project page has a wealth of documentation if you have any questions.
|
9
|
+
* https://github.com/robbiehanson/CocoaLumberjack
|
10
|
+
*
|
11
|
+
* If you're new to the project you may wish to read the "Getting Started" wiki.
|
12
|
+
* https://github.com/robbiehanson/CocoaLumberjack/wiki/GettingStarted
|
13
|
+
*
|
14
|
+
*
|
15
|
+
* This class provides an abstract implementation of a database logger.
|
16
|
+
*
|
17
|
+
* That is, it provides the base implementation for a database logger to build atop of.
|
18
|
+
* All that is needed for a concrete database logger is to extend this class
|
19
|
+
* and override the methods in the implementation file that are prefixed with "db_".
|
20
|
+
**/
|
21
|
+
|
22
|
+
@interface DDAbstractDatabaseLogger : DDAbstractLogger {
|
23
|
+
@protected
|
24
|
+
NSUInteger saveThreshold;
|
25
|
+
NSTimeInterval saveInterval;
|
26
|
+
NSTimeInterval maxAge;
|
27
|
+
NSTimeInterval deleteInterval;
|
28
|
+
BOOL deleteOnEverySave;
|
29
|
+
|
30
|
+
BOOL saveTimerSuspended;
|
31
|
+
NSUInteger unsavedCount;
|
32
|
+
dispatch_time_t unsavedTime;
|
33
|
+
dispatch_source_t saveTimer;
|
34
|
+
dispatch_time_t lastDeleteTime;
|
35
|
+
dispatch_source_t deleteTimer;
|
36
|
+
}
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Specifies how often to save the data to disk.
|
40
|
+
* Since saving is an expensive operation (disk io) it is not done after every log statement.
|
41
|
+
* These properties allow you to configure how/when the logger saves to disk.
|
42
|
+
*
|
43
|
+
* A save is done when either (whichever happens first):
|
44
|
+
*
|
45
|
+
* - The number of unsaved log entries reaches saveThreshold
|
46
|
+
* - The amount of time since the oldest unsaved log entry was created reaches saveInterval
|
47
|
+
*
|
48
|
+
* You can optionally disable the saveThreshold by setting it to zero.
|
49
|
+
* If you disable the saveThreshold you are entirely dependent on the saveInterval.
|
50
|
+
*
|
51
|
+
* You can optionally disable the saveInterval by setting it to zero (or a negative value).
|
52
|
+
* If you disable the saveInterval you are entirely dependent on the saveThreshold.
|
53
|
+
*
|
54
|
+
* It's not wise to disable both saveThreshold and saveInterval.
|
55
|
+
*
|
56
|
+
* The default saveThreshold is 500.
|
57
|
+
* The default saveInterval is 60 seconds.
|
58
|
+
**/
|
59
|
+
@property (assign, readwrite) NSUInteger saveThreshold;
|
60
|
+
@property (assign, readwrite) NSTimeInterval saveInterval;
|
61
|
+
|
62
|
+
/**
|
63
|
+
* It is likely you don't want the log entries to persist forever.
|
64
|
+
* Doing so would allow the database to grow infinitely large over time.
|
65
|
+
*
|
66
|
+
* The maxAge property provides a way to specify how old a log statement can get
|
67
|
+
* before it should get deleted from the database.
|
68
|
+
*
|
69
|
+
* The deleteInterval specifies how often to sweep for old log entries.
|
70
|
+
* Since deleting is an expensive operation (disk io) is is done on a fixed interval.
|
71
|
+
*
|
72
|
+
* An alternative to the deleteInterval is the deleteOnEverySave option.
|
73
|
+
* This specifies that old log entries should be deleted during every save operation.
|
74
|
+
*
|
75
|
+
* You can optionally disable the maxAge by setting it to zero (or a negative value).
|
76
|
+
* If you disable the maxAge then old log statements are not deleted.
|
77
|
+
*
|
78
|
+
* You can optionally disable the deleteInterval by setting it to zero (or a negative value).
|
79
|
+
*
|
80
|
+
* If you disable both deleteInterval and deleteOnEverySave then old log statements are not deleted.
|
81
|
+
*
|
82
|
+
* It's not wise to enable both deleteInterval and deleteOnEverySave.
|
83
|
+
*
|
84
|
+
* The default maxAge is 7 days.
|
85
|
+
* The default deleteInterval is 5 minutes.
|
86
|
+
* The default deleteOnEverySave is NO.
|
87
|
+
**/
|
88
|
+
@property (assign, readwrite) NSTimeInterval maxAge;
|
89
|
+
@property (assign, readwrite) NSTimeInterval deleteInterval;
|
90
|
+
@property (assign, readwrite) BOOL deleteOnEverySave;
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Forces a save of any pending log entries (flushes log entries to disk).
|
94
|
+
**/
|
95
|
+
- (void)savePendingLogEntries;
|
96
|
+
|
97
|
+
/**
|
98
|
+
* Removes any log entries that are older than maxAge.
|
99
|
+
**/
|
100
|
+
- (void)deleteOldLogEntries;
|
101
|
+
|
102
|
+
@end
|