Line 1... |
Line 1... |
// $Id: RlogFile.cpp 611 2014-12-10 23:23:58Z mueller $
|
// $Id: RlogFile.cpp 631 2015-01-09 21:36:51Z mueller $
|
//
|
//
|
// Copyright 2011-2014 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
// Copyright 2011-2015 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
|
//
|
//
|
// This program is free software; you may redistribute and/or modify it under
|
// This program is free software; you may redistribute and/or modify it under
|
// the terms of the GNU General Public License as published by the Free
|
// the terms of the GNU General Public License as published by the Free
|
// Software Foundation, either version 2, or at your option any later version.
|
// Software Foundation, either version 2, or at your option any later version.
|
//
|
//
|
Line 11... |
Line 11... |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
// for complete details.
|
// for complete details.
|
//
|
//
|
// Revision History:
|
// Revision History:
|
// Date Rev Version Comment
|
// Date Rev Version Comment
|
|
// 2015-01-08 631 2.2 Open(): now with RerrMsg and cout/cerr support
|
// 2014-12-10 611 2.1.2 timestamp now usec precision (was msec)
|
// 2014-12-10 611 2.1.2 timestamp now usec precision (was msec)
|
// 2013-10-11 539 2.1.1 fix date print (month was off by one)
|
// 2013-10-11 539 2.1.1 fix date print (month was off by one)
|
// 2013-02-23 492 2.1 add Name(), keep log file name; add Dump()
|
// 2013-02-23 492 2.1 add Name(), keep log file name; add Dump()
|
// 2013-02-22 491 2.0 add Write(),IsNew(), RlogMsg iface; use lockable
|
// 2013-02-22 491 2.0 add Write(),IsNew(), RlogMsg iface; use lockable
|
// 2011-01-30 357 1.0 Initial version
|
// 2011-01-30 357 1.0 Initial version
|
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
|
|
/*!
|
/*!
|
\file
|
\file
|
\version $Id: RlogFile.cpp 611 2014-12-10 23:23:58Z mueller $
|
\version $Id: RlogFile.cpp 631 2015-01-09 21:36:51Z mueller $
|
\brief Implemenation of RlogFile.
|
\brief Implemenation of RlogFile.
|
*/
|
*/
|
|
|
#include <sys/time.h>
|
#include <sys/time.h>
|
|
#include <errno.h>
|
|
|
#include "boost/thread/locks.hpp"
|
#include "boost/thread/locks.hpp"
|
|
|
#include "RosFill.hpp"
|
#include "RosFill.hpp"
|
#include "RosPrintf.hpp"
|
#include "RosPrintf.hpp"
|
Line 48... |
Line 50... |
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! Default constructor
|
//! Default constructor
|
|
|
RlogFile::RlogFile()
|
RlogFile::RlogFile()
|
: fpExtStream(0),
|
: fpExtStream(nullptr),
|
fIntStream(),
|
fIntStream(),
|
fNew(true),
|
fNew(true),
|
fName(),
|
fName(),
|
fMutex()
|
fMutex()
|
{
|
{
|
Line 64... |
Line 66... |
|
|
RlogFile::RlogFile(std::ostream* os, const std::string& name)
|
RlogFile::RlogFile(std::ostream* os, const std::string& name)
|
: fpExtStream(os),
|
: fpExtStream(os),
|
fIntStream(),
|
fIntStream(),
|
fNew(false),
|
fNew(false),
|
fName(name),
|
fName(BuildinStreamName(os, name)),
|
fMutex()
|
fMutex()
|
{
|
{
|
ClearTime();
|
ClearTime();
|
}
|
}
|
|
|
Line 79... |
Line 81... |
{}
|
{}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
|
|
bool RlogFile::Open(std::string name)
|
bool RlogFile::Open(std::string name, RerrMsg& emsg)
|
{
|
{
|
|
std::ostream* os = nullptr;
|
|
if (name == "<cout>" || name == "-") os = &cout;
|
|
else if (name == "<cerr>") os = &cerr;
|
|
else if (name == "<clog>") os = &clog;
|
|
if (os) {
|
|
UseStream(os);
|
|
return true;
|
|
}
|
|
|
fNew = false;
|
fNew = false;
|
fpExtStream = 0;
|
fpExtStream = nullptr;
|
fName = name;
|
fName = name;
|
fIntStream.open(name.c_str());
|
fIntStream.open(name.c_str());
|
|
if (!fIntStream.is_open())
|
|
emsg.InitErrno("RlogFile::Open",
|
|
string("open for '") + name + "' failed: ",
|
|
errno);
|
return fIntStream.is_open();
|
return fIntStream.is_open();
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
Line 105... |
Line 120... |
void RlogFile::UseStream(std::ostream* os, const std::string& name)
|
void RlogFile::UseStream(std::ostream* os, const std::string& name)
|
{
|
{
|
fNew = false;
|
fNew = false;
|
if (fIntStream.is_open()) Close();
|
if (fIntStream.is_open()) Close();
|
fpExtStream = os;
|
fpExtStream = os;
|
fName = name;
|
fName = BuildinStreamName(os, name);
|
return;
|
return;
|
}
|
}
|
|
|
//------------------------------------------+-----------------------------------
|
//------------------------------------------+-----------------------------------
|
//! FIXME_docs
|
//! FIXME_docs
|
Line 207... |
Line 222... |
fTagMonth = -1;
|
fTagMonth = -1;
|
fTagDay = -1;
|
fTagDay = -1;
|
return;
|
return;
|
}
|
}
|
|
|
|
//------------------------------------------+-----------------------------------
|
|
//! FIXME_docs
|
|
|
|
std::string RlogFile::BuildinStreamName(std::ostream* os,
|
|
const std::string& str)
|
|
{
|
|
if (str.size()) return str;
|
|
if (os == &cout) return string("<cout>");
|
|
if (os == &cerr) return string("<cerr>");
|
|
if (os == &clog) return string("<clog>");
|
|
return string("<?stream?>");
|
|
}
|
|
|
} // end namespace Retro
|
} // end namespace Retro
|
|
|
No newline at end of file
|
No newline at end of file
|