If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
FleshCrawler
Posts: 108 Joined: Fri Aug 22, 2003 1:04 pm
Location: Kerkrade, Netherlands
Contact:
Post
by FleshCrawler » Fri Sep 26, 2003 10:41 am
Any Idea how i can log into a file?
like that what gets written in the dosbox, i get logged into a file. like a program.log ot logfile.txt , i have no idea how to fix something like that.
tnx in advance
WhytWulf
Posts: 51 Joined: Mon Sep 08, 2003 11:14 am
Location: Australia, Tamworth, NSW
Contact:
Post
by WhytWulf » Fri Sep 26, 2003 10:49 am
here is the code I use for my log file writer..in might be of use to someone. functions like printf();
Code: Select all
#include <stdio.h>
#include <stdarg.h>
#include <time.h>
void InitLog(void)
{
//creates logfile "sprawl.log" if it doesn't exist
FILE *LogFile;
time_t current = time(NULL);
if((LogFile=fopen("Runner.log","w+"))!=NULL)
{
fprintf(LogFile,"Log File started %s",ctime(¤t));
fclose(LogFile);
}
}
void LogWrite(char *string, ...)
{
char LogString[1000];
va_list ap;
va_start(ap, string);
vsprintf(LogString,string,ap);
va_end(ap);
FILE *filelog;
time_t current = time(NULL);
if ((filelog=fopen("Runner.log","a"))!=NULL)
{
fprintf(filelog,"-> %s: %s",ctime(¤t),LogString);
fprintf(filelog,"\n");
fclose(filelog);
}
}
To use call InitLog(); this deletes the file blah blah and creates a new file.
and when you want to output something to the logfile, use
Code: Select all
LogWrite("This is a test output variable %d\n",output);
It is quite versitile..It could easily be added to and made into a monster debug/log file..
FleshCrawler
Posts: 108 Joined: Fri Aug 22, 2003 1:04 pm
Location: Kerkrade, Netherlands
Contact:
Post
by FleshCrawler » Fri Sep 26, 2003 11:20 am
thanks very much
FleshCrawler
Posts: 108 Joined: Fri Aug 22, 2003 1:04 pm
Location: Kerkrade, Netherlands
Contact:
Post
by FleshCrawler » Fri Oct 31, 2003 3:59 pm
Digging this old topic up again, but i felt like it was useless to create a complete new topic on the same subject
My Logwriter works fine so far, but i got the following problem, i want to let it write wich kind of renderer and Resolution the app. is running.
but when i use the LogWrite function like
LogWrite("Render: %d on Resolution: %d", DriverType, ResolutionType);
so if someone has a solution for that, thanks in advance
I've been absent for really long, but i'm ready to reign my terror on you once again, mwuahahahahaha
Gonosz
Posts: 24 Joined: Wed Oct 29, 2003 4:21 pm
Location: Hungary (one joke and you're dead)
Post
by Gonosz » Fri Oct 31, 2003 7:22 pm
I am not quite sure what you are talking about :], but if you are saying you are looing for a printf-like function, then here it goes:
Code: Select all
inline void logwrite(char* logline, ...)
{
va_list pfmt;
FILE * fp = fopen("log.txt", "a");
if (fp == NULL)
return;
if (logline != NULL)
{
va_start(pfmt, logline);
vfprintf(fp, logline, pfmt);
fprintf(fp,"\n");
fclose(fp);
va_end(pfmt);
}
}
BTW if you don't close the file and your app crashes, chances are that the logfile will be gone.
Hope I helped,
Gonosz
FleshCrawler
Posts: 108 Joined: Fri Aug 22, 2003 1:04 pm
Location: Kerkrade, Netherlands
Contact:
Post
by FleshCrawler » Sat Nov 01, 2003 10:31 am
well, i got this:
Code: Select all
void InitLog(void)
{
//creates logfile "Astornia.log" if it doesn't exist
FILE *LogFile;
time_t current = time(NULL);
if((LogFile=fopen("Astornia.log","w+"))!=NULL)
{
fprintf(LogFile,"Log File started %s \n",ctime(¤t));
fclose(LogFile);
}
}
void LogWrite(char *logstr)
{
char LogString[1000];
va_list ap;
va_start(ap, logstr);
vsprintf(LogString,logstr,ap);
va_end(ap);
FILE *filelog;
time_t current = time(NULL);
if ((filelog=fopen("Astornia.log","a"))!=NULL)
{
fprintf(filelog,"%s",LogString);
fclose(filelog);
}
}
and i cant add more parameters to it, because i only wanna have it for 1 function. to show the driver, and resolution in the logfile
I've been absent for really long, but i'm ready to reign my terror on you once again, mwuahahahahaha
Gonosz
Posts: 24 Joined: Wed Oct 29, 2003 4:21 pm
Location: Hungary (one joke and you're dead)
Post
by Gonosz » Sat Nov 01, 2003 11:22 am
Okay. You can use vsprintf, which is like printf, but the output goes to a char[]. Then you can pass this string to your logwrite.
FleshCrawler
Posts: 108 Joined: Fri Aug 22, 2003 1:04 pm
Location: Kerkrade, Netherlands
Contact:
Post
by FleshCrawler » Sat Nov 01, 2003 12:09 pm
when i change it VC6 gives me the following error.
c:\program files\microsoft visual studio\myfiles\projects\astornia\logwriter.h(43) : error C2664: 'vsprintf' : cannot convert parameter 1 from 'struct _iobuf *' to 'char *'
i dont know so much about C/C++ yet. still learning
I've been absent for really long, but i'm ready to reign my terror on you once again, mwuahahahahaha
Gonosz
Posts: 24 Joined: Wed Oct 29, 2003 4:21 pm
Location: Hungary (one joke and you're dead)
Post
by Gonosz » Sat Nov 01, 2003 2:42 pm
I don't think I can help without seeing you're source, so I copied a working function here for you (it's from the Half-Life SDK). BTW this is C, not C++
Code: Select all
void UTIL_LogPrintf( char *fmt, ... )
{
va_list argptr;
char string[1024];
va_start ( argptr, fmt );
vsprintf ( string, fmt, argptr );
va_end ( argptr );
logwrite( string );
}
EDIT:
Damn I am stupid, it is in the code you posted above
You actually use the vsprintf in the logwrite! Anyway, this just proves that I didn't give you a bad advice
Another idea: maybe you passed the file pointer as the first argument instead of the char[]... maybe
Okay, I'm off to learn reading
Gonosz<helpdesk>
FleshCrawler
Posts: 108 Joined: Fri Aug 22, 2003 1:04 pm
Location: Kerkrade, Netherlands
Contact:
Post
by FleshCrawler » Sat Nov 01, 2003 5:40 pm
Gonosz wrote: Another idea: maybe you passed the file pointer as the first argument instead of the char[]... maybe
could you explain plz
and everyone can make reading mistakes, no big problem
I've been absent for really long, but i'm ready to reign my terror on you once again, mwuahahahahaha
Gonosz
Posts: 24 Joined: Wed Oct 29, 2003 4:21 pm
Location: Hungary (one joke and you're dead)
Post
by Gonosz » Sat Nov 01, 2003 9:33 pm
Code: Select all
char string[200];
vsprintf ( string, "Render: %d on Resolution: %d\n", DriverType, ResolutionType);
LogWrite(string);
This should work.
FleshCrawler
Posts: 108 Joined: Fri Aug 22, 2003 1:04 pm
Location: Kerkrade, Netherlands
Contact:
Post
by FleshCrawler » Sat Nov 01, 2003 10:05 pm
it still says it cant take 4 parameters, vsprintf that is,
but if i remove em one by one, it says cant take 3 ,2 ,1...somehow i dont understand
but as you wrote it there, it actually has to work :S
I've been absent for really long, but i'm ready to reign my terror on you once again, mwuahahahahaha
FleshCrawler
Posts: 108 Joined: Fri Aug 22, 2003 1:04 pm
Location: Kerkrade, Netherlands
Contact:
Post
by FleshCrawler » Mon Nov 03, 2003 7:54 pm
I guess i will never get that fixed. been thinking how to solve, asked a friend, he didnt know the solution because he uses CBuilder. and only knew the CBuilder solution that doesnt work in VC6. so if someone is out there that does know the solution to this, i'm like begging to help me with a code to solve it, i'm really desperate...
I've been absent for really long, but i'm ready to reign my terror on you once again, mwuahahahahaha
Halan
Posts: 447 Joined: Tue Oct 04, 2005 8:17 pm
Location: Germany, Freak City
Contact:
Post
by Halan » Fri Jul 07, 2006 8:09 pm
okay this is an old topic i know but i used the code for logging
when compiling it says "`va_start' used in function with fixed args+"
any ideas?
greets,
Halan
hybrid
Admin
Posts: 14143 Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:
Post
by hybrid » Fri Jul 07, 2006 10:15 pm
Learn C, read your compiler manual, try google. va_start is a function which is required for variable argument lists. This is plain ANSI C.