///
/// The log manager
/// 

#ifndef __LOG_MANAGER_H__
#define __LOG_MANAGER_H__

#include "Manager.h"
#include <time.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

#define LOGFILE_NAME "dragonfly.log"

class LogManager{// : public Manager {

 private:
	LogManager (LogManager const&){}    /// don't allow copy
	void operator=(LogManager const&){} /// don't allow assignment
			     /// private since a singleton
	static LogManager* pLog;

 protected:
	//LogManager();
  bool do_flush;		     /// true if fflush after each write
  FILE *fp;			     /// pointer to log file
  

 public:
	LogManager();
  ~LogManager();

  char *getTimeString(){	     /// returns pretty-formatted string
	  time_t rawtime;
	  struct tm * timeinfo;
	  char buffer [32];
	  time ( &rawtime );
	  timeinfo = localtime ( &rawtime );
	  strftime (buffer,32,"%Y",timeinfo);
	  return buffer;
  }

  /// Get the one and only instance of the LogManager.
  static LogManager &getInstance();

  /// Startup the LogManager (open logfile "dragonfly.h").
  /// append = true to add to logfile, flush = true if flush() afer each write.
  int startUp(bool append, bool flush);

  /// Shutdown the LogManager (close logfile).
  void shutDown();

  /// Write to logfile.
  /// Supports printf() formatting of strings.
  /// Return number of bytes written, -1 if error.
  int writeLog(const char *fmt, ...);
};

#endif // __LOG_MANAGER_H__
