Skip to content

Commit

Permalink
Merge pull request #12431 from keymanapp/change/mac/11525-remove-verb…
Browse files Browse the repository at this point in the history
…ose-logging

change(mac): remove verbose logging option
  • Loading branch information
sgschantz authored Sep 20, 2024
2 parents 6c491a6 + 7f7bbd4 commit d28c2f3
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 214 deletions.
21 changes: 1 addition & 20 deletions mac/Keyman4Mac/Keyman4Mac/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#import "AppDelegate.h"
#import <KeymanEngine4Mac/KeymanEngine4Mac.h>

static BOOL debugMode = YES;

BOOL isKeyMapEnabled;
const unsigned short keyMapSize = 0x80;

Expand Down Expand Up @@ -47,8 +45,6 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSArray *kvkFiles = [self KVKFiles];
for (NSString *path in kvkFiles){
KVKFile *kvkFile = [[KVKFile alloc] initWithFilePath:path];
if (debugMode)
NSLog(@"%@", kvkFile);
}*/
}

Expand Down Expand Up @@ -116,7 +112,7 @@ CGEventRef eventTapFunction(CGEventTapProxy proxy, CGEventType type, CGEventRef
NSLog(@"AppDelegate eventTapFunction key down event: %@", event);
// Key down event
NSEvent *mEvent = [NSEvent eventWithCGEvent:event];
KMEngine *kme = [[KMEngine alloc] initWithKMX:kmx context:contextBuffer verboseLogging:debugMode];
KMEngine *kme = [[KMEngine alloc] initWithKMX:kmx context:contextBuffer];
CoreKeyOutput *coreKeyOutput = [kme processEvent:mEvent];
if (coreKeyOutput) {
if (coreKeyOutput.hasTextToInsert) {
Expand Down Expand Up @@ -227,18 +223,6 @@ - (void)comboBoxSelectionDidChange:(NSNotification *)notification {
NSLog(@"%d: %@", index, kmStore);
index++;
}

for (NSObject *gp in kmx.group) {
if (debugMode) {
NSLog(@"Group %@", gp);
//NSLog(@"match = %@", gp.match);
//NSLog(@"nomatch = %@", gp.noMatch);
/*
for (KMCompKey *kmKey in gp.keys) {
NSLog(@"\nKey: %@", kmKey);
}*/
}
}
}
}

Expand All @@ -259,9 +243,6 @@ - (void)setKMXList {
if (!infoDict)
continue;

//if (debugMode)
// NSLog(@"%@", infoDict);
//NSString *str = [NSString stringWithFormat:@"%@ (%@)", [infoDict objectForKey:kKMKeyboardNameKey], [infoDict objectForKey:kKMKeyboardVersionKey]];
NSString *str = [infoDict objectForKey:kKMKeyboardNameKey];
[kmxDesc addObject:str];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22689"/>
<plugIn identifier="com.apple.WebKitIBPlugin" version="22689"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22690"/>
<plugIn identifier="com.apple.WebKitIBPlugin" version="22690"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
Expand All @@ -13,8 +13,6 @@
<outlet property="supportForward" destination="OSG-wW-VHs" id="8dG-cd-ByI"/>
<outlet property="supportHome" destination="RUX-eW-d6h" id="i5g-Lo-6zG"/>
<outlet property="tableView" destination="epz-Md-JOY" id="fHy-6f-hXN"/>
<outlet property="useVerboseLoggingCheckBox" destination="uWx-3J-U0D" id="deO-CV-6KJ"/>
<outlet property="verboseLoggingInfo" destination="PiJ-pY-UY7" id="o0X-ZY-NKX"/>
<outlet property="webView" destination="gTQ-rF-m9S" id="u7r-Sf-QKb"/>
<outlet property="window" destination="F0z-JX-Cv5" id="gIp-Ho-8D9"/>
</connections>
Expand Down Expand Up @@ -209,29 +207,6 @@
<view key="view" id="N1x-px-93m">
<rect key="frame" x="10" y="33" width="754" height="538"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button toolTip="Turn this on if you are having problems with a specific keyboard or with Keyman in general." verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="uWx-3J-U0D">
<rect key="frame" x="15" y="483" width="200" height="18"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="check" title="Use verbose Console logging" bezelStyle="regularSquare" imagePosition="left" inset="2" id="7J6-zy-R20">
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<connections>
<action selector="useVerboseLoggingCheckBoxAction:" target="-2" id="DGX-fy-5qP"/>
</connections>
</button>
<textField hidden="YES" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="PiJ-pY-UY7">
<rect key="frame" x="34" y="414" width="705" height="63"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" sendsActionOnEndEditing="YES" id="MrI-GM-7d6">
<font key="font" metaFont="system"/>
<string key="title">When the verbose logging option is on, Keyman will log actions that might help Keyman Support diagnose a problem. The Console program can be used to see a log of messages from Keyman. In Console, filter to show all messages from the "Keyman" process. This log can be exported and sent to Keyman support if needed.</string>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
</view>
</tabViewItem>
<tabViewItem label="Support" identifier="3" id="93O-x6-RLF">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
@interface KMConfigurationWindowController ()
@property (nonatomic, weak) IBOutlet NSTableView *tableView;
@property (nonatomic, weak) IBOutlet WebView *webView;
@property (nonatomic, weak) IBOutlet NSButton *useVerboseLoggingCheckBox;
@property (nonatomic, weak) IBOutlet NSTextField *verboseLoggingInfo;
@property (nonatomic, weak) IBOutlet NSButton *supportBack;
@property (nonatomic, weak) IBOutlet NSButton *supportForward;
@property (nonatomic, weak) IBOutlet NSButton *supportHome;
Expand Down Expand Up @@ -68,8 +66,6 @@ - (void)windowDidLoad {

NSURL *homeUrl = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html" subdirectory:@"Help"];
[self.webView.mainFrame loadRequest:[NSURLRequest requestWithURL:homeUrl]];

[self.useVerboseLoggingCheckBox setState:(self.AppDelegate.useVerboseLogging ? NSOnState : NSOffState)];
}

- (void)webView:(WebView *)sender decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id<WebPolicyDecisionListener>)listener {
Expand Down Expand Up @@ -437,13 +433,6 @@ - (IBAction)downloadAction:(id)sender {
[self.AppDelegate.downloadKBWindow.window makeKeyAndOrderFront:nil];
}

- (IBAction)useVerboseLoggingCheckBoxAction:(id)sender {
NSButton *checkBox = (NSButton *)sender;
BOOL verboseLoggingOn = checkBox.state == NSOnState;
[self.AppDelegate setUseVerboseLogging:verboseLoggingOn];
[self.verboseLoggingInfo setHidden:!verboseLoggingOn];
}

- (void)handleRequestToInstallPackage:(KMPackage *) package {
os_log_debug([KMLogs dataLog], "handleRequestToInstallPackage");
NSString *keyboardInfoString = NSLocalizedString(@"info-install-keyboard-filename", nil);
Expand Down
2 changes: 0 additions & 2 deletions mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ static const int KEYMAN_FIRST_KEYBOARD_MENUITEM_INDEX = 0;
@property (nonatomic, strong) NSString *downloadFilename;
@property (nonatomic, strong) NSMutableData *receivedData;
@property (nonatomic, assign) NSUInteger expectedBytes;
@property (nonatomic, assign) BOOL useVerboseLogging;
@property (nonatomic, assign) BOOL useNullChar;
@property (nonatomic, assign) BOOL debugMode;

- (NSMenu *)menu;
- (void)saveActiveKeyboards;
Expand Down
30 changes: 3 additions & 27 deletions mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,7 @@ @implementation KMInputMethodAppDelegate

- (id)init {
self = [super init];
if (self) {
#ifdef DEBUG
// If debugging, we'll turn it on by default, regardless of setting. If developer
// really wants it off, they can either change this line of code temporarily or
// go to the config screen and turn it off explicitly.
_debugMode = YES;
#else
_debugMode = self.useVerboseLogging;
#endif

if (self) {
// first notify user and request access to Accessibility/PostEvent permissions
// pass block as completion handler to complete init with initCompletion
[PrivacyConsent.shared requestPrivacyAccess:^void (void){
Expand Down Expand Up @@ -384,7 +375,7 @@ - (NSMenu *)menu {

- (KMEngine *)kme {
if (_kme == nil) {
_kme = [[KMEngine alloc] initWithKMX:nil context:self.contextBuffer verboseLogging:self.debugMode];
_kme = [[KMEngine alloc] initWithKMX:nil context:self.contextBuffer];
}

return _kme;
Expand Down Expand Up @@ -441,19 +432,6 @@ - (NSString *)oskWindowTitle {
return [NSString stringWithFormat:@"%@ - Keyman", _keyboardName];
}

- (void)setUseVerboseLogging:(BOOL)useVerboseLogging {
os_log_debug([KMLogs configLog], "Turning verbose logging %{public}@", useVerboseLogging ? @"on." : @"off.");
_debugMode = useVerboseLogging;
if (_kme != nil)
[_kme setUseVerboseLogging:useVerboseLogging];

[[KMSettingsRepository shared] writeUseVerboseLogging:useVerboseLogging];
}

- (BOOL)useVerboseLogging {
return [[KMSettingsRepository shared] readUseVerboseLogging];
}

#pragma mark - Keyman Data

/**
Expand Down Expand Up @@ -769,9 +747,7 @@ - (void)addDynamicKeyboardMenuItems {
NSString *keyboardMenuName = @"";
int menuItemIndex = KEYMAN_FIRST_KEYBOARD_MENUITEM_INDEX;

if (self.debugMode) {
os_log_info([KMLogs configLog], "*** populateKeyboardMenuItems, number of active keyboards=%lu", self.activeKeyboards.count);
}
os_log_debug([KMLogs configLog], "*** populateKeyboardMenuItems, number of active keyboards=%lu", self.activeKeyboards.count);

// loop through the active keyboards list and add them to the menu
for (NSString *path in self.activeKeyboards) {
Expand Down
15 changes: 8 additions & 7 deletions mac/Keyman4MacIM/Keyman4MacIM/KMInputMethodEventHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@ - (instancetype)initWithClient:(NSString *)clientAppId client:(id) sender {
_lowLevelBackspaceCount = 0;
_queuedText = nil;

// In Xcode, if Keyman is the active IM and is in "debugMode" and "English plus Spanish" is
// the current keyboard and you type "Sentry force now", it will force a simulated crash to
BOOL forceSentryCrash = [KMSettingsRepository.shared readForceSentryError];

// In Xcode, if Keyman is the active IM and the settings include the
// forceSentryCrash flag and "English plus Spanish" is the current keyboard
// and you type "Sentry force now", it will force a simulated crash to
// test reporting to sentry.keyman.com
if ([self.appDelegate debugMode] && [clientAppId isEqual: @"com.apple.dt.Xcode"]) {
os_log_debug([KMLogs testLog], "Sentry - Preparing to detect Easter egg.");
if (forceSentryCrash && [clientAppId isEqual: @"com.apple.dt.Xcode"]) {
os_log_debug([KMLogs testLog], "initWithClient, preparing to force Sentry crash.");
_easterEggForSentry = [[NSMutableString alloc] init];
}
else
Expand All @@ -66,9 +69,7 @@ - (void)deactivate {
if (_generatedBackspaceCount > 0 || (_queuedText != nil && _queuedText.length > 0) ||
_keyCodeOfOriginalEvent != 0 || _sourceFromOriginalEvent != nil)
{
if ([self.appDelegate debugMode]) {
os_log_error([KMLogs lifecycleLog], "ERROR: new app activated before previous app finished processing pending events! _generatedBackspaceCount: %lu, _queuedText: '%{public}@' _keyCodeOfOriginalEvent: %hu", _generatedBackspaceCount, _queuedText == nil ? @"(NIL)" : (NSString*)[self queuedText], _keyCodeOfOriginalEvent);
}
os_log_error([KMLogs lifecycleLog], "ERROR: new app activated before previous app finished processing pending events! _generatedBackspaceCount: %lu, _queuedText: '%{public}@' _keyCodeOfOriginalEvent: %hu", _generatedBackspaceCount, _queuedText == nil ? @"(NIL)" : (NSString*)[self queuedText], _keyCodeOfOriginalEvent);
_keyCodeOfOriginalEvent = 0;
_generatedBackspaceCount = 0;
_queuedText = nil;
Expand Down
3 changes: 1 addition & 2 deletions mac/Keyman4MacIM/Keyman4MacIM/KMSettingsRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)writeOptionForSelectedKeyboard:(NSString *)key withValue:(NSString*)value;
- (BOOL)readShowOskOnActivate;
- (void)writeShowOskOnActivate:(BOOL)show;
- (BOOL)readUseVerboseLogging;
- (void)writeUseVerboseLogging:(BOOL)verboseLogging;
- (BOOL)readForceSentryError;
@end

NS_ASSUME_NONNULL_END
16 changes: 8 additions & 8 deletions mac/Keyman4MacIM/Keyman4MacIM/KMSettingsRepository.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
NSString *const kSelectedKeyboardKey = @"KMSelectedKeyboardKey";
NSString *const kPersistedOptionsKey = @"KMPersistedOptionsKey";
NSString *const kShowOskOnActivate = @"KMShowOskOnActivate";
NSString *const kUseVerboseLogging = @"KMUseVerboseLogging";
NSString *const kForceSentryError = @"KMForceSentryError";

/**
* The following constant "KMSavedStoresKey" is left here for documentation
Expand All @@ -30,6 +30,11 @@
* but the related UI has been removed according to issue #12342
*/
NSString *const kAlwaysShowOSKKey = @"KMAlwaysShowOSKKey";
/**
* The following constant "KMUseVerboseLogging" is left here for documentation
* but it is obsolete and removed issue #11525
*/
NSString *const kUseVerboseLogging = @"KMUseVerboseLogging";

NSString *const kObsoletePathComponent = @"/Documents/Keyman-Keyboards";
NSString *const kNewPathComponent = @"/Library/Application Support/keyman.inputmethod.Keyman/";
Expand Down Expand Up @@ -321,14 +326,9 @@ - (void)writeShowOskOnActivate:(BOOL)show {
[userData setBool:show forKey:kShowOskOnActivate];
}

- (BOOL)readUseVerboseLogging {
NSUserDefaults *userData = [NSUserDefaults standardUserDefaults];
return [userData boolForKey:kUseVerboseLogging];
}

- (void)writeUseVerboseLogging:(BOOL)verboseLogging {
- (BOOL)readForceSentryError {
NSUserDefaults *userData = [NSUserDefaults standardUserDefaults];
[userData setBool:verboseLogging forKey:kUseVerboseLogging];
return [userData boolForKey:kForceSentryError];
}

@end
1 change: 0 additions & 1 deletion mac/Keyman4MacIM/KeymanTests/TestAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ typedef void(^PostEventCallback)(CGEventRef eventToPost);
@property (nonatomic, assign) CFMachPortRef lowLevelEventTap; // Always nil for tests
@property (nonatomic, assign) BOOL contextChangingEventDetected;
@property (nonatomic, assign) BOOL useNullChar;
@property (nonatomic, assign) BOOL debugMode;
@property (nonatomic, assign) CGKeyCode virtualKeyPosted;

// Helper method
Expand Down
6 changes: 1 addition & 5 deletions mac/Keyman4MacIM/KeymanTests/TestAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ @implementation TestAppDelegate

- (KMEngine *)kme {
if (_kme == nil) {
_kme = [[KMEngine alloc] initWithKMX:nil context:self.contextBuffer verboseLogging:self.debugMode];
_kme = [[KMEngine alloc] initWithKMX:nil context:self.contextBuffer];
}

return _kme;
Expand All @@ -42,10 +42,6 @@ - (void)setContextBuffer:(NSMutableString *)contextBuffer {
[self.kme setCoreContextIfNeeded:self.contextBuffer];
}

- (BOOL)debugMode {
return YES;
}

-(NSEvent *)keyStrokeEventForCharacter:(NSString *)character keyCode:(unsigned short) keyCode {
return [NSEvent keyEventWithType:NSEventTypeKeyDown location:NSZeroPoint modifierFlags:0 timestamp:NSTimeIntervalSince1970 windowNumber:0 context:nil characters:character charactersIgnoringModifiers:character isARepeat:NO keyCode:keyCode];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ extern UInt32 VirtualKeyMap[0x80];

@interface CoreHelper : NSObject

@property (assign, nonatomic) BOOL debugMode;

-(unichar const *) createUnicharStringFromNSString:(NSString *)string;
-(NSString *) createNSStringFromUnicharString:(unichar const *)string;
-(unsigned long long) unicharStringLength:(unichar const *)string;

-(instancetype)initWithDebugMode:(BOOL)debugMode;
-(unsigned short) macVirtualKeyToWindowsVirtualKey:(unsigned short) keyCode;
-(UTF32Char)macToKeymanModifier:(NSEventModifierFlags)modifiers;
-(NSString*)utf32ValueToString:(UTF32Char)scalarValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ -(unsigned long) scalarValueStringLength:(UTF32Char const *)string {
return length;
}

-(instancetype)initWithDebugMode:(BOOL)debugMode {
-(instancetype)init {
self = [super init];
if (self) {
_debugMode = debugMode;
[self initVirtualKeyMapping];
}
return self;
Expand Down
4 changes: 1 addition & 3 deletions mac/KeymanEngine4Mac/KeymanEngine4Mac/KME/KMEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,14 @@
@interface KMEngine : NSObject

@property (weak, nonatomic) KMXFile *kmx;
@property (assign, nonatomic) BOOL debugMode;

- (id)initWithKMX:(KMXFile *)kmx context:(NSString *)ctxBuf verboseLogging:(BOOL)enableDebugLogging;
- (id)initWithKMX:(KMXFile *)kmx context:(NSString *)ctxBuf;
- (NSString *)getCoreContextDebug;
- (void)clearCoreContext;
- (void)setCoreContextIfNeeded:(NSString *)context;

- (void)setCoreOptions:(NSString *)key withValue:(NSString *)value;
- (CoreKeyOutput *)processEvent:(NSEvent *)event;
- (void)setUseVerboseLogging:(BOOL)useVerboseLogging;

@end

Expand Down
Loading

0 comments on commit d28c2f3

Please sign in to comment.