Skip to content

Commit

Permalink
chore: clean up macOS preview log output (#2823)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman authored Jan 31, 2025
1 parent 10821b0 commit 6208a25
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
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.*\]'),
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

0 comments on commit 6208a25

Please sign in to comment.