Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

file_logger.cpp

Go to the documentation of this file.
00001 /*
00002 **  ClanLib SDK
00003 **  Copyright (c) 1997-2005 The ClanLib Team
00004 **
00005 **  This software is provided 'as-is', without any express or implied
00006 **  warranty.  In no event will the authors be held liable for any damages
00007 **  arising from the use of this software.
00008 **
00009 **  Permission is granted to anyone to use this software for any purpose,
00010 **  including commercial applications, and to alter it and redistribute it
00011 **  freely, subject to the following restrictions:
00012 **
00013 **  1. The origin of this software must not be misrepresented; you must not
00014 **     claim that you wrote the original software. If you use this software
00015 **     in a product, an acknowledgment in the product documentation would be
00016 **     appreciated but is not required.
00017 **  2. Altered source versions must be plainly marked as such, and must not be
00018 **     misrepresented as being the original software.
00019 **  3. This notice may not be removed or altered from any source distribution.
00020 **
00021 **  Note: Some of the libraries ClanLib link to may have additional
00022 **  requirements or restrictions.
00023 **
00024 **  File Author(s):
00025 **
00026 **    Magnus Norddahl
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 // CL_FileLogger Construction:
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 // CL_FileLogger Attributes:
00051 
00053 // CL_FileLogger Operations:
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         // Tue Nov 16 11:34:15 CET 2004
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 // CL_FileLogger Implementation:

Generated on Sat Feb 19 22:51:16 2005 for npcore by  doxygen 1.4.1