1
// Copyright (C) 2003-2007 Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
4
// First added: 2003-03-13
5
// Last changed: 2007-05-15
10
#include <dolfin/constants.h>
11
#include <dolfin/log.h>
12
#include <dolfin/LogManager.h>
13
#include <dolfin/LogStream.h>
15
using namespace dolfin;
17
// Definition of the global cout and endl variables
18
LogStream dolfin::cout(LogStream::COUT);
19
LogStream dolfin::endl(LogStream::ENDL);
21
//-----------------------------------------------------------------------------
22
LogStream::LogStream(Type type)
25
buffer = new char[DOLFIN_LINELENGTH];
28
//-----------------------------------------------------------------------------
29
LogStream::~LogStream()
34
//-----------------------------------------------------------------------------
35
LogStream& LogStream::operator<<(const char* s)
40
//-----------------------------------------------------------------------------
41
LogStream& LogStream::operator<<(const std::string& s)
46
//-----------------------------------------------------------------------------
47
LogStream& LogStream::operator<<(const LogStream& stream)
49
if (stream.type == ENDL)
51
LogManager::logger.message(buffer);
60
//-----------------------------------------------------------------------------
61
LogStream& LogStream::operator<<(int a)
63
char tmp[DOLFIN_LINELENGTH];
64
snprintf(tmp, DOLFIN_LINELENGTH, "%d", a);
68
//-----------------------------------------------------------------------------
69
LogStream& LogStream::operator<<(unsigned int a)
71
char tmp[DOLFIN_LINELENGTH];
72
snprintf(tmp, DOLFIN_LINELENGTH, "%u", a);
76
//-----------------------------------------------------------------------------
77
LogStream& LogStream::operator<<(real a)
79
char tmp[DOLFIN_LINELENGTH];
81
if (fabs(a) < 1e-5 || fabs(a) > 1e5)
82
sprintf(tmp, "%e", a);
84
sprintf(tmp, "%f", a);
86
snprintf(tmp, DOLFIN_LINELENGTH, "%.3g", a);
90
//-----------------------------------------------------------------------------
91
LogStream& LogStream::operator<<(complex z)
93
char tmp[DOLFIN_LINELENGTH];
94
snprintf(tmp, DOLFIN_LINELENGTH, "%f + %fi", z.real(), z.imag());
98
//-----------------------------------------------------------------------------
99
void LogStream::disp() const
101
// This is used for debugging
103
printf("This i a LogStream of type ");
112
printf("The buffer size is %d. Currently at position %d. \n",
113
DOLFIN_LINELENGTH, current);
115
//-----------------------------------------------------------------------------
116
void LogStream::add(const char* msg)
118
for (int i = 0; msg[i]; i++)
120
if (current >= (DOLFIN_LINELENGTH-1))
122
LogManager::logger.message(buffer);
127
buffer[current++] = msg[i];
129
buffer[current] = '\0';
131
//-----------------------------------------------------------------------------