SFML community forums

General => SFML wiki => Topic started by: mateandmetal on October 14, 2012, 01:13:11 am

Title: Simple and elegant C++ File Logger
Post by: mateandmetal on October 14, 2012, 01:13:11 am
Ok, this is my File Logger class  ;)

Simple C++ File Logger (by mateandmetal) (https://github.com/SFML/SFML/wiki/Source%3A-Simple-File-Logger-%28by-mateandmetal%29)

Yes, it is written in english, no spanish variable names here  ;D
Title: Re: Simple and elegant C++ File Logger
Post by: Laurent on October 14, 2012, 08:54:54 am
Thanks for sharing :)

This is really a minor comment, but I find these identifiers too long:
ige::FileLogger::e_logType::LOG_WARNING

They contain "log" 3 times, and mix a lot of different naming conventions. Maybe something like this would be nicer:
ige::FileLogger::Type::Warning
Or
ige::FileLogger::Warning
Or
ige::LogType::Warning
Title: Re: Simple and elegant C++ File Logger
Post by: Foaly on October 14, 2012, 02:01:13 pm
Wow this looks cool! But I have to agree with Laurent. I would go with the last suggestion.

Another question: Is it possible to redirect SFML's error logging to this log?
Title: Re: Simple and elegant C++ File Logger
Post by: eXpl0it3r on October 14, 2012, 05:51:33 pm
Another question: Is it possible to redirect SFML's error logging to this log?
Yes, SFML uses sf::err() to output errors which by default writes to std::err but you can redirect it, by using the rdbuf() function provided by the std::ostream class.
See here in the doc (http://www.sfml-dev.org/documentation/2.0/group__system.php#ga7fe7f475639e26334606b5142c29551f). ;)
Title: Re: Simple and elegant C++ File Logger
Post by: Laurent on October 14, 2012, 06:42:13 pm
By the way, logging classes should also follow this design (I mean the design of the standard library): separate formatting (std::ostream) and the target (std::streambuf).

For example, if your logger only implements formatting operations, it could inherit from std::ostream and use the standard std::streambufs available (filebuf, stringbuf, ...). By deriving from std::ostream it would also benefit from the features that it provides. Unfortunately, standard streams are not easy to implement; however boost provides a simpler API on top of it with its boost.iostream library.
Title: Re: Simple and elegant C++ File Logger
Post by: mateandmetal on October 14, 2012, 09:21:59 pm
I find these identifiers too long

Maybe a typedef can help  ;D

Wow this looks cool!

Thanks  ;)


Guys... How can I put my article under the Sources/Miscellaneous wiki page?
Title: Re: Simple and elegant C++ File Logger
Post by: FRex on October 15, 2012, 11:53:33 am
You have to edit that page and add link and name of your page.
Title: Re: Simple and elegant C++ File Logger
Post by: mateandmetal on October 15, 2012, 10:13:55 pm
You have to edit that page and add link and name of your page.

Thanks FRex
Title: Re: Simple and elegant C++ File Logger
Post by: mateandmetal on October 22, 2012, 01:36:54 am
Link fixed  8)