3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
9 * Full author contact details are available in file CREDITS.
14 #include "support/debug.h"
15 #include "support/gettext.h"
17 #include "support/convert.h"
18 #include "support/lstrings.h"
19 #include "support/FileName.h"
25 using namespace lyx::support;
38 ErrorItem errorTags[] = {
39 { Debug::NONE, "none", N_("No debugging message")},
40 { Debug::INFO, "info", N_("General information")},
41 { Debug::DEBUG, "debug", N_("Developers' general debug messages")},
42 { Debug::ANY, "any", N_("All debugging messages")}
46 int const numErrorTags = sizeof(errorTags)/sizeof(errorTags[0]);
51 Debug::Type Debug::value(string const & val)
56 string::size_type const st = v.find(',');
57 string const tmp(ascii_lowercase(v.substr(0, st)));
62 l |= static_cast<Type>(convert<int>(tmp));
64 // Search for an explicit name
65 for (int i = 0 ; i < numErrorTags ; ++i)
66 if (tmp == errorTags[i].name) {
67 l |= errorTags[i].level;
70 if (st == string::npos) break;
77 void Debug::showLevel(ostream & os, Debug::Type level)
79 // Show what features are traced
80 for (int i = 0; i < numErrorTags ; ++i) {
81 if (errorTags[i].level != Debug::ANY
82 && errorTags[i].level != Debug::NONE
83 && errorTags[i].level & level) {
84 // avoid to_utf8(_(...)) re-entrance problem
85 docstring const s = _(errorTags[i].desc);
86 os << to_utf8(bformat(_("Debugging `%1$s' (%2$s)"),
87 from_utf8(errorTags[i].name), s))
95 void Debug::showTags(ostream & os)
97 for (int i = 0; i < numErrorTags ; ++i)
98 os << setw(10) << static_cast<unsigned int>(errorTags[i].level)
99 << setw(13) << errorTags[i].name
100 << " " << to_utf8(_(errorTags[i].desc)) << '\n';
105 void LyXErr::disable()
111 void LyXErr::enable()
117 bool LyXErr::debugging(Debug::Type t) const
125 stream() << std::endl;
129 LyXErr & operator<<(LyXErr & l, void const * t)
130 { l.stream() << t; return l; }
131 LyXErr & operator<<(LyXErr & l, char const * t)
132 { l.stream() << t; return l; }
133 LyXErr & operator<<(LyXErr & l, char t)
134 { l.stream() << t; return l; }
135 LyXErr & operator<<(LyXErr & l, int t)
136 { l.stream() << t; return l; }
137 LyXErr & operator<<(LyXErr & l, unsigned int t)
138 { l.stream() << t; return l; }
139 LyXErr & operator<<(LyXErr & l, long t)
140 { l.stream() << t; return l; }
141 LyXErr & operator<<(LyXErr & l, unsigned long t)
142 { l.stream() << t; return l; }
143 LyXErr & operator<<(LyXErr & l, double t)
144 { l.stream() << t; return l; }
145 LyXErr & operator<<(LyXErr & l, std::string const & t)
146 { l.stream() << t; return l; }
147 LyXErr & operator<<(LyXErr & l, docstring const & t)
148 { l.stream() << to_utf8(t); return l; }
149 LyXErr & operator<<(LyXErr & l, support::FileName const & t)
150 { l.stream() << t; return l; }
151 LyXErr & operator<<(LyXErr & l, std::ostream &(*t)(std::ostream &))
152 { l.stream() << t; return l; }
153 LyXErr & operator<<(LyXErr & l, std::ios_base &(*t)(std::ios_base &))
154 { l.stream() << t; return l; }