diff --git a/Sparkle/SULog.m b/Sparkle/SULog.m index 188a3a85..c850eb02 100644 --- a/Sparkle/SULog.m +++ b/Sparkle/SULog.m @@ -8,15 +8,27 @@ #include "SULog.h" #include +#include "SUExport.h" #ifdef _APPKITDEFINES_H #error This is a "core" implementation and should NOT import AppKit #endif +void _SULogDisableStandardErrorStream(void); +static BOOL gDisableStandardErrorStream; + // For converting constants to string literals using the preprocessor #define STRINGIFY(x) #x #define TO_STRING(x) STRINGIFY(x) +// Private API for disable logging to standard error stream +// We don't want to do this normally unless eg: releasing a command line utility, +// because it may be useful for error output to show up in an immediately visible terminal/panel +SU_EXPORT void _SULogDisableStandardErrorStream(void) +{ + gDisableStandardErrorStream = YES; +} + void SULog(NSString *format, ...) { static aslclient client; @@ -25,8 +37,11 @@ void SULog(NSString *format, ...) dispatch_once(&onceToken, ^{ NSBundle *mainBundle = [NSBundle mainBundle]; NSString *displayName = [[NSFileManager defaultManager] displayNameAtPath:mainBundle.bundlePath]; -#warning Can there be a better approach than always outputting to stderr? - uint32_t options = ASL_OPT_NO_DELAY | ASL_OPT_STDERR; + + uint32_t options = ASL_OPT_NO_DELAY; + if (!gDisableStandardErrorStream) { + options |= ASL_OPT_STDERR; + } client = asl_open([displayName stringByAppendingString:@" [Sparkle]"].UTF8String, mainBundle.bundleIdentifier.UTF8String, options); queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); }); diff --git a/sparkle-cli/SUCommandLineDriver.m b/sparkle-cli/SUCommandLineDriver.m index a2be123b..2f4ab442 100644 --- a/sparkle-cli/SUCommandLineDriver.m +++ b/sparkle-cli/SUCommandLineDriver.m @@ -10,6 +10,8 @@ #import #import "SUCommandLineUserDriver.h" +void _SULogDisableStandardErrorStream(void); + @interface SUCommandLineDriver () @property (nonatomic, readonly) SUUpdater *updater; @@ -52,6 +54,10 @@ _applicationBundlePath = applicationBundle.bundlePath; +#ifndef DEBUG + _SULogDisableStandardErrorStream(); +#endif + id userDriver = [[SUCommandLineUserDriver alloc] initWithApplicationBundle:applicationBundle updatePermission:updatePermission deferInstallation:deferInstallation verbose:verbose]; _updater = [[SUUpdater alloc] initWithHostBundle:updateBundle userDriver:userDriver delegate:self]; }