65

Running xcodebuild from the console will bring you very verbose output and I wasn't able to locate any options for limit its output in order to display only warnings and errors.

I'm looking for a way to capture the xcodebuild output and filter it. It would prefer a Python solution that will work with pipes but I'm open to other approaches as long they are command line based solutions.

Are any tools that are already able to do this?

sorin
  • 161,544
  • 178
  • 535
  • 806

12 Answers12

118

Use xcodebuild -quiet.

According to the xcodebuild man page:

-quiet : Do not print any output except for warnings and errors.

Bonus: No other tools necessary! (Although I also like xcodebuild | xcpretty)

I build with Travis CI, which complains after 4 MB of logs. This argument solved the problem.

Amin Ariana
  • 4,635
  • 2
  • 35
  • 21
50

There’s a Ruby gem called xcpretty.

It filters the output of xcodebuild and also provides different formatters and coloring.

UPDATE: As Mike Hardy correctly states in the comments to this answer, xcpretty is no longer maintained.

Koraktor
  • 41,357
  • 10
  • 69
  • 99
36

This isn't sufficient for me. Piping to /dev/null will just show you that a build failed, but you don't see the reason(s) why. Ideally we could see just the errors and/or warnings without all of the successful compiler commands.

This basically does the job:

xcodebuild | grep -A 5 error:
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
rosejn
  • 849
  • 1
  • 7
  • 9
  • 10
    or `egrep '^(/.+:[0-9+:[0-9]+:.(error|warning):|fatal|===)' -` to also get lines saying what xcodebuild is about to do. – PatchyFog Apr 30 '15 at 22:39
25

To only see the error output messages, redirect the standard output to /dev/null (a special file that works as a black hole) like this:

xcodebuild > /dev/null

If you want to capture the error output into a file, you can do:

xcodebuild 2> ./build_errors.log
Guillaume
  • 21,685
  • 6
  • 63
  • 95
  • If you try this on a build server, make sure the build agent has permissions to that path. What happened to me is that build kept going and timed out, without warning about the permissions issue in GitLab. – Blanthor Apr 14 '21 at 19:55
14

enter image description here

-quiet is the best way to do it at now.

weijia.wang
  • 2,088
  • 2
  • 18
  • 32
  • quiet is too quiet for me. xcpretty is dead. xcbeautify is the new tool that does this wonderfully and is well-maintained – Mike Hardy Dec 14 '21 at 18:11
6

There’s a Swift command line tool https://github.com/thii/xcbeautify that can also format xcodebuild output.

Thi
  • 2,066
  • 1
  • 17
  • 12
2

I love xcpretty for looking at as a human, but I had a need to find build errors in an automated setting for propagation elsewhere, and I wanted to be sure I captured just the relevant information. The following sed command serves that purpose:

xcodebuild | sed -nE '/error:/,/^[[:digit:]] errors? generated/ p'

Output:

main.c:16:5: error: use of undeclared identifier 'x'
    x = 5;
    ^
main.c:17:5: error: use of undeclared identifier 'y'
    y = 3;
    ^
2 errors generated.
ravron
  • 11,014
  • 2
  • 39
  • 66
0

I am building an expo project and there are a lot of warnings that come from libraries which I don't want to see. I was able to filter out the warnings with this command.

set -o pipefail \
&& xcodebuild build -workspace app.xcworkspace -scheme app \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
| xcpretty \
| grep --line-buffered -v -F "[-W" \
| grep --line-buffered -v -F "*" \
| grep --line-buffered -v -F "^" \
| grep --line-buffered -v -F ";" \
| grep --line-buffered -v -e "^$" \
| grep --line-buffered -v -F "@" \
| grep --line-buffered -v -F ")" \
| grep --line-buffered -v -F "/" \
| grep --line-buffered -v -F "}" \
| grep --line-buffered -v -F "{" \
| grep --line-buffered -v -F "\\" \
| grep --line-buffered -v -F "#" \
| grep --line-buffered -v -F ","

I'll admit it's a little sloppy but I couldn't get any of the other solutions to work. The -quiet option still printed hundreds of warnings I had no ability to resolve.

What is strange is that when I compile on the command line on the build machine I wasn't getting the warnings but when I compiled in my CI build I would get the warnings. Very annoying. I wish apple would provide a way to silence warnings for xcodebuild

Josh Woodcock
  • 2,683
  • 1
  • 22
  • 29
  • when you have warnings you don't like in pods you don't control (like libevent, in react-native / expo builds), you want to actually disable them since they are basically out of scope for you. You can do that in a podfile postinstall, like this https://github.com/invertase/react-native-firebase-authentication-example/blob/f21b0bba63e299535e2d35a41d98cb3d3b45075e/template/ios/Podfile#L33 – Mike Hardy Dec 14 '21 at 17:46
0

I have been bitten by xcpretty swallowing way too much information in a CI environment, making it pretty hard to debug the error. -quiet hides output in a way that's a bit too aggressive, so I put together this one-liner and called it xcquiet.sh. It only hides specific lines, while preserving enough of the original output and not swallowing any other unexpected log entries.

andersonvom
  • 11,701
  • 4
  • 35
  • 40
0

if you want to remove warnings use

xcodebuild <command> | sed -e '/warning:/,/\^/d'

if you want to suppress warnings while using xcpretty try this

xcodebuild <command> \
    | sed -e '/warning:/,/\^/d' \
    | xcpretty -s
Willian
  • 181
  • 2
  • 5
0

You should use xcbeautify with the quiet (warnings and errors) or quieter (only errors) options.

Example from their site, adapted to warnings and errors:

set -o pipefail && xcodebuild [flags] | xcbeautify --quiet
Fab1n
  • 2,103
  • 18
  • 32
-1

We run detox build command and it threw too many logs in CI. -quite parameter failed with hiding logs.

The best solution is to hide and save logs in file:

npx detox build -c ios &> detox_build.log