Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# Logger.cpp

Go to the documentation of this file.

    00001 //------------------------------------------------------------------------------
    00002 // Lamp : Open source game middleware
    00003 // Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
    00004 //
    00005 // This library is free software; you can redistribute it and/or
    00006 // modify it under the terms of the GNU Lesser General Public
    00007 // License as published by the Free Software Foundation; either
    00008 // version 2.1 of the License, or (at your option) any later version.
    00009 //
    00010 // This library is distributed in the hope that it will be useful,
    00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013 // Lesser General Public License for more details.
    00014 //
    00015 // You should have received a copy of the GNU Lesser General Public
    00016 // License along with this library; if not, write to the Free Software
    00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    00018 //------------------------------------------------------------------------------
    00019
    00020 /** @file
    00021  * ロガー実装
    00022  * @author Junpee
    00023  */
    00024
    00025 #include "LampBasic.h"
    00026 #include "Core/Debug/Logger.h"
    00027 #include "Core/InputOutput/TextFileWriter.h"
    00028 #include "Core/System/StringMethod.h"
    00029 #include "Core/Debug/DebugStringTemporary.h"
    00030
    00031 namespace Lamp{
    00032
    00033 //------------------------------------------------------------------------------
    00034 // コンストラクタ
    00035 Logger::Logger(const String& fileName, LogLevel logLevel){
    00036     writer_ = new TextFileWriter(fileName);
    00037     logLevel_ = logLevel;
    00038 }
    00039 //------------------------------------------------------------------------------
    00040 // デストラクタ
    00041 Logger::~Logger(){
    00042     writer_->flush();
    00043     SafeDelete(writer_);
    00044 }
    00045 //------------------------------------------------------------------------------
    00046 // ログ出力
    00047 void Logger::output(LogLevel logLevel, String message){
    00048     Assert(logLevel != zeroLevel);
    00049     if(logLevel == zeroLevel){ return; }
    00050     if(logLevel_ < logLevel){ return; }
    00051     writer_->writeText(message);
    00052 }
    00053 //------------------------------------------------------------------------------
    00054 // ログ出力
    00055 void Logger::output(LogLevel logLevel, const char* format, ...){
    00056     Assert(logLevel != zeroLevel);
    00057     if(logLevel == zeroLevel){ return; }
    00058     if(logLevel_ < logLevel){ return; }
    00059     va_list args;
    00060     va_start(args, format);
    00061     int size = StdVsnprintf(DebugStringTemporary::buffer_,
    00062         DebugStringTemporary::bufferSize_ - 1, format, args);
    00063     if(size < 0){
    00064         ErrorOut(String("ログ出力のフォーマットに失敗しました。"));
    00065         return;
    00066     }
    00067     DebugStringTemporary::buffer_[size] = '\0';
    00068     va_end(args);
    00069     writer_->writeText(DebugStringTemporary::buffer_, size);
    00070 }
    00071 //------------------------------------------------------------------------------
    00072 // ログ出力
    00073 void Logger::output(const char* format, ...){
    00074     if(logLevel_ < midiumLevel){ return; }
    00075     va_list args;
    00076     va_start(args, format);
    00077     int size = StdVsnprintf(DebugStringTemporary::buffer_,
    00078         DebugStringTemporary::bufferSize_ - 1, format, args);
    00079     if(size < 0){
    00080         ErrorOut(String("ログ出力のフォーマットに失敗しました。"));
    00081         return;
    00082     }
    00083     DebugStringTemporary::buffer_[size] = '\0';
    00084     va_end(args);
    00085     writer_->writeText(DebugStringTemporary::buffer_, size);
    00086 }
    00087 //------------------------------------------------------------------------------
    00088 // フラッシュ
    00089 void Logger::flush(){
    00090     writer_->flush();
    00091 }
    00092 //------------------------------------------------------------------------------
    00093 } // End of namespace Lamp
    00094 //------------------------------------------------------------------------------