SDL2 LOG File output

Hello,
I need to output my log which is showed in console using SDL_Log and SDL_LogError. Is there some way how can I do it? I need it for error reporting from users which don’t have access to console because the game is launched by launcher.
Thank you for response

On Windows, log messages are also send to the debugger with
OutputDebugString
(http://msdn.microsoft.com/en-us/library/windows/desktop/aa363362(v=vs.85).aspx)

  • so one can get the log text if a debugger can be attached by the user.On 1/4/2014 4:59 PM, sgcsim wrote:

Hello,
I need to output my log which is showed in console using SDL_Log and
SDL_LogError. Is there some way how can I do it? I need it for error
reporting from users which don’t have access to console because the
game is launched by launcher.
Thank you for response


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

A quick Google search could easily answer your question.
http://stackoverflow.com/questions/7400418/writing-a-log-file-in-c-cOn Sat, Jan 4, 2014 at 6:59 PM, sgcsim wrote:

Hello,
I need to output my log which is showed in console using SDL_Log and
SDL_LogError. Is there some way how can I do it? I need it for error
reporting from users which don’t have access to console because the game is
launched by launcher.
Thank you for response


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I went this way and it is working now. But I was wondering about some SDL function or some kind of event binded to SDL_Log for easier output to file. But thanks.

Alberto Corona wrote:> A quick Google search could easily answer your question.

http://stackoverflow.com/questions/7400418/writing-a-log-file-in-c-c (http://stackoverflow.com/questions/7400418/writing-a-log-file-in-c-c)

On Sat, Jan 4, 2014 at 6:59 PM, sgcsim <@sgcsim (@sgcsim)> wrote:

  Hello,

I need to output my log which is showed in console using SDL_Log and SDL_LogError. Is there some way how can I do it? I need it for error reporting from users which don’t have access to console because the game is launched by launcher.
Thank you for response


SDL mailing list
SDL at lists.libsdl.org (SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

I have found some better solution for this problem. In SDL is function called “SDL_LogSetOutputFunction” and by using this function can override ddefault function to your own. But I don’t know how to use it and on wiki is not any example. Anybody know how to use it please ?

Well, it’s pretty standard usage. Create a function that matches the
callback signature (SDL_LogOutputFunction), e.g.:
void* myLogFn(void* userdata, int category, SDL_LogPriority priority, const
char* message)
{
// Change to fit your needs (like to output to a file)
printf("%s", message);
}

Then set the callback:
SDL_LogSetOutputFunction(&myLogFn, NULL); // replace NULL with some other
’userdata’, as desired

Whenever a SDL_Log* function is called, I would expect your callback to be
triggered with the userdata passed in.

Jonny DOn Mon, Jan 6, 2014 at 4:45 AM, sgcsim wrote:

I have found some better solution for this problem. In SDL is function
called “SDL_LogSetOutputFunction” and by using this function can override
ddefault function to your own. But I don’t know how to use it and on wiki
is not any example. Anybody know how to use it please ?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I implemented it like this:

Code:

void* Log(void *userdata, int category, SDL_LogPriority priority, const char *message)
{
	printf("[Log] %s", message);
}

int main(int argc, char* argv[])
{
	SDL_LogSetOutputFunction(&Log, NULL);

....

and I’m getting these errors:

Code:

2	IntelliSense: argument of type "void *(*)(void *userdata, int category, SDL_LogPriority priority, const char *message)" is incompatible with parameter of type "SDL_LogOutputFunction"	.......main.cpp	617	28

Error 1 error C2664: ‘SDL_LogSetOutputFunction’ : cannot convert parameter 1 from ‘void *(__cdecl *)(void *,int,SDL_LogPriority,const char *)’ to ‘SDL_LogOutputFunction’ …\main.cpp 623 1

Any idea how to fix it ?

Jonny D wrote:

Well, it’s pretty standard usage. ?Create a function that matches the callback signature (SDL_LogOutputFunction), e.g.:
void* myLogFn(void* userdata, int category, SDL_LogPriority priority, const char* message)
{
? ? // Change to fit your needs (like to output to a file)
? ? printf("%s", message);
}

Then set the callback:
SDL_LogSetOutputFunction(&myLogFn, NULL); ?// replace NULL with some other ‘userdata’, as desired

Whenever a SDL_Log* function is called, I would expect your callback to be triggered with the userdata passed in.

Jonny D

   	I have found some better solution for this problem. In SDL is function called "SDL_LogSetOutputFunction" and by using this function can override ddefault function to your own. But I don't know how to use it and on wiki is not any example. Anybody know how to use it please ?

SDL mailing list
SDL at lists.libsdl.org (SDL at lists.libsdl.org)
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org (http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org)

Code:

Code:> On Mon, Jan 6, 2014 at 4:45 AM, sgcsim <@sgcsim (@sgcsim)> wrote:

Oh sorry, a typo there, I think? SDL_LogOutputFunction is a void()
typedef, so I accidentally put a * in the return type. Change the return
type to just ‘void’ instead of 'void
’.

Jonny DOn Mon, Jan 6, 2014 at 1:01 PM, sgcsim wrote:

I implemented it like this:

Code:

void* Log(void *userdata, int category, SDL_LogPriority priority, const
char *message)
{
printf("[Log] %s", message);
}

int main(int argc, char* argv[])
{
SDL_LogSetOutputFunction(&Log, NULL);

and I’m getting these errors:

Code:

2 IntelliSense: argument of type “void ()(void *userdata, int
category, SDL_LogPriority priority, const char *message)” is incompatible
with parameter of type “SDL_LogOutputFunction” …main.cpp 617 28
Error 1 error C2664: ‘SDL_LogSetOutputFunction’ : cannot convert
parameter 1 from ‘void *(__cdecl *)(void *,int,SDL_LogPriority,const char
*)’ to ‘SDL_LogOutputFunction’ …\main.cpp 623 1

Any idea how to fix it ?

Jonny D wrote:

Well, it’s pretty standard usage. Create a function that matches the
callback signature (SDL_LogOutputFunction), e.g.:
void* myLogFn(void* userdata, int category, SDL_LogPriority priority,
const char* message)
{
// Change to fit your needs (like to output to a file)
printf("%s", message);
}

Then set the callback:
SDL_LogSetOutputFunction(&myLogFn, NULL); // replace NULL with some other
’userdata’, as desired

Whenever a SDL_Log* function is called, I would expect your callback to be
triggered with the userdata passed in.

Jonny D

On Mon, Jan 6, 2014 at 4:45 AM, sgcsim <> wrote:

Quote:

I have found some better solution for this problem. In SDL is function
called “SDL_LogSetOutputFunction” and by using this function can override
ddefault function to your own. But I don’t know how to use it and on wiki
is not any example. Anybody know how to use it please ?


SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Code:

Quote:

Code:


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

If that works, then it’s the wiki’s fault! :wink:

Jonny D

Ok thanks very much, it works great now. :slight_smile:

Jonny D wrote:> If that works, then it’s the wiki’s fault! :wink:

Jonny D