Default Logging on OSX/Xcode


#1

Please forgive me if this has already been asked but I looked through the tutorials, code examples, the forums and the source code for JUCE.

I’m running the NoiseSynth demo and am curious where the Logger is logging to.

    String message;
    message << "Preparing to play audio...\n";
    message << " samplesPerBlockExpected = " << samplesPerBlockExpected << "\n";
    message << " sampleRate = " << sampleRate;
    Logger::getCurrentLogger()->writeToLog (message);
    Logger::getCurrentLogger()->outputDebugString (message);

I added the last line to double check, although I read the source code and see that by default writeToLog calls outputDebugString.

I’m running XCode, I’ve set up the scheme for debugging and I’ve run the built app from XCode. I can’t see where the Logging is actually going to. I read the source code and found fputs to stderr for the OSX config but I can’t figure out where that is going, it doesn’t appear to be going to the console in XCode. I tried reading online but don’t see where else it could be going.

Am I missing something? I tried reading through all the related forum posts but I didn’t find explicit answers, I saw references to other discussions that sounded like they had more information but couldn’t locate them.

Thanks
Alessandro


#2

The default logger writes to the std::cout, i.e. the console. You will see that either in your IDE (VisualStudio has two windows, I keep forgetting which, one called output), in XCode it is shown on the bottom or if you call your app from the terminal or the windows cmd shell.

If you want to log to a file, you can create a FileLogger instance and set it as logger. Here is how the Projucer does that:


Note that you are in charge to remove the logger class when the program terminates (e.g. by using a ScopedPointer or std::unique_ptr.

Also a hint, you don’t need to call getCurrentLogger, there is a static shorthand, that will use the current logger:

Logger::writeToLog (message);

HTH


#3

@daniel Thank you for your quick response, I’ve read through and while I’ve learned a little bit more about the Logger process, my application still does not log output.

I’ve tried both running the app from XCode and opening the app from the terminal, in neither case do I get any output. I’m specifically looking to find out if I’m doing something wrong, or am supposed to add more code to actually see the Logging, but as of now when compiling the simple NoiseSynth demo with the logging code I’ve posted above, I do not get any logging.


#4

I am sorry, that it gives you trouble. I double checked here in my app, that it works for me. I run XCode as well, and I see the output in the XCode output, as well in the terminal when I start from there.
Can you make sure, that the code that logs is definitively called, like in the constructor of your main component?

HTH


#5

@daniel
I double checked everything, added the Logging code to the constructor of my MainComponent and still no Logging, not through Xcode or Terminal. I’ve posted my project up to github.

Note that I have not changed anything in projucer and believe I set up my scheme correctly in Xcode. The build config is debug, the noisesynth executable is selected and I have debug executable selected.

Thank You


#6

Do you have the correct Windows/Panels open in Xcode to see the Output? Are you seeing the Debug area? In the Debug area do you have the right-hand panel open?

Rail


#7

@Rail_Jon_Rogut

Ok, that took care of XCode! I had the debug area open, and selected activate console from the view menu but did not have the “right hand panel” open. I had googled how to open the console, but only saw the view menu suggestion, not the “right hand panel”.

However, I still don’t have output from the terminal. I’m trying open path from terminal and while the app opens, nothing reads from the terminal.


#8

How are you trying to output to STDIO ?

Rail


#9

Only using the above lines. I took it from @daniel’s comments that the logging should go on the console in xcode or terminal if run from terminal. Perhaps I misunderstood.


#10

Try using the DBG macro

DBG (message);

in a Debug build… and I take it you’re running the app from inside the App’s bundle MacOS folder.

To log to a file, use FileLogger and make sure you initialize it when you start your app and set it to nullptr when you destroy your app.

Rail


#11

Ok, I’ve tried adding the DBG (message) macro, it compiles. I believe I am using the debug build, my scheme is set to debug configuration and my App is building to the debug folder. If i run the app from Xcode, I see the Logger messages as well as the DBG message.

However, I still cannot get any messaging on Terminal as @daniel mentioned was possible. It’s not absolutely paramount, I’ve already achieved my original goal of viewing Logging messages, but after he mentioned it I figured I would try.

Thank you for the additional information on FileLogger, I will try it soon.


#12

Don’t know if it’s useful for you, but I built a simple juce module that contains an alternative logger, writing to the systems console.app, which even makes log messages from within plugins running e.g. in Pro Tools visible there. I find it quite useful here and there

By the way, you don’t need to write Logger::getCurrentLogger()->writeToLog (message); as writeToLog is a static function always writing to the current logger. So Logger::writeToLog (message); will do the same thing :wink:


#13

I’ll check it out, thank you very much!


#14

Are you trying to compile an AUv3 on iOS? Then the JUCE logger won’t work and sadly there is no easy way to get just the JUCE logs.

You should be able to see anything going to stdout in the device logs of your iDevice. Open the device log by clicking on the device log button in the “Devices and Simulator” window. Unfortunately, there is a lot of logging going on so it’s easy to miss JUCE messages.

Another option is to write to a file that you have access to on your iPhone and use that file as a log.

Edit: OK just saw your title :-). In any case, I’ll leave this here in case anyone else runs into this.


#15

Thanks for chiming in Fabian with this additional information. Any chance you know how to get terminal logging working like daniel was mentioning?

Thanks


#16

Did you try these buttons? (click on the image, the right border might be cropped)

If that doesn’t help, please describe what you are doing step by step, so we can get an idea, where you do something differently…


#17

So I may have misunderstood you. I’ve had console logging in my XCode terminal for several days.

or if you call your app from the terminal or the windows cmd shell

I took the second part of your statement to mean if I launch my app from the terminal using open path/to/app.app the Log statements should output to the actual Terminal that is a standalone app in osx.

Did I misunderstand?

Thanks


#18

No, you understood it right, both should work. If you hit play in XCode, you should see the logging in the described window, see previous screenshot.

Or you head into your folder, where the binary lives and call it there:


#19

This doesn’t appear to work for my compiled App. I see you were able to open Projucer by name, where as I have type open appname because it’s not added to path by default. Not sure if that matters but I’m not sure what else to add, the app logs to xcode so maybe I’m not opening it correctly.


#20

Well no, open calls finder or LaunchService to open your programm, hence you see no logging.

call it like ./appName.app/Contents/MacOS/appName if you don’t have it in the path…

HTH