Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added CouchbaseMobile.logLevel property

Logging defaults to level 0, i.e. none. Higher values enable various Erlang and CouchDB logs.
Currently level 0 doesn't disable all logging, because there are various log messages in our Erlang patches
 that just write to stderr without going through any log facility. We should fix those later.

Change-Id: I886e03e90dac6338da39cce6e42581893cb4dea8
Reviewed-on: http://review.couchbase.org/10594
Tested-by: Farshid Ghods <farshid.ghods@gmail.com>
Reviewed-by: Jens Alfke <jens@couchbase.com>
  • Loading branch information...
commit 5f9793d894f70872007a557fb36004a137b2bcc2 1 parent 30e4d12
@snej snej authored
View
5 EmptyApp/Source/EmptyAppDelegate.m
@@ -34,9 +34,10 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
// Initialize CouchDB:
CouchbaseMobile* cb = [[CouchbaseMobile alloc] init];
cb.delegate = self;
+ cb.logLevel = 2; // Enable Erlang errors and CouchDB info
NSString* iniPath = [[NSBundle mainBundle] pathForResource: @"app" ofType: @"ini"];
if (iniPath) {
- NSLog(@"Registering custom .ini file %@", iniPath);
+ NSLog(@"Empty App: Registering custom .ini file %@", iniPath);
cb.iniFilePath = iniPath;
}
NSAssert([cb start], @"Couchbase couldn't start! Error = %@", cb.error);
@@ -66,7 +67,7 @@ - (void)applicationWillTerminate:(UIApplication *)application {
-(void)couchbaseMobile:(CouchbaseMobile*)couchbase didStart:(NSURL*)serverURL {
- NSLog(@"CouchDB is Ready, go!");
+ NSLog(@"Empty App: CouchDB is Ready, go!");
NSLog(@"My local IP address is %@", self.localIPAddress);
self.serverURL = serverURL;
View
6 Framework/Classes/CouchbaseMobile.h
@@ -47,6 +47,7 @@
NSString* _iniFilePath;
NSURL* _serverURL;
NSError* _error;
+ uint8_t _logLevel;
BOOL _autoRestart;
BOOL _started;
}
@@ -110,6 +111,11 @@
emptying the file at this path before calling -start.*/
@property (readonly) NSString* localIniFilePath;
+/** Controls the amount of logging by Erlang and CouchDB.
+ Defaults to 0, meaning none.
+ 1 logs errors only, 2 also logs CouchDB info (like HTTP requests), 3 logs Erlang 'progress'. */
+@property uint8_t logLevel;
+
/** Copies a database file into the databaseDirectory if no such file exists there already.
Call this before -start, to set up initial contents of one or more databases on first run. */
- (BOOL) installDefaultDatabase: (NSString*)databasePath;
View
55 Framework/Classes/CouchbaseMobile.m
@@ -119,7 +119,7 @@ - (void)dealloc {
}
-@synthesize delegate = _delegate, iniFilePath = _iniFilePath, serverURL = _serverURL, error = _error, autoRestart = _autoRestart;
+@synthesize delegate = _delegate, iniFilePath = _iniFilePath, serverURL = _serverURL, error = _error, autoRestart = _autoRestart, logLevel = _logLevel;
- (NSString*) rootDirectory {
return _rootDirectory;
@@ -162,9 +162,11 @@ - (BOOL)start
return YES;
_timeStarted = CFAbsoluteTimeGetCurrent();
- NSLog(@"Couchbase: Starting CouchDB, using runtime files at: %@ (built %s, %s)",
- _bundlePath, __DATE__, __TIME__);
- NSLog(@"Couchbase: Storing data in %@", _rootDirectory);
+ if (_logLevel >= 2) {
+ NSLog(@"Couchbase: Starting CouchDB, using runtime files at: %@ (built %s, %s)",
+ _bundlePath, __DATE__, __TIME__);
+ NSLog(@"Couchbase: Storing data in %@", _rootDirectory);
+ }
if(![self createDir: self.logDirectory]
|| ![self createDir: self.databaseDirectory]
@@ -199,27 +201,36 @@ - (void) restart {
postNotificationName:kInternalRestartCouchNotification object:nil];
}
+
#pragma mark LAUNCHING ERLANG:
// Body of the pthread that runs Erlang (and CouchDB)
- (void)erlangThread {
- char* erlang_args[15] = {"beam", "--", "-noinput",
- "-sasl", "errlog_type", "error", // Change "error" to "all" to re-enable progress reports
+ const char* erlang_args[21] = {"beam", "--", "-noinput",
+ "-kernel", "error_logger", NULL /*kernel log*/,
+ "-sasl", "errlog_type", NULL /*log level*/,
+ "-sasl", "sasl_error_logger", NULL /*log type*/,
"-eval", "R = application:start(couch), io:format(\"~w~n\",[R]).",
"-root", NULL, "-couch_ini", NULL, NULL, NULL, NULL};
int erlang_argc;
{
+ // Log level. 0 is silent, 1-2 shows errors, 3 shows progress.
+ // (The difference between 1 and 2 is that 2 shows CouchDB [info] logs; see below
+ erlang_args[5] = _logLevel > 0 ? "tty" : "silent";
+ erlang_args[8] = _logLevel >= 3 ? "progress" : "error";
+ erlang_args[11] = _logLevel > 0 ? "tty" : "false";
+
// Alloc some paths to pass in as args to erl_start:
NSAutoreleasePool* pool = [NSAutoreleasePool new];
char* erl_root = strdup([[_bundlePath stringByAppendingPathComponent:@"erlang"]
fileSystemRepresentation]);
- erlang_args[9] = erl_root;
+ erlang_args[15] = erl_root;
// Yes, there are up to four layers of .ini files: Default, iOS, app, local.
- erlang_args[11] = strdup([[_bundlePath stringByAppendingPathComponent:@"default.ini"]
+ erlang_args[17] = strdup([[_bundlePath stringByAppendingPathComponent:@"default.ini"]
fileSystemRepresentation]);
- erlang_args[12] = strdup([[_rootDirectory stringByAppendingPathComponent:
+ erlang_args[18] = strdup([[_rootDirectory stringByAppendingPathComponent:
@"default_ios.ini"] fileSystemRepresentation]);
- erlang_argc = 13;
+ erlang_argc = 19;
if (_iniFilePath)
erlang_args[erlang_argc++] = strdup([_iniFilePath fileSystemRepresentation]);
erlang_args[erlang_argc++] = strdup([self.localIniFilePath fileSystemRepresentation]);
@@ -237,7 +248,7 @@ - (void)erlangThread {
[pool drain];
}
- erl_start(erlang_argc, erlang_args); // This never returns (unless Erlang exits)
+ erl_start(erlang_argc, (char**)erlang_args); // This never returns (unless Erlang exits)
}
@@ -261,8 +272,9 @@ - (void)notifyCouchStarted:(NSDictionary*)info {
NSURL* serverURL = urlStr ? [NSURL URLWithString:urlStr] : nil;
NSError* error = nil;
if (serverURL) {
- NSLog(@"Couchbase: CouchDB is up and running after %.3f sec at <%@>",
- (CFAbsoluteTimeGetCurrent() - _timeStarted), serverURL);
+ if (_logLevel >= 2)
+ NSLog(@"Couchbase: CouchDB is up and running after %.3f sec at <%@>",
+ (CFAbsoluteTimeGetCurrent() - _timeStarted), serverURL);
} else {
NSLog(@"Couchbase: Error: CouchDB returned invalid server URL");
error = [NSError errorWithDomain:@"Couchbase" code:1 userInfo:nil]; //TODO: Real error
@@ -294,7 +306,8 @@ - (BOOL)createDir:(NSString*)dirName {
NSError* createError = nil;
if([fm createDirectoryAtPath:dirName withIntermediateDirectories:YES
attributes:nil error:&createError]) {
- NSLog(@"Couchbase: Created dir %@", dirName);
+ if (_logLevel >= 2)
+ NSLog(@"Couchbase: Created dir %@", dirName);
} else {
NSLog(@"Couchbase: Error creating dir '%@': %@", dirName, createError);
self.error = createError;
@@ -359,7 +372,8 @@ - (BOOL)installItemNamed:(NSString*)name
// OK, do the copy:
if ([fm copyItemAtPath: source toPath: target error: &error]) {
- NSLog(@"Couchbase: Installed %@ into %@", [name lastPathComponent], target);
+ if (_logLevel >= 2)
+ NSLog(@"Couchbase: Installed %@ into %@", [name lastPathComponent], target);
return YES;
} else {
NSLog(@"Couchbase: Error installing to %@: %@", target, error);
@@ -400,10 +414,14 @@ - (BOOL)installTemplateNamed:(NSString*)name
return NO;
}
- [contents replaceOccurrencesOfString: @"$APPDIR"
- withString: [[NSBundle mainBundle] bundlePath]
+ [contents replaceOccurrencesOfString: @"$LOGLEVEL"
+ withString: (_logLevel >= 2 ? @"info" : @"none")
options: 0
range: NSMakeRange(0, contents.length)];
+ [contents replaceOccurrencesOfString: @"$APPDIR"
+ withString: [[NSBundle mainBundle] bundlePath]
+ options: 0
+ range: NSMakeRange(0, contents.length)];
[contents replaceOccurrencesOfString: @"$BUNDLEDIR"
withString: _bundlePath
options: 0
@@ -420,7 +438,8 @@ - (BOOL)installTemplateNamed:(NSString*)name
return YES; // No need to copy
if ([newData writeToFile: target options: NSDataWritingFileProtectionNone error: &error]) {
- NSLog(@"Couchbase: Installed customized %@ into %@", [name lastPathComponent], target);
+ if (_logLevel >= 2)
+ NSLog(@"Couchbase: Installed customized %@ into %@", [name lastPathComponent], target);
return YES;
} else {
NSLog(@"Couchbase: Error installing to %@: %@", target, error);
View
2  Framework/Resources/default_ios.ini
@@ -15,6 +15,7 @@
; This file is preprocessed before being shown to CouchDB:
; $INSTALLDIR --> Application's 'Documents' directory
; $BUNDLEDIR --> The "CouchbaseResources" directory in the app bundle
+; $LOGLEVEL --> The log level CouchDB should use ('none' or 'info')
;
[couchdb]
@@ -23,6 +24,7 @@ view_index_dir = $INSTALLDIR/couchdb
uri_file = $INSTALLDIR/couch.uri
[log]
+level = $LOGLEVEL
file = $INSTALLDIR/log/couch.log
[view_server_emonk]
Please sign in to comment.
Something went wrong with that request. Please try again.