Using IrrLicht Logger also for LogFiles

A forum to store posts deemed exceptionally wise and useful
Post Reply
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

Using IrrLicht Logger also for LogFiles

Post 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.
Last edited by DaChief on Wed Nov 23, 2005 9:43 am, edited 2 times in total.
IrrLicht v0.14
Audiere Sounds-API v1.9.3
Current Project: KoulesXD
Guest

Post by Guest »

so this logs the console output?
Conquistador
Posts: 340
Joined: Wed Sep 28, 2005 4:38 pm
Location: Canada, Eh!

Post 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.
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

Post 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
IrrLicht v0.14
Audiere Sounds-API v1.9.3
Current Project: KoulesXD
Cristian

Post by Cristian »

The iostream header is unnecessary, if fstream is included.
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

Post 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...
IrrLicht v0.14
Audiere Sounds-API v1.9.3
Current Project: KoulesXD
dhenton9000
Posts: 395
Joined: Fri Apr 08, 2005 8:46 pm

Post by dhenton9000 »

Works like a charm :lol:



I needed this for a joystick demo, which I will post in the same spirit as this. This was a life saver!!
MikeR
Posts: 767
Joined: Sun Dec 26, 2004 4:03 pm
Location: Northern California USA
Contact:

Post by MikeR »

Could this be used to log to a listbox?
If so, how would you do that?
If it exists in the real world, it can be created in 3d

Sys specs:
AMD 3700+ 64 processor
1.0 gb ram
e-Geforce 6600 graphics 256 mb onboard ram
DaChief
Posts: 45
Joined: Tue Nov 01, 2005 9:02 am
Location: Switzerland

Post 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 :wink:

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 :lol:
IrrLicht v0.14
Audiere Sounds-API v1.9.3
Current Project: KoulesXD
Thellis
Posts: 1
Joined: Sun Oct 22, 2006 9:09 am
Location: Melbourne, Australia
Contact:

Post 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 :P...

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?
Kaade- lvl38 Gnome Warlock (Blackrock)
Arodaen- lvl60 Night Elf Druid (Bloodscalp)
Image
Post Reply