00001 #ifndef EZLOGGER_OUTPUT_POLICY_HPP_HEADER_GRD_
00002 #define EZLOGGER_OUTPUT_POLICY_HPP_HEADER_GRD_
00003
00004 #include <vector>
00005 #include <iostream>
00006 #include <fstream>
00007 #include <string>
00008 #include <stdio.h>
00009 #include <time.h>
00010
00011 namespace axter
00012 {
00019 class ezlogger_output_policy
00020 {
00021 #ifdef _WIN32
00022 inline static std::string GetRunningProgramName()
00023 {
00024 char ModuleFileName[2048] = "";
00025 GetModuleFileNameA(NULL, ModuleFileName, sizeof(ModuleFileName));
00026 return ModuleFileName;
00027 }
00028 inline static std::string GetFileName()
00029 {
00030 static std::string ModuleFileName = GetRunningProgramName() + "_debuglog.txt";
00031 return ModuleFileName;
00032 }
00033 #ifndef EZLOGGER_OUTPUT_FILENAME
00034 #define EZLOGGER_OUTPUT_FILENAME GetFileName()
00035 #endif //EZLOGGER_OUTPUT_FILENAME
00036 #endif //_WIN32
00037
00038
00039 #ifndef EZLOGGER_OUTPUT_FILENAME
00040 #define "ezlogger_output.txt"
00041 #endif
00042
00043 public:
00044 inline static std::ostream& get_log_stream()
00045 {
00046 static const std::string FileName = EZLOGGER_OUTPUT_FILENAME;
00047 #ifdef EZLOGGER_REPLACE_EXISTING_LOGFILE_
00048 static std::ofstream logfile(FileName.c_str(), std::ios_base::out);
00049 #else
00050 static std::ofstream logfile(FileName.c_str(), std::ios_base::out | std::ios_base::app);
00051 #endif
00052 static bool logfile_is_open = logfile.is_open();
00053 if (logfile_is_open) return logfile;
00054 return std::cout;
00055 }
00056 inline static void add_to_stack(const std::string& function_name)
00057 {
00058 get_stack().push_back(function_name);
00059 }
00060 inline static void pop_stack()
00061 {
00062 get_stack().pop_back();
00063 }
00064 protected:
00065 inline static void display_stack_main(int LineNo = 0)
00066 {
00067 get_log_stream() << "Begin Stack -------------------- (" << LineNo << ")" << std::endl;
00068 for(std::vector<std::string>::iterator i = get_stack().begin();
00069 i != get_stack().end();++i)
00070 {
00071 get_log_stream() << *i << std::endl;
00072 }
00073 get_log_stream() << "End Stack --------------------" << std::endl;
00074 }
00075 private:
00076 inline static std::vector<std::string>& get_stack()
00077 {
00078 static std::vector<std::string> my_stack;
00079 return my_stack;
00080 }
00081 };
00082 }
00083
00084
00085 #endif //EZLOGGER_OUTPUT_POLICY_HPP_HEADER_GRD_