Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clean up macOS preview log output #2823

Merged
merged 3 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion packages/shorebird_cli/lib/src/commands/preview_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,37 @@ This is only applicable when previewing Android releases.''',
final logs = await open.newApplication(path: appDirectory.path);
final completer = Completer<void>();

// Filter out extra noise from the logs.
final logFilters = [
RegExp(r'\[com\.apple.*\]'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised macos doesn't have an easy way to do the opposite and just filter for the flutter stuff 🤷 But I guess that would require running a separate process since this is just a direct dump from stdout/stderr.

RegExp(r'\(RunningBoardServices\)'),
RegExp(r'\(CoreFoundation\)'),
RegExp(r'\(TCC\)'),
RegExp(r'\(Metal\)'),
RegExp('^Timestamp'),
RegExp('^Filtering the log data'),
];

// Removes the log prefix from the log line.
// Example log line:
// ignore: lines_longer_than_80_chars
// 2025-01-31 09:53:22.889 Df macos_sandbox[22535:1d268] [dev.shorebird:updater::cache::patch_manager] [shorebird] No public key provided, skipping signature verification
final prefixRegex = RegExp(
r'^[\d-]+\W+[\d:\.]+\W+\w+\W+\w+\[[\da-f]+:[\da-f]+\]',
);
String removeLogPrefix(String line) {
return line.trim().replaceFirst(prefixRegex, '').trim();
}

logs.listen(
(log) => logger.info(utf8.decode(log)),
(log) {
final logLine = utf8.decode(log);
if (logFilters.any((filter) => filter.hasMatch(logLine))) {
return;
}

logger.info(removeLogPrefix(logLine));
},
onDone: completer.complete,
);

Expand Down
41 changes: 41 additions & 0 deletions packages/shorebird_cli/test/src/commands/preview_command_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// cspell:words libinfo networkd
import 'dart:async';
import 'dart:convert';
import 'dart:io' hide Platform;
Expand Down Expand Up @@ -2146,6 +2147,46 @@ channel: ${DeploymentTrack.staging.channel}
verify(() => logger.info('hello world')).called(1);
});
});

group('log output', () {
final rawLogOutput = '''
2025-01-31 10:15:29.807 Df macos_sandbox[33557:2cc3d] [com.apple.network:] networkd_settings_read_from_file initialized networkd settings by reading plist directly

2025-01-31 10:15:29.807 Df macos_sandbox[33557:2cc3d] [com.apple.network:path] nw_path_libinfo_path_check [5E11C960-BB0A-456A-8024-620DAB6CCF17 Hostname#941210b4:0 tcp, legacy-socket, attribution: developer]
libinfo check path: satisfied (Path is satisfied), interface: en0, ipv4, dns

2025-01-31 10:15:29.808 Df macos_sandbox[33557:2cc12] [dev.shorebird:updater::updater] [shorebird] Reporting successful launch.
'''
.split('\n');

setUp(() {
setupMacosShorebirdYaml();
when(() => open.newApplication(path: any(named: 'path'))).thenAnswer(
(_) async => Stream.fromIterable(rawLogOutput.map(utf8.encode)),
);
});

test('removes noisy lines from log output', () async {
final result = await runWithOverrides(command.run);
expect(result, equals(ExitCode.success.code));

verify(
() => logger.info(
'''[dev.shorebird:updater::updater] [shorebird] Reporting successful launch.''',
),
).called(1);
verifyNever(
() => logger.info(
any(that: contains('networkd_settings_read_from_file')),
),
);
verifyNever(
() => logger.info(
any(that: contains('nw_path_libinfo_path_check')),
),
);
});
});
});

group('windows', () {
Expand Down