Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Simple and elegant C++ File Logger  (Read 21808 times)

0 Members and 1 Guest are viewing this topic.

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Simple and elegant C++ File Logger
« on: October 14, 2012, 01:13:11 am »
Ok, this is my File Logger class  ;)

Simple C++ File Logger (by mateandmetal)

Yes, it is written in english, no spanish variable names here  ;D
« Last Edit: October 22, 2012, 01:34:54 am by mateandmetal »
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Simple and elegant C++ File Logger
« Reply #1 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
Laurent Gomila - SFML developer

Foaly

  • Sr. Member
  • ****
  • Posts: 453
    • View Profile
Re: Simple and elegant C++ File Logger
« Reply #2 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Simple and elegant C++ File Logger
« Reply #3 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. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Simple and elegant C++ File Logger
« Reply #4 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.
Laurent Gomila - SFML developer

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Re: Simple and elegant C++ File Logger
« Reply #5 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?
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Simple and elegant C++ File Logger
« Reply #6 on: October 15, 2012, 11:53:33 am »
You have to edit that page and add link and name of your page.
« Last Edit: October 15, 2012, 12:03:52 pm by FRex »
Back to C++ gamedev with SFML in May 2023

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Re: Simple and elegant C++ File Logger
« Reply #7 on: October 15, 2012, 10:13:55 pm »
You have to edit that page and add link and name of your page.

Thanks FRex
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!

mateandmetal

  • Full Member
  • ***
  • Posts: 171
  • The bird is the word
    • View Profile
    • my blog
Re: Simple and elegant C++ File Logger
« Reply #8 on: October 22, 2012, 01:36:54 am »
Link fixed  8)
- Mate (beverage) addict
- Heavy metal addict _lml
- SFML 2 addict
- My first (and free) game: BichingISH!