Page 1 of 1
Using IrrLicht Logger also for LogFiles
Posted: Tue Nov 22, 2005 7:07 pm
by DaChief
hey guys
maybe you are wondering why the IrrLicht Logger can't write its messages into a LogFile.
Well, i don't know ^^
whatever, i've found a nice way, to use the IrrLicht Logger also for writing LogFiles by capturing the LogText in the EventReceiver and then write it down in a textfile. So you don't have to recompile the Engine and the messages in the console are still there.
here is the code of the EventReceiver.h i use for this:
Code: Select all
#include <fstream>
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == irr::EET_LOG_TEXT_EVENT)
{
std::fstream LogFile("LogFile.log",std::ios::out|std::ios::app);
LogFile << (event.LogEvent.Text) << std::endl;
LogFile.close();
return true;
};
return false;
}
};
I hope someone can use it.
Posted: Tue Nov 22, 2005 7:39 pm
by Guest
so this logs the console output?
Posted: Wed Nov 23, 2005 12:24 am
by Conquistador
I think the iostream header is unnecessary, I've used file streams and all that junk before without having it. Oh well, I don't think it increases the filesize at all, so meh.
Posted: Wed Nov 23, 2005 8:29 am
by DaChief
@GFXstyLER
Yes, the console output will be logged into a file
@Conquistador
hmm.. quite possible.. i didn't test that yet... i tought i include it all to get rid of some errors... whatever, if it is so, i'll update my post
Posted: Wed Nov 23, 2005 9:26 am
by Cristian
The iostream header is unnecessary, if fstream is included.
Posted: Wed Nov 23, 2005 9:44 am
by DaChief
Ok, i've updated my post.
if something doesn't work so tell me.
did anybody test it yet ? in my project it works fine so far...
Posted: Sun Nov 27, 2005 3:50 pm
by dhenton9000
Works like a charm
I needed this for a joystick demo, which I will post in the same spirit as this. This was a life saver!!
Posted: Mon Jan 30, 2006 11:11 pm
by MikeR
Could this be used to log to a listbox?
If so, how would you do that?
Posted: Tue Jan 31, 2006 8:59 am
by DaChief
hmm.. it should work yes.. but i've no time to test it right now...
here is the code that "should" do it
Code: Select all
#include <fstream>
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == irr::EET_LOG_TEXT_EVENT)
{
//Log to File
std::fstream LogFile("LogFile.log",std::ios::out|std::ios::app);
LogFile << (event.LogEvent.Text) << std::endl;
LogFile.close();
//Log into ListBox
myListBox->addItem(event.LogEvent.Text);
return true;
};
return false;
}
};
It's very simple... a bit too simple... not sure if it works... but whatever...
Well.. I have to go back to work now
Posted: Sun Oct 22, 2006 9:14 am
by Thellis
I use VB.NET, but basically there is also the option of using the Windows Log files and viewer
Code: Select all
Imports Irrlicht
Imports Irrlicht.Core
Imports Irrlicht.IO
Imports Irrlicht.Scene
Imports Irrlicht.Video
Module Main
Dim Reciever As New EventReciever
Dim Log As New System.Diagnostics.EventLog
Dim LogSource As String
Sub Main()
Device.EventReceiver = Reciever
'Init our log event source if it is not in existance (either first run or cleared logs)
Log.SourceExists("Irrlicht Test App")
If Not Log.SourceExists("Irrlicht Test App") Then
Log.CreateEventSource("Irrlicht Test App","")
End If
LogSource = "Irrlicht Test App"
End Sub
Class EventReciever
Implements IEventReceiver
Function OnEvent(e As [Event]) As Boolean Implements IEventReceiver.OnEvent
Select Case e.Type
Case EventType.LogText
'Write the log entry :)
Log.WriteEntry(LogSource,e.LogText)
End Select
End Function
End Class
End Module
And I think thats about all there is to it
... of course, as i said, this is VB.NET code, so i dont know the c++ headers for it etc and no i cant translate it due to my knowledge of c++ being less than poor
...
To view these logs, Control Panel->Administrative Tools->Event Viewer
The "source" name is specified in the above code (ive called myne Irrlicht Test App)
Not too sure exactly (can not tell 100% from MSDN) what the second arg in
Code: Select all
Log.CreateEventSource("Irrlicht Test App","")
is sposed to do... anyone?