33 #include <boost/lexical_cast.hpp>
36 using boost::lexical_cast;
37 namespace fs = boost::filesystem;
73 virtual ostream& os() = 0;
108 template<
typename TImpl>
112 return dl->coincideix(i_);
127 assert( !fs::exists(f) || fs::is_regular_file(f) );
128 if (fs::exists(f) && !fs::is_regular_file(f)) {
129 throw ErrorLogNoValid(
"El fitxer de log "+f.string()+
" no es pot escriure");
131 of_.open(f.string().c_str(), ios_base::out|ios_base::app);
141 virtual ostream&
os() {
145 return ( f == ruta_ );
163 virtual ostream&
os() {
167 return ( &os == &os_ );
178 destins_.push_back(shared_ptr<DestiLogging>(
new DestiOstream(os, n)));
182 destins_.push_back(shared_ptr<DestiLogging>(
new DestiFitxer(p, n)));
186 void Log::desassocia(ostream &) {
191 template<
typename TIt,
typename TImpl>
195 auto it = find_if(beg, end, FunctorCoincideix<TImpl>(d));
203 template<
typename TIt,
typename TImpl>
207 auto it = find_if(beg, end, FunctorCoincideix<TImpl>(d));
211 return (*it)->nivell();
231 for_each(destins_.begin(), destins_.end(), FunctorCanviNivell(nn));
235 string Log::marca_de_temps() {
248 struct FunctorCommit {
251 void operator()(shared_ptr<DestiLogging> & desti) {
252 if (
nivell >= desti->nivell()) {
253 desti->os() << str << flush;
258 if (ml.
str().empty()) {
261 ostringstream buffer;
262 buffer <<
"[" << marca_de_temps() <<
"] " << ml.
str() <<
"\n";
263 FunctorCommit fc(ml.
nivell(),buffer.str());
267 for (
auto it=destins_.begin(); it != destins_.end(); ++it) {
279 Log::singleton().imprimeix(ml);
314 MissatgeLog& MissatgeLog::operator<<(const std::shared_ptr<ManipuladorParametritzat> & manip) {
316 return (*pmanip)(*this);