Logging into a file
-
- Posts: 108
- Joined: Fri Aug 22, 2003 1:04 pm
- Location: Kerkrade, Netherlands
- Contact:
Logging into a file
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
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
here is the code I use for my log file writer..in might be of use to someone. functions like printf();
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
It is quite versitile..It could easily be added to and made into a monster debug/log file..
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);
}
}
and when you want to output something to the logfile, use
Code: Select all
LogWrite("This is a test output variable %d\n",output);
Project Admin -
http://shadowrunonline.sourceforge.net
------------------------------------
There are 10 kinds of people, those that understand binary and those that don't.
http://shadowrunonline.sourceforge.net
------------------------------------
There are 10 kinds of people, those that understand binary and those that don't.
-
- Posts: 108
- Joined: Fri Aug 22, 2003 1:04 pm
- Location: Kerkrade, Netherlands
- Contact:
-
- Posts: 108
- Joined: Fri Aug 22, 2003 1:04 pm
- Location: Kerkrade, Netherlands
- Contact:
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
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
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:
BTW if you don't close the file and your app crashes, chances are that the logfile will be gone.
Hope I helped,
Gonosz
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);
}
}
Hope I helped,
Gonosz
-
- Posts: 108
- Joined: Fri Aug 22, 2003 1:04 pm
- Location: Kerkrade, Netherlands
- Contact:
well, i got this:
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
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);
}
}
I've been absent for really long, but i'm ready to reign my terror on you once again, mwuahahahahaha
-
- Posts: 108
- Joined: Fri Aug 22, 2003 1:04 pm
- Location: Kerkrade, Netherlands
- Contact:
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
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
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++
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>
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 );
}
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>
-
- Posts: 108
- Joined: Fri Aug 22, 2003 1:04 pm
- Location: Kerkrade, Netherlands
- Contact:
Code: Select all
char string[200];
vsprintf ( string, "Render: %d on Resolution: %d\n", DriverType, ResolutionType);
LogWrite(string);
-
- Posts: 108
- Joined: Fri Aug 22, 2003 1:04 pm
- Location: Kerkrade, Netherlands
- Contact:
-
- Posts: 108
- Joined: Fri Aug 22, 2003 1:04 pm
- Location: Kerkrade, Netherlands
- Contact:
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