| # Gaudi Framework, version v21r8 |

Home |  | Generated: 17 Mar 2010

# StreamLogger.cpp

Go to the documentation of this file.

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