| # Gaudi Framework, version v20r3
Generated: 24 Nov 2008

# StreamLogger.cpp

Go to the documentation of this file.

    00001
    00002 #include "StreamLogger.h"
    00003
    00004 #include "GaudiKernel/IMessageSvc.h"
    00005
    00006 #include <stdexcept>
    00007 #include <fstream>
    00008
    00009 // StreamLogger::StreamLogger(): m_isMine(0), p_ost(0), p_msgStr(0), m_level(0){};
    00010
    00011 StreamLogger::StreamLogger(const std::string& file): m_isMine(1),
    00012                                                      p_ost(0), p_msgStr(0) {
    00013   m_name = "file:" + file;
    00014   p_ost = new std::ofstream(file.c_str());
    00015   if (p_ost == 0) {
    00016     throw std::invalid_argument("can't open file");
    00017   }
    00018 }
    00019
    00020 StreamLogger::StreamLogger(IMessageSvc *svc, MSG::Level lev):
    00021   m_isMine(1), p_ost(0), p_msgStr(0) {
    00022   p_msgStr = new MsgStream( svc, "IssueLogger");
    00023   m_level = lev;
    00024   m_name = "MsgStream";
    00025 }
    00026
    00027 StreamLogger::StreamLogger(std::ostream& ost): m_isMine(0) , p_ost(0),
    00028                                                p_msgStr(0){
    00029   p_ost = &ost;
    00030   if (ost == std::cerr) {
    00031     m_name = "STDERR";
    00032   } else if ( ost == std::cout) {
    00033     m_name = "STDOUT";
    00034   } else {
    00035     m_name = "unknown ostream";
    00036   }
    00037 }
    00038
    00039 std::string
    00040 StreamLogger::name() const {
    00041   return m_name;
    00042 }
    00043
    00044 StreamLogger::~StreamLogger() {
    00045   if (m_isMine && p_ost != 0) {
    00046     delete p_ost;
    00047   }
    00048   if (p_msgStr != 0) {
    00049     delete p_msgStr;
    00050   }
    00051 }