Commit c4a7c2b2 authored by Sebastien Ponce's avatar Sebastien Ponce
Browse files

Last version of the logging facility, now allowing to choose between No Log...

Last version of the logging facility, now allowing to choose between No Log (default), DLF and stdout
parent 76f2a671
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: BaseObject.cpp,v $ $Revision: 1.6 $ $Release$ $Date: 2004/07/08 08:26:33 $ $Author: sponcec3 $
* @(#)$RCSfile: BaseObject.cpp,v $ $Revision: 1.7 $ $Release$ $Date: 2004/07/12 14:19:01 $ $Author: sponcec3 $
*
*
*
......@@ -38,6 +38,7 @@
// static values initialization
// -----------------------------------------------------------------------
std::string castor::BaseObject::s_msgSvcName("");
unsigned long castor::BaseObject::s_msgSvcId(0);
// -----------------------------------------------------------------------
// constructor
......@@ -52,9 +53,10 @@ castor::BaseObject::~BaseObject() throw() {}
// -----------------------------------------------------------------------
// msgSvc
// -----------------------------------------------------------------------
castor::MsgSvc* castor::BaseObject::msgSvc(std::string name)
castor::MsgSvc* castor::BaseObject::msgSvc(std::string name,
const unsigned long id)
throw (castor::exception::Exception) {
IService* svc = svcs()->service(name, castor::MsgSvc::ID());
IService* svc = services()->service(name, id);
if (0 == svc) {
castor::exception::Internal e;
e.getMessage() << "Unable to retrieve MsgSvc";
......@@ -111,10 +113,22 @@ void castor::BaseObject::getTLS(void **thip)
//------------------------------------------------------------------------------
// initlog
//------------------------------------------------------------------------------
void castor::BaseObject::initLog(std::string name) throw() {
Cthread_mutex_lock(&s_msgSvcName);
void castor::BaseObject::initLog(std::string name,
const unsigned long id)
throw() {
Cthread_mutex_lock(&s_msgSvcId);
if (0 != s_msgSvcId) {
try {
// This always returns a valid service if no exception is raised
clog() << WARNING << "initLog called several times. "
<< "Only the first is taken into account."
<< std::endl;
} catch(castor::exception::Exception e) {}
return;
}
s_msgSvcName = name;
Cthread_mutex_unlock(&s_msgSvcName);
s_msgSvcId = id;
Cthread_mutex_unlock(&s_msgSvcId);
}
//------------------------------------------------------------------------------
......@@ -122,5 +136,12 @@ void castor::BaseObject::initLog(std::string name) throw() {
//------------------------------------------------------------------------------
castor::logstream& castor::BaseObject::clog()
throw(castor::exception::Exception) {
return msgSvc(s_msgSvcName)->stream();
if (0 == s_msgSvcId) {
castor::exception::Internal e;
e.getMessage() << "clog() was called before initialization of the log facility.\n"
<< "Please call initLog first.";
throw e;
}
// This always returns a valid service if no exception is raised
return msgSvc(s_msgSvcName, s_msgSvcId)->stream();
}
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: BaseObject.hpp,v $ $Revision: 1.6 $ $Release$ $Date: 2004/07/08 08:26:34 $ $Author: sponcec3 $
* @(#)$RCSfile: BaseObject.hpp,v $ $Revision: 1.7 $ $Release$ $Date: 2004/07/12 14:19:01 $ $Author: sponcec3 $
*
* Basic object support, including pointer to Services and log support
*
......@@ -68,24 +68,30 @@ namespace castor {
* gets a given message service from its name.
* Note that the service has to be released after usage
* @param name the name of the MsgSvc to retrieve
* @param name the type of the MsgSvc to retrieve
* @return a pointer to the message service. This is always
* a valid pointer if no exception was raised
* @exception Exception if something went wrong
*/
MsgSvc* msgSvc(std::string name) throw(castor::exception::Exception);
static MsgSvc* msgSvc(std::string name,
const unsigned long id)
throw(castor::exception::Exception);
/**
* Sets the name of the MsgSvc to use for logging
* Note that this name should be set only once if DLF
* is used due to limitations in the current implementation
* of DLF itsef
* Defines which logging service should be used in
* the future by giving a name and a service type.
* Note that this method should only be called once.
* In case of other calls, they will be ignored and
* a warning will be issued in the already configured
* log
*/
void initLog(std::string name) throw();
static void initLog(std::string name,
const unsigned long id) throw();
/**
* Access to the log stream
*/
castor::logstream& clog() throw(castor::exception::Exception);
static castor::logstream& clog() throw(castor::exception::Exception);
private:
......@@ -101,6 +107,11 @@ namespace castor {
*/
static std::string s_msgSvcName;
/**
* The type of MsgSvc to use
*/
static unsigned long s_msgSvcId;
}; // end of class BaseObject
} // end of namespace castor
......
......@@ -69,7 +69,9 @@ namespace castor {
*/
enum ServicesIds {
SVC_INVALID,
SVC_MSG,
SVC_NOMSG,
SVC_DLFMSG,
SVC_STDMSG,
SVC_ORACNV,
SVC_ODBCCNV,
SVC_STREAMCNV,
......
/******************************************************************************
* DlfMsgSvc.cpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: DlfMsgSvc.cpp,v $ $Revision: 1.1 $ $Release$ $Date: 2004/07/12 14:19:01 $ $Author: sponcec3 $
*
* A message service writing into DLF
*
* @author Sebastien Ponce
*****************************************************************************/
// Include Files
#include "castor/Constants.hpp"
#include "castor/IService.hpp"
#include "castor/SvcFactory.hpp"
#include "castor/dlfbuf.h"
// Local Includes
#include "DlfMsgSvc.hpp"
// -----------------------------------------------------------------------
// Instantiation of a static factory class
// -----------------------------------------------------------------------
static castor::SvcFactory<castor::DlfMsgSvc> s_factoryDlfMsgSvc;
const castor::IFactory<castor::IService>& DlfMsgSvcFactory = s_factoryDlfMsgSvc;
// -----------------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------------
castor::DlfMsgSvc::DlfMsgSvc(const std::string name)
throw(castor::exception::Exception) :
MsgSvc(name) {
// use a DLF buffer in the log stream
stream().setBuffer(new dlfbuf(name));
}
// -----------------------------------------------------------------------
// id
// -----------------------------------------------------------------------
const unsigned int castor::DlfMsgSvc::id() const {
return ID();
}
// -----------------------------------------------------------------------
// ID
// -----------------------------------------------------------------------
const unsigned int castor::DlfMsgSvc::ID() {
return SVC_DLFMSG;
}
/******************************************************************************
* DlfMsgSvc.hpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: DlfMsgSvc.hpp,v $ $Revision: 1.1 $ $Release$ $Date: 2004/07/12 14:19:02 $ $Author: sponcec3 $
*
* A message service writing into DLF
*
* @author Sebastien Ponce
*****************************************************************************/
#ifndef CASTOR_DLFMSGSVC_HPP
#define CASTOR_DLFMSGSVC_HPP 1
// Include Files
#include "castor/MsgSvc.hpp"
#include "castor/logstream.h"
#include "castor/exception/Exception.hpp"
namespace castor {
/**
* A message service logging into DLF
*/
class DlfMsgSvc : public MsgSvc {
public:
/**
* Constructor
*/
DlfMsgSvc(const std::string name)
throw(castor::exception::Exception);
/**
* Destructor
*/
virtual ~DlfMsgSvc() throw() {};
/**
* Get the service id
*/
virtual const unsigned int id() const;
/**
* Get the service id, statically
*/
static const unsigned int ID();
};
} // end of namespace castor
#endif // CASTOR_DLFMSGSVC_HPP
......@@ -17,7 +17,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# @(#)$RCSfile: Imakefile,v $ $Revision: 1.24 $ $Release$ $Date: 2004/07/05 14:12:01 $ $Author: jdurand $
# @(#)$RCSfile: Imakefile,v $ $Revision: 1.25 $ $Release$ $Date: 2004/07/12 14:19:02 $ $Author: sponcec3 $
#
# Make Castor libraries and executables
#
......@@ -76,6 +76,7 @@ STGLIB_SRCS = IAddressCInt.cpp \
BaseAddressCInt.cpp \
BaseCnvSvc.cpp \
BaseObject.cpp \
BaseObjectCInt.cpp \
BaseServer.cpp \
BaseSvc.cpp \
Converters.cpp \
......@@ -87,12 +88,17 @@ STGLIB_SRCS = IAddressCInt.cpp \
MessageAck.cpp \
MessageAckCInt.cpp \
MsgSvc.cpp \
NoMsgSvc.cpp \
StdMsgSvc.cpp \
DlfMsgSvc.cpp \
ObjectCatalog.cpp \
ObjectSet.cpp \
Services.cpp \
ServicesCInt.cpp \
logstream.cpp \
logbuf.cpp \
stdbuf.cpp \
dlfbuf.cpp \
client/BaseClient.cpp \
io/Socket.cpp \
io/StreamAddress.cpp \
......@@ -167,7 +173,11 @@ STGLIB_SRCS = IAddressCInt.cpp \
exception/Exception.cpp \
exception/InvalidArgument.cpp \
exception/Internal.cpp \
exception/NoEntry.cpp
exception/NoEntry.cpp
#if BuildDlfClient
STGLIB_SRCS += DlfMsgSvc.cpp
#endif
STGLIB_OBJS = $(STGLIB_SRCS:.cpp=.Osuf)
......
......@@ -17,29 +17,19 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: MsgSvc.cpp,v $ $Revision: 1.3 $ $Release$ $Date: 2004/07/07 16:37:15 $ $Author: sponcec3 $
* @(#)$RCSfile: MsgSvc.cpp,v $ $Revision: 1.4 $ $Release$ $Date: 2004/07/12 14:19:02 $ $Author: sponcec3 $
*
*
* A message service internaly using a castor log stream
*
* @author Sebastien Ponce
*****************************************************************************/
// Include Files
#include "castor/logstream.h"
#include "castor/Constants.hpp"
#include "castor/IService.hpp"
#include "castor/SvcFactory.hpp"
#include "common.h"
// Local Includes
#include "MsgSvc.hpp"
// -----------------------------------------------------------------------
// Instantiation of a static factory class
// -----------------------------------------------------------------------
static castor::SvcFactory<castor::MsgSvc> s_factoryMsgSvc;
const castor::IFactory<castor::IService>& MsgSvcFactory = s_factoryMsgSvc;
// -----------------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------------
......@@ -56,24 +46,3 @@ castor::MsgSvc::~MsgSvc() throw() {
m_stream->close();
delete m_stream;
}
// -----------------------------------------------------------------------
// id
// -----------------------------------------------------------------------
const unsigned int castor::MsgSvc::id() const {
return ID();
}
// -----------------------------------------------------------------------
// ID
// -----------------------------------------------------------------------
const unsigned int castor::MsgSvc::ID() {
return SVC_MSG;
}
// -----------------------------------------------------------------------
// stream
// -----------------------------------------------------------------------
castor::logstream& castor::MsgSvc::stream() const {
return *m_stream;
}
......@@ -17,9 +17,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: MsgSvc.hpp,v $ $Revision: 1.3 $ $Release$ $Date: 2004/07/07 16:37:15 $ $Author: sponcec3 $
* @(#)$RCSfile: MsgSvc.hpp,v $ $Revision: 1.4 $ $Release$ $Date: 2004/07/12 14:19:02 $ $Author: sponcec3 $
*
*
* A message service internaly using a castor log stream
*
* @author Sebastien Ponce
*****************************************************************************/
......@@ -53,20 +53,10 @@ namespace castor {
*/
virtual ~MsgSvc() throw();
/**
* Get the service id
*/
virtual const unsigned int id() const;
/**
* Get the service id, statically
*/
static const unsigned int ID();
/**
* get the output stream associated to this service
*/
castor::logstream& stream() const;
castor::logstream& stream() const { return *m_stream; }
private:
......
/******************************************************************************
* NoMsgSvc.cpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: NoMsgSvc.cpp,v $ $Revision: 1.1 $ $Release$ $Date: 2004/07/12 14:19:02 $ $Author: sponcec3 $
*
* A message service writing nowhere
*
* @author Sebastien Ponce
*****************************************************************************/
// Include Files
#include "castor/Constants.hpp"
#include "castor/IService.hpp"
#include "castor/SvcFactory.hpp"
// Local Includes
#include "NoMsgSvc.hpp"
// -----------------------------------------------------------------------
// Instantiation of a static factory class
// -----------------------------------------------------------------------
static castor::SvcFactory<castor::NoMsgSvc> s_factoryNoMsgSvc;
const castor::IFactory<castor::IService>& NoMsgSvcFactory = s_factoryNoMsgSvc;
// -----------------------------------------------------------------------
// Constructor
// -----------------------------------------------------------------------
castor::NoMsgSvc::NoMsgSvc(const std::string name) throw() :
MsgSvc(name) {}
// -----------------------------------------------------------------------
// id
// -----------------------------------------------------------------------
const unsigned int castor::NoMsgSvc::id() const {
return ID();
}
// -----------------------------------------------------------------------
// ID
// -----------------------------------------------------------------------
const unsigned int castor::NoMsgSvc::ID() {
return SVC_NOMSG;
}
/******************************************************************************
* NoMsgSvc.hpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: NoMsgSvc.hpp,v $ $Revision: 1.1 $ $Release$ $Date: 2004/07/12 14:19:02 $ $Author: sponcec3 $
*
* A message service writing nowhere
*
* @author Sebastien Ponce
*****************************************************************************/
#ifndef CASTOR_NOMSGSVC_HPP
#define CASTOR_NOMSGSVC_HPP 1
// Local Includes
#include "castor/MsgSvc.hpp"
namespace castor {
/**
* A message service not logging at all
*/
class NoMsgSvc : public MsgSvc {
public:
/**
* Constructor
*/
NoMsgSvc(const std::string name) throw();
/**
* Destructor
*/
virtual ~NoMsgSvc() throw() {};
/**
* Get the service id
*/
virtual const unsigned int id() const;
/**
* Get the service id, statically
*/
static const unsigned int ID();
};
} // end of namespace castor
#endif // CASTOR_NOMSGSVC_HPP
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: Services.cpp,v $ $Revision: 1.7 $ $Release$ $Date: 2004/07/08 08:37:33 $ $Author: sponcec3 $
* @(#)$RCSfile: Services.cpp,v $ $Revision: 1.8 $ $Release$ $Date: 2004/07/12 14:19:02 $ $Author: sponcec3 $
*
*
*
......@@ -58,7 +58,8 @@ castor::Services::~Services() {
// service
//-----------------------------------------------------------------------------
castor::IService* castor::Services::service(const std::string name,
const unsigned int id) throw() {
const unsigned int id)
throw(castor::exception::Exception) {
std::map<const std::string, IService*>::const_iterator it =
m_services.find(name);
if (it == m_services.end()) {
......@@ -88,7 +89,8 @@ castor::IService* castor::Services::service(const std::string name,
// cnvService
//-----------------------------------------------------------------------------
castor::ICnvSvc* castor::Services::cnvService(const std::string name,
const unsigned int id) throw() {
const unsigned int id)
throw(castor::exception::Exception) {
IService* svc = service(name, id);
if (0 == svc) {
return 0;
......@@ -151,7 +153,8 @@ void castor::Services::deleteRep(castor::IAddress* address,
// cnvSvcFromAddress
// -----------------------------------------------------------------------
castor::ICnvSvc*
castor::Services::cnvSvcFromAddress(castor::IAddress* address) {
castor::Services::cnvSvcFromAddress(castor::IAddress* address)
throw (castor::exception::Exception) {
// check address
if (0 == address) {
castor::exception::Internal ex;
......
......@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @(#)$RCSfile: Services.hpp,v $ $Revision: 1.9 $ $Release$ $Date: 2004/07/08 08:37:33 $ $Author: sponcec3 $
* @(#)$RCSfile: Services.hpp,v $ $Revision: 1.10 $ $Release$ $Date: 2004/07/12 14:19:02 $ $Author: sponcec3 $
*
*
*
......@@ -58,7 +58,8 @@ namespace castor {
* is created.
*/
IService* service (const std::string name,
const unsigned int id = 0) throw();
const unsigned int id = 0)
throw(castor::exception::Exception);
/**
* gets a conversion service by name.
......@@ -66,7 +67,8 @@ namespace castor {
* is created.
*/
ICnvSvc* cnvService (const std::string name,
const unsigned int id = 0) throw();
const unsigned int id = 0)
throw(castor::exception::Exception);
/**
* removes reference to a service. This means that it will be
......@@ -164,7 +166,8 @@ namespace castor {
* gets a conversion service able to deal with a given
* address
*/
castor::ICnvSvc* cnvSvcFromAddress(castor::IAddress* address);
castor::ICnvSvc* cnvSvcFromAddress(castor::IAddress* address)
throw (castor::exception::Exception);
private:
......
/******************************************************************************
* StdMsgSvc.cpp
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*