   Log manager?
  Hi,I'm looking for a solution of a following problem:Imagine a situation when a program hangs, or throws a non-handled exception, or calls a wrong pointer and gets killed by the system (Windows). To figure out where the error comes from, some kind of a trace would be useful, so I created a singleton-based LogManager class. It's called during the runtime, and it should log some std::string's, using standard fprintf function. Unfortunately, it does only, if the program finishes correctly.How to force the system to flush the file buffer each time the log occurs, to make it immediate, and failure-safe?   
  If you are using a normal c FILE and want to flush its contents then call fflush(pointer to file);Else if you are using std::ofstream then call File.flush();Hope that helps   ;  In addition to the above, looking into SEH (structured exception handling; OS-level exceptions versus C++'s language-level exceptions) might be benficial as it can give you more contextual information regarding your crash and also give you a better chance to preserve some information about it.   ;Quote:Original post by jpetrieIn addition to the above, looking into SEH (structured exception handling; OS-level exceptions versus C++'s language-level exceptions) might be benficial as it can give you more contextual information regarding your crash and also give you a better chance to preserve some information about it.Hmm that's interesting, never knew about that. Thanks!   ;  Also the Event Viewer might be a good place to look for things. With the aforementioned Event Viewer you could use the Windows Event Log API. Then there are libraries like Pantheios or something from the log4X family.   ;Quote:Original post by jpetrieIn addition to the above, looking into SEH (structured exception handling; OS-level exceptions versus C++'s language-level exceptions) might be benficial as it can give you more contextual information regarding your crash and also give you a better chance to preserve some information about it.Related to exceptions, Minidump Files could become handy in certain situations.   ;Quote:Original post by deathtrapQuote:Original post by jpetrieIn addition to the above, looking into SEH (structured exception handling; OS-level exceptions versus C++'s language-level exceptions) might be benficial as it can give you more contextual information regarding your crash and also give you a better chance to preserve some information about it.Hmm that's interesting, never knew about that. Thanks!Found linky;http://www.gamedev.net/reference/programming/features/sehbasics/Although depending on what you want, these methods other than providing your own logfile class might be a little bit of overkill.  Programming exception handling into the system when all you want to do is output a message inside an if statement to see if its getting executed would be such an example.;Quote:Original post by moosedudeQuote:Original post by deathtrapQuote:Original post by jpetrieIn addition to the above, looking into SEH (structured exception handling; OS-level exceptions versus C++'s language-level exceptions) might be benficial as it can give you more contextual information regarding your crash and also give you a better chance to preserve some information about it.Hmm that's interesting, never knew about that. Thanks!Found linky;http://www.gamedev.net/reference/programming/features/sehbasics/Although depending on what you want, these methods other than providing your own logfile class might be a little bit of overkill.  Programming exception handling into the system when all you want to do is output a message inside an if statement to see if its getting executed would be such an example.Then again it could be argued using a design pattern like a singleton (beaten to death on these forums of why they're bad) to reinvent the wheel is also likely overkill.  std::cerr exists for this very purpose.  The OP spent time making a likely memory leak (the singleton) in his program (depending how it was made) to add existing functionality that doesn't even perform as he wanted.   ;  Ok, so how it is done by "the professionals"? I mean: bug tracing and asserting the code? When to use C++ exceptions?   ;Quote:Ok, so how it is done by "the professionals"? I mean: bug tracing and asserting the code? When to use C++ exceptions?Who cares? It depends on the context anyway, and how and why the professionals do certain things often has very little bearing or applicablility to how other people (particularly hobby developers) should.The important thing is to use them effectively and correctly within the contexts of your project in a fashion that is useful to you. Identify what you need out of your logging system, and implement that. Don't waste time implementing what you don't need.Ask more specific questions, as what defines "correct" and "a good idea," et cetera, depend on context.   