Skip to content

Commit

Permalink
logging: separate by \r as well as \n and filter empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
osy committed Apr 29, 2024
1 parent 06b806f commit a3dca97
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Sources/QEMUKitInternal/QEMULogging.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ - (BOOL)redirectStandardFds {
return @[];
}
NSString *string = [*buffer stringByAppendingString:line];
NSArray *lines = [string componentsSeparatedByString:@"\n"];
NSArray *lines = [string componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\r\n"]];
*buffer = [lines lastObject];
if (lines.count > 0) {
lines = [lines subarrayWithRange:NSMakeRange(0, lines.count - 1)];
}
return lines;

// remove empty lines
return [lines filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"count > 0"]];
}

- (void)logToFile:(NSURL *)path {
Expand Down

0 comments on commit a3dca97

Please sign in to comment.