00001 /* 00002 * This file is part of Micole Architecture 00003 * 00004 * Copyright (C) 2007 Micole partners 00005 * 00006 * Micole Architecture is free software: you can redistribute it 00007 * and/or modify it under the terms of the GNU Lesser General 00008 * Public License as published by the Free Software Foundation, 00009 * either version 3 of the License, or (at your option) any 00010 * later version. 00011 * 00012 * Micole Architecture is distributed in the hope that it will be 00013 * useful, * but WITHOUT ANY WARRANTY; without even the implied 00014 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00015 * PURPOSE. See the GNU Lesser General Public License for more 00016 * details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with Micole Architecture. If not, see 00020 * <http://www.gnu.org/licenses/>. 00021 */ 00022 00023 //#include "StdAfx.h" 00024 #include "stdafx.h" 00025 #include "LoggerAgent.h" 00026 #include "MicoleStringStream.h" 00027 00028 #include <time.h> 00029 00030 LoggerAgent::LoggerAgent() 00031 : MicoleAgent("LoggerAgent", "Logger") 00032 { 00033 time_t tim = time (NULL); 00034 struct tm t; 00035 gmtime_s(&t, &tim); 00036 MicoleStringStream s; 00037 s << "MicoleLog-" << 1900 + t.tm_year << "_" << t.tm_mon << "_" << t.tm_mday << "-" << 00038 t.tm_hour << "_" << t.tm_min << "_" << t.tm_sec << ".log"; 00039 _log.open(s.str().c_str()); 00040 bindMessage("(.*)", BUS_CALLBACK_OF(LoggerAgent, handleAllMessage)); 00041 } 00042 00043 LoggerAgent::~LoggerAgent() 00044 { 00045 _log.close(); 00046 } 00047 00048 void LoggerAgent::handleAllMessage ( MicoleBus *app, int argc, const char **argv ) 00049 { 00050 if (argc > 0) 00051 { 00052 time_t tim = time (NULL); 00053 struct tm t; 00054 gmtime_s(&t, &tim); 00055 _log << t.tm_hour << ":" << t.tm_min << ":" << t.tm_sec << " : " << argv[0] << endl; 00056 } 00057 }