Welcome! Log In Create A New Profile

Advanced

Syslog client

Posted by TekWarrior 
Syslog client
January 07, 2009 09:49PM
Hi!

I just wrote a small syslog client which I use for debugging and logging and thought I'd share the code in case anyone needs it. It is distributed under the MIT license, which basically means that you can do anything with it and just have to preserve the copyright notice at the top of the files.

You can find the latest information as well as the downloads at [blog.tekwarrior.net]



Edited 2 time(s). Last edit at 01/17/2009 04:22PM by TekWarrior.
Re: Syslog client
January 12, 2009 01:14AM
Hello Tek
Definitely a great tool.
To complete, for beginners :
1 - you must init the net before init Syslog : for example:
while (net_init() == -EAGAIN);
int r=Syslog_Start("Wii");

2 - Syslog_GetErrorMessage has probably replaced Syslog_GetErrorString

3 - on Windows there dont seem to have an integrated Syslog listener/server. I have found one freeware that seems to work nice : Kiwi Syslog Daemon 8.3.4.
Launch it once and just keep the windows opened to receive messages from Wii.

Test code :
#include
#include
#include
#include
#include
#include
#if defined(__wii__)
#include
#endif
static GXRModeObj *rmode = NULL;
static void *xfb = NULL;
int main(int argc, char **argv)
{
VIDEO_Init();
rmode = VIDEO_GetPreferredMode(NULL);
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
VIDEO_Configure(rmode);
VIDEO_SetNextFramebuffer(xfb);
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
// Wait for Video setup to complete
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
printf("\x1b[2;0H");
printf("Syslog test\n");
VIDEO_WaitVSync();

WPAD_Init();
printf("connecting...\n");
while (net_init() == -EAGAIN);
printf("connected.\n");

int r=Syslog_Start("Wii");
if (r==FALSE)
{ printf("Syslog_Start failed !\n");
printf(Syslog_GetErrorMessage());
printf("\n");
}

if (Syslog_SetDestination("192.168.0.3", 514)==0)
{
printf("Syslog_SetDest failed !\n");
printf(Syslog_GetErrorMessage());
printf("\n");
}

if (Syslog_Send(1, 1, "Hello this is the Wii !")==0)
{
printf("Syslog_Send failed !\n");
printf(Syslog_GetErrorMessage());
printf("\n");
}

printf("Press A to quit\n");

u16 mi=0;
while ( (WPAD_ButtonsDown(0) & WPAD_BUTTON_A) == 0 )
{
printf("\r%d", mi++);
Syslog_Send(1, 1, "Hello this is the Wii !");
WPAD_ScanPads();
VIDEO_WaitVSync();
}

Syslog_End();
return 0;
}

@Tek
According to me, it would be necessery to :
- include the Wii client part inside libogc ; Is there bugs ?
- add a tiny syslog server/listener to "wiiload" that could then be renamed "wiirun". The prog could send the dol as usual, and then waiting for possible syslog message and displaying it in the PC console. Then a simple Ctr+c to quit.
Best
tawi
Re: Syslog client
January 12, 2009 07:12AM
Ah, now that I know what that is it seems very useful. I'll be sure to use it when I get to a stage where I'm programming something with graphics.

I agree that this could be something that would be useful to have built into libogc.



Edited 1 time(s). Last edit at 01/12/2009 07:13AM by iofthestorm.
Re: Syslog client
January 12, 2009 07:46AM
Very good idea; works great! Do you plan on making it thread safe? Edit: I'm finding when (different) messages are sent in quick succession, only the first message is logged. Not sure if it's an issue with my setup (syslog-ng on Debian stable) or the code. To test it, I put sleep(1) after each Syslog_Send, and all the messages log fine, but obviously that isn't practical.

Quote

add a tiny syslog server/listener to "wiiload" that could then be renamed "wiirun". The prog could send the dol as usual, and then waiting for possible syslog message and displaying it in the PC console. Then a simple Ctr+c to quit.
Excellent idea. Instead of having to use ctr+c to stop, perhaps a special "stop listening" message could be sent for a clean exit.



Edited 1 time(s). Last edit at 01/12/2009 08:32AM by DrTwox.
Re: Syslog client
January 14, 2009 12:15AM
@tawi:
Yes, it is Syslog_GetErrorMessage() instead of Syslog_GetErrorString() - sorry for messing this up. And yes, you need to initialize the network before using the client. I updated my post to avoid confusion among new users.
I don't know of any bugs yet (except what DrTwox has mentioned, but I get to this point later), so if you find any just tell me :).
Integrating a syslog server to wiiload shouldn't be too hard, maybe I will create a patch for it when I have the time.

@DrTwox:
I can not reproduce the behaviour you describe. I'm using Sysrose Syslog Desktop (http://www.sysrose.com/) because I'm using windows for Wii development. Maybe it's some anti-dos mechanism in syslog-ng or (as you said) some error in your setup or lwip code.

EDIT:
OK, I just added a small syslog server to wiiload. It doesn't parse the incoming packets and just writes them to the console. If a message containing "WIILOADSYSLOG:EXIT" is received, it stops the server. You can simply do this with a simple
Syslog_Send(0, 0, "WIILOADSYSLOG:EXIT");
This also means that someone could just stop the daemon, so dont't use it over the internet or at least be prepared of the daemon quitting. For now the daemon is started automatically and listens on port 514 (standard syslog port). I will add some way to change that later.
A .zip file containing a windows executable is located here: [www.tekwarrior.net]
The sources can be downloaded from: [www.tekwarrior.net]
They should build on other systems, too, but I can not test this right now. You don't need it for Linux anyway as virtually all distributions include a daemon. Feedback appreciated :). When it's done I will add the links to the first post.



Edited 1 time(s). Last edit at 01/14/2009 02:08AM by TekWarrior.
Re: Syslog client
January 14, 2009 04:49AM
Strangely, it was only the little example/test app I made that had the problem. I've replaced my own logging system in WiiMP with your syslog code and it works perfectly.
Re: Syslog client
January 14, 2009 08:43AM
Thanks very much TekWarrior for the modified wiiload. This will save me a lot of trouble, because reading text on the Wii's console output (on a CRT TV) is horrible.
Re: Syslog client
January 14, 2009 01:50PM
I made some changes to the code and put it into an example project. It now supports multiple instances and should be thread-safe. You can download the new source, the modified wiiload code, the modified wiiload .exe and a .pdf with the manual at [www.tekwarrior.net]
Re: Syslog client
January 14, 2009 09:24PM
I was able to compile wiiload_syslog on OS X 10.5.5 with 1 warning:

syslogd.c:81: warning: pointer targets in passing argument 6 of 'recvfrom' differ in signedness

Normal wiiload functionality works but then wiiload exits with the following message:

unable to start syslog daemon

Might the two be related? Any suggestions? I'm about a week into C so I'm at a loss as to resolving this particular problem myself but would love to replace my existing logging solution (which involves writing to a log on the SD and swapping it back and forth between the Wii and my Mac).
Re: Syslog client
January 14, 2009 09:52PM
Shouldn't OS X have a syslog daemon since it's UNIX based?
Re: Syslog client
January 14, 2009 10:03PM
It should but I haven't been able to get it listening. All the information I've found suggests that it's been broken in Leopard. Besides, unless I'm misunderstanding what the syslog version of wiiload does, it would be far more useful to have my messages sent directly to the wiiload console window I keep open anyways than to another application.
Re: Syslog client
January 15, 2009 12:50AM
The warning can be safely ignored. The problem might be that you already have a syslog daemon running on port 514 on your system, so the wiiload one can not bind the socket to this port. Another possibility is that you can not bind to ports <= 1024 as non-root. Just be patient until I have created a way to set the port from outside the program (might do that the next days).



Edited 1 time(s). Last edit at 01/15/2009 12:53AM by TekWarrior.
Re: Syslog client
January 15, 2009 01:54AM
Hmm, I tried changing the port number (to 515) but didn't think to make it greater than 1024. Changing it to 1514 worked! This is phenomenal.
Re: Syslog client
January 15, 2009 02:01AM
Ports 1024 and below are reserved IIRC. That's probably why it wouldn't let you.
Re: Syslog client
January 15, 2009 04:33AM
I finally figured out how to get Xcode's Build and Go feature to work with wiiload (and documented it here). Combined with this new syslog-enabled wiiload I'm down from 3 apps to 1 for building and testing homebrew. Can't thank you enough TekWarrior.
Re: Syslog client
January 17, 2009 04:24PM
I just installed a wordpress blog where I will release information about my projects for the Wii. I changed my first post accordingly. The link in the first post directs you to the syslog category for more information about that specific part.
Re: Syslog client
January 19, 2009 11:11PM
WARNING : important test for possible bug/drawbacks

Just try this in your main loop :

if( pressed & WPAD_BUTTON_A )
{
Syslog_Send(s_Syslog, SYSLOG_PRI_LOCAL0, SYSLOG_SEV_DEBUG, "input: pressed A 1");
Syslog_Send(s_Syslog, SYSLOG_PRI_LOCAL0, SYSLOG_SEV_DEBUG, "input: pressed A 2");
Syslog_Send(s_Syslog, SYSLOG_PRI_LOCAL0, SYSLOG_SEV_DEBUG, "input: pressed A 3");
Syslog_Send(s_Syslog, SYSLOG_PRI_LOCAL0, SYSLOG_SEV_DEBUG, "input: pressed A 4");
}

Now run the exec and press very quickly on A button.
Then tell us if some messages are lost or if you receive ALL the messages on the PC.
If some disappear sometimes, please mention :
- if you are WIFI or USB-Eth.
- Windows or Linux
- wiiload_syslog or wiiload + demaon
- your syslog port
Regards
tawi
Re: Syslog client
January 20, 2009 12:16AM
Quote

WARNING : important test for possible bug/drawbacks
I too was having the same problem (see an earlier post) with a small example app I wrote to test the library. However, the problem seemed to vanish one I integrated the syslog code into my real app as a replacement for the existing logging functions.

I use wifi, Linux, wiiload + syslog-ng, port 514.

Is it necessary, in a real app, to be sending messages in quick succession like this? Ideally the answer would be 'yes', and you would be certain to never loose a single message, but for practical purposes the library works great now, in my humble opinion. :)
Re: Syslog client
January 20, 2009 01:23AM
Warning for new comers : some messages are sometimes lost and never arrive on the PC !!!!!!!
Tek, I suppose this is a net_send or UDP problem.
Do you have an idea ?
Regards
Re: Syslog client
January 20, 2009 10:12AM
I will take a look at it when I'm back home from university.

EDIT:
Okay, I tested it now and I am unable to reproduce this behaviour, as you can see here: [rafb.net]

I'm using my modified wiiload_syslog on Windows, port 514, over WiFI connections (both Wii and syslog daemon host).

EDIT #2:
Do you do any other networking related stuff, like connecting somewhere via TCP?



Edited 2 time(s). Last edit at 01/22/2009 02:35PM by TekWarrior.
Sorry, only registered users may post in this forum.

Click here to login