00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "precomp.h"
00030 #include "file_logger.h"
00031 #include "file.h"
00032 #include "string_help.h"
00033 #include "string_format.h"
00034 #include "datetime.h"
00035
00037
00038
00039 CL_FileLogger::CL_FileLogger(const CL_String &filename) : file(0)
00040 {
00041 file = new CL_File(filename, CL_File::open_always);
00042 }
00043
00044 CL_FileLogger::~CL_FileLogger()
00045 {
00046 delete file;
00047 }
00048
00050
00051
00053
00054
00055 void CL_FileLogger::log(const CL_StringA &type, const CL_String &text)
00056 {
00057 TCHAR *months[] =
00058 {
00059 TEXT("Jan"),
00060 TEXT("Feb"),
00061 TEXT("Mar"),
00062 TEXT("Apr"),
00063 TEXT("May"),
00064 TEXT("Jun"),
00065 TEXT("Jul"),
00066 TEXT("Aug"),
00067 TEXT("Sep"),
00068 TEXT("Oct"),
00069 TEXT("Nov"),
00070 TEXT("Dec")
00071 };
00072
00073 TCHAR *days[] =
00074 {
00075 TEXT("Sun"),
00076 TEXT("Mon"),
00077 TEXT("Tue"),
00078 TEXT("Wed"),
00079 TEXT("Thu"),
00080 TEXT("Fri"),
00081 TEXT("Sat")
00082 };
00083
00084
00085 CL_DateTime cur_time = CL_DateTime::get_system_time();
00086
00087 CL_StringFormat format(TEXT("%1 %2 %3 %4:%5:%6 %7 %8 [%9] %10\r\n"));
00088 format.set_arg(1, days[cur_time.get_week_day_local()]);
00089 format.set_arg(2, months[cur_time.get_month_local()]);
00090 format.set_arg(3, cur_time.get_month_day_local());
00091 format.set_arg(4, cur_time.get_hours_local(), 2);
00092 format.set_arg(5, cur_time.get_minutes_local(), 2);
00093 format.set_arg(6, cur_time.get_seconds_local(), 2);
00094 format.set_arg(7, cur_time.get_zone_abbreviation());
00095 format.set_arg(8, cur_time.get_year_local());
00096 format.set_arg(9, type);
00097 format.set_arg(10, text);
00098 CL_StringA log_line = CL_StringHelp::text_to_local8(format.get_result());
00099
00100 file->seek(0, CL_File::seek_end);
00101 file->write(log_line.data(), (int) log_line.length());
00102 }
00103
00105