Пример #1
0
Logger::Logger(ostream &out) : out(out.rdbuf())
{
    pthread_mutex_lock(&counterLock);
    threadCount++;
    pthread_mutex_unlock(&counterLock);
    
    clientPort = 0;
    
    if(threadCount==1)
    {
        if(pthread_attr_init(&threadAttr))
        {
            out<<"ERROR: Failed to initialize thread attribute"<<endl;
            return;
        }
    
        if(pthread_attr_setdetachstate(&threadAttr, PTHREAD_CREATE_JOINABLE))
        {
            out<<"ERROR: Failed to set detach state"<<endl;
            out<<"ERROR: Failed to allocate memory for LoggerImpl"<<endl;
            return;
        }
        
        //First ever Logger instance gets to start the log writing thread
        int ret = pthread_create(&thread, &threadAttr, logWriter, this);
        if(ret)
        {
            out<<"ERROR: Failed to start log printer thread. Error code: "<<strerror(ret)<<endl;
            threadCount = 0;
            return;
        }
    }
}
Пример #2
0
ostream&  __STL_CALL operator<<(ostream& __os,
                                const basic_string<_CharT,_Traits,_Alloc>& __s)
{
    __STL_USING_VENDOR_STD
    streambuf* __buf = __os.rdbuf();
    if (__buf) {
        size_t __n = __s.size();
        size_t __pad_len = 0;
        const bool __left = (__os.flags() & ios::left) !=0;
        const size_t __w = __os.width();

        if (__w > 0) {
            __n = min(__w, __n);
            __pad_len = __w - __n;
        }

        if (!__left)
            __sgi_string_fill(__os, __buf, __pad_len);

        const size_t __nwritten = __buf->sputn(__s.data(), __n);

        if (__left)
            __sgi_string_fill(__os, __buf, __pad_len);

        if (__nwritten != __n)
            __os.clear(__os.rdstate() | ios::failbit);

        __os.width(0);
    }
    else
        __os.clear(__os.rdstate() | ios::badbit);

    return __os;
}
Пример #3
0
void redirect (ostream& strm)
{
    ofstream file("redirect.txt");
    
    // save output buffer of the stream
    streambuf* strm_buffer = strm.rdbuf();

    // redirect ouput into the file
    strm.rdbuf (file.rdbuf());

    file << "one row for the file" << endl;
    strm << "one row for the stream" << endl;

    // restore old output buffer
    strm.rdbuf (strm_buffer);

}    // closes file AND its buffer automatically
Пример #4
0
void redirect (ostream& strm)
{
    // save output buffer of the stream
    // - use unique pointer with deleter that ensures to restore
    //     the original output buffer at the end of the function
    auto del = [&](streambuf* p) {
                   strm.rdbuf(p);
               };
    unique_ptr<streambuf,decltype(del)> origBuffer(strm.rdbuf(),del);

    // redirect ouput into the file redirect.txt
    ofstream file("redirect.txt");
    strm.rdbuf (file.rdbuf());

    file << "one row for the file" << endl;
    strm << "one row for the stream" << endl;
} // closes file AND its buffer automatically
Пример #5
0
 SVOutStream::SVOutStream(ostream& out, const String& sep,
                          const String& replacement,
                          String::QuotingMethod quoting) :
   ostream(out.rdbuf()), sep_(sep), replacement_(replacement), nan_("nan"),
   inf_("inf"), quoting_(quoting), modify_strings_(true), newline_(true)
 {
   // use high decimal precision (appropriate for double):
   precision(std::numeric_limits<double>::digits10);
 }
Пример #6
0
bool
ios_base::sync_with_stdio(bool sync)
{
    static ios_base::Init  __make_sure_streams_are_constructed;
    static bool previous_sync = true;
    bool result = previous_sync;
    previous_sync = sync;
    cin.rdbuf()->pubsetbuf(0, !sync);
    cout.rdbuf()->pubsetbuf(0, !sync);
    clog.rdbuf()->pubsetbuf(0, !sync);
    cerr.rdbuf()->pubsetbuf(0, !sync);
#ifndef _EWL_NO_WCHART_CPP_SUPPORT
    wcin.rdbuf()->pubsetbuf(0, !sync);
    wcout.rdbuf()->pubsetbuf(0, !sync);
    wclog.rdbuf()->pubsetbuf(0, !sync);
    wcerr.rdbuf()->pubsetbuf(0, !sync);
#endif  // _EWL_NO_WCHART_CPP_SUPPORT
    return result;
}
Пример #7
0
void Environment::setLogFile(const string& x)
{
  // Bye bye message
  if (!logfilename.empty())
    logger << "Stop logging at " << Date::now() << endl;

  // Close an eventual existing log file.
  if (logfile.is_open()) logfile.close();

  // No new logfile specified: redirect to the standard output stream
  if (x.empty() || x == "+")
  {
    logfilename = x;
    logger.rdbuf(cout.rdbuf());
    return;
  }

  // Open the file: either as a new file, either appending to existing file
  if (x[0] != '+') logfile.open(x.c_str(), ios::out);
  else logfile.open(x.c_str()+1, ios::app);
  if (!logfile.good())
  {
    // Redirect to the previous logfile (or cout if that's not possible)
    if (logfile.is_open()) logfile.close();
    logfile.open(logfilename.c_str(), ios::app);
    logger.rdbuf(logfile.is_open() ? logfile.rdbuf() : cout.rdbuf());
    // The log file could not be opened
    throw RuntimeException("Could not open log file '" + x + "'");
  }

  // Store the file name
  logfilename = x;

  // Redirect the log file.
  logger.rdbuf(logfile.rdbuf());

  // Print a nice header
  logger << "Start logging frePPLe " << PACKAGE_VERSION << " ("
      << __DATE__ << ") at " << Date::now() << endl;
}
Пример #8
0
ostream::ostream(const ostream& _ostrm)
{
    init(_ostrm.rdbuf());

    x_floatused = 0;
}
Пример #9
0
void genLineDirective( ostream &out )
{
	std::streambuf *sbuf = out.rdbuf();
	output_filter *filter = static_cast<output_filter*>(sbuf);
	lineDirective( out, filter->fileName, filter->line + 1 );
}
Пример #10
0
 ostream::ostream(ostream const& rhs)
 :   std::ios(0), base_type(rhs.rdbuf()), impl_(rhs.impl_)
 {
     this->copyfmt(rhs);
     this->clear(rhs.rdstate());
 }
Пример #11
0
// Threadsafe print a given stream.
void print_stream(ostream &strng)
{
	cout << strng.rdbuf();
	cout.flush();
	strng.clear();
}
Пример #12
0
void
Redirect( ostream& from, ostream& to )
{
  CheckInit();
  from.rdbuf( to.rdbuf() );
}
	    StreamBuf_Swapper(ostream & orig, ostream & replacement)
		          : buf_(orig.rdbuf()), str_(orig)
	    {
	        orig.rdbuf(replacement.rdbuf());
	    }
void
Nav2Logging::deleteHandlers(ostream& logStream)
{
   if (dynamic_cast<LogBuffer*>(logStream.rdbuf()) != NULL)
      static_cast<LogBuffer*>(logStream.rdbuf())->deleteHandlers();
}