]>
cygwin.com Git - cygwin-apps/setup.git/blob - LogSingleton.cc
2 * Copyright (c) 2002, Robert Collins..
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
12 * Written by Robert Collins <rbtcollins@hotmail.com>
16 #include "LogSingleton.h"
22 /* Helper functions */
24 /* End of a Log comment */
25 ostream
& endLog(ostream
& outs
)
27 /* Doesn't seem to be any way around this */
28 dynamic_cast<LogSingleton
&>(outs
).endEntry();
32 /* The LogSingleton class */
34 LogSingleton
* LogSingleton::theInstance(0);
36 LogSingleton::LogSingleton(std::streambuf
* aStream
) : ios (aStream
), ostream (aStream
)
40 LogSingleton::~LogSingleton(){}
43 LogSingleton::GetInstance()
46 throw new invalid_argument ("No instance has been set!");
51 LogSingleton::SetInstance(LogSingleton
&newInstance
)
53 theInstance
= &newInstance
;
57 // Logging class. Default logging level is PLAIN.
58 class LogSingleton
: public ostream
62 /* Some platforms don't call destructors. So this call exists
63 * which guarantees to flush any log data...
64 * but doesn't call generic C++ destructors
66 virtual void exit (int const exit_code
) __attribute__ ((noreturn
));
67 // get a specific verbosity stream.
68 virtual ostream
&operator() (enum log_level level
);
70 friend ostream
& endLog(ostream
& outs
);
73 LogSingleton (LogSingleton
const &); // no copy constructor
74 LogSingleton
&operator = (LogSingleton
const&); // no assignment operator
75 void endEntry(); // the current in-progress entry is complete.
77 static LogSingleton
*theInstance
;
81 // Log adapators for printf-style output
83 LogBabblePrintf(const char *fmt
, ...)
89 len
= vsnprintf (buf
, 2000, fmt
, args
);
90 if ((len
> 0) && (buf
[len
-1] == '\n'))
92 Log (LOG_BABBLE
) << buf
<< endLog
;
96 LogPlainPrintf(const char *fmt
, ...)
101 va_start (args
, fmt
);
102 len
= vsnprintf (buf
, 2000, fmt
, args
);
103 if ((len
> 0) && (buf
[len
-1] == '\n'))
105 Log (LOG_PLAIN
) << buf
<< endLog
;
This page took 0.048914 seconds and 6 git commands to generate.