How to print/debug from a c plugin

The title says it all, I have try’d a couple(std::out,printf), but none of them go through to any where… I miss Debug.Log :frowning:

Redirecting stdout to a file works when you can create a file(standalone)

	freopen("debug.txt", "a", stdout);
	printf("SetTexture id:%d

");

fprintf(stderr, “something”); writes to ~/Library/Logs/Unity/Editor.log and/or ~/Library/Logs/Unity/Player.log just fine for me.

Another alternative is to use syslog. E.g. somewhere near the start of your app:
#include <syslog.h>
openlog(“My identifier”, LOG_CONS, LOG_USER);

and on shutdown:
closelog();

to write to the log:
const char *error = “fubar”;
syslog(LOG_ERR, “Error: %s”, error);

writing 6 years after the previous answers, and using unity 2017,
i also see fprintf(stdout, …) or fprintf(stderr, …) working as expected, except that it seems like it’s (now) also necessary to do a fflush() as well. this seems like a change in behavior on unity’s part.

#From c++ you have to do this:

  1. in your plugin code (ie, in Xcode)

  2. use ::fprintf(stderr, "some text
    ");

  3. for example

    static void UNITY_INTERFACE_API OnRenderEvent(int eventID)
    {
    if (s_CurrentAPI == NULL) return;
    ::fprintf(stderr, "howdy log
    "); // don’t forget the newline
    ModifyTexturePixels();
    }

  4. on mac, open terminal

  5. cd ~/Library/Logs/Unity

  6. tail -f Editor.log

  7. In Unity, click “Play”

You will now see the log (from the fprintf statement) in real time as the project Plays.

#In an iOS project / C plugin, it’s easier:

Just

 #include <stdio.h>

and then normal printf statements do appear on console

void set_texture_from_unity(void* textureHandle, int w, int h) {
	printf("set texture called 

");

° it will appear on the console in Xcode

° when you run the final built app on tethered iPhone

(Recall it’s generally impossible to run iPhone apps with native plugins in the Editor; you have to go through to a device anyway.)