33 #include <android/log.h>
39 using std::ostringstream;
42 Notify *Notify::_global_ptr =
nullptr;
49 _ostream_ptr = &std::cerr;
50 _owns_ostream_ptr =
false;
51 _null_ostream_ptr =
new std::fstream;
53 _assert_handler =
nullptr;
54 _assert_failed =
false;
62 if (_owns_ostream_ptr) {
65 delete _null_ostream_ptr;
76 if (_owns_ostream_ptr && ostream_ptr != _ostream_ptr) {
80 if (ostream_ptr ==
nullptr) {
82 _owns_ostream_ptr =
false;
84 _ostream_ptr = ostream_ptr;
85 _owns_ostream_ptr = delete_later;
109 static bool got_flag =
false;
110 static ios_fmtflags flag;
113 #ifndef PHAVE_IOSTREAM
114 flag = std::ios::bitalloc();
118 flag = (ios_fmtflags)0;
139 _assert_handler = assert_handler;
148 _assert_handler =
nullptr;
156 return (_assert_handler !=
nullptr);
165 return _assert_handler;
185 nassertr(basename.find(
':') == string::npos,
nullptr);
188 if (parent_category !=
nullptr) {
189 fullname = parent_category->get_fullname() +
":" + basename;
194 if (!basename.empty()) {
196 fullname =
":" + basename;
200 std::pair<Categories::iterator, bool> result =
201 _categories.insert(Categories::value_type(fullname,
nullptr));
203 bool inserted = result.second;
209 category =
new NotifyCategory(fullname, basename, parent_category);
222 get_category(
const string &basename,
const string &parent_fullname) {
235 Categories::const_iterator ci;
236 ci = _categories.find(fullname);
237 if (ci != _categories.end()) {
244 string basename = fullname;
246 size_t colon = fullname.rfind(
':');
247 if (colon != string::npos) {
248 parent_category =
get_category(fullname.substr(0, colon));
249 basename = fullname.substr(colon + 1);
251 }
else if (!fullname.empty()) {
266 return *(
ptr()->_ostream_ptr);
275 return *(
ptr()->_null_ostream_ptr);
285 out() << str <<
"\n";
294 if (_global_ptr ==
nullptr) {
313 const char *source_file) {
329 const char *source_file) {
330 ostringstream message_str;
332 << expression <<
" at line " << line <<
" of " << source_file;
333 string message = message_str.str();
335 if (!_assert_failed) {
338 _assert_failed =
true;
339 _assert_error_message = message;
343 return (*_assert_handler)(expression, line, source_file);
347 __android_log_assert(
"assert",
"Panda3D",
"Assertion failed: %s", message.c_str());
349 nout <<
"Assertion failed: " << message <<
"\n";
393 for (string::const_iterator si = str.begin();
396 lstring += (char)tolower(*si);
399 if (lstring ==
"spam") {
402 }
else if (lstring ==
"debug") {
405 }
else if (lstring ==
"info") {
408 }
else if (lstring ==
"warning") {
411 }
else if (lstring ==
"error") {
414 }
else if (lstring ==
"fatal") {
418 return NS_unspecified;
433 if (_ostream_ptr == &cerr) {
435 (
"notify-output",
"",
436 "The filename to which to write all the output of notify");
439 static std::atomic_flag initialized = ATOMIC_FLAG_INIT;
441 std::string value = notify_output.
get_value();
442 if (!value.empty() && !initialized.test_and_set()) {
443 if (value ==
"stdout") {
444 cout.setf(std::ios::unitbuf);
447 }
else if (value ==
"stderr") {
457 int logfile_fd = open(os_specific.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
458 if (logfile_fd < 0) {
459 nout <<
"Unable to open file " << filename <<
" for output.\n";
461 dup2(logfile_fd, STDOUT_FILENO);
462 dup2(logfile_fd, STDERR_FILENO);
468 pofstream *
out =
new pofstream;
470 nout <<
"Unable to open file " << filename <<
" for output.\n";
473 out->setf(std::ios::unitbuf);
This is a convenience class to specialize ConfigVariable as a boolean type.
This is a convenience class to specialize ConfigVariable as a Filename type.
get_value
Returns the variable's value.
The name of a file, such as a texture file or an Egg file.
std::string to_os_specific() const
Converts the filename from our generic Unix-like convention (forward slashes starting with the root a...
void set_text()
Indicates that the filename represents a text file.
bool open_write(std::ofstream &stream, bool truncate=true) const
Opens the indicated ifstream for writing the file, if possible.
A particular category of error messages.
An object that handles general error reporting to the user.
static std::ostream & out()
A convenient way to get the ostream that should be written to for a Notify- type message.
static void write_string(const std::string &str)
A convenient way for scripting languages, which may know nothing about ostreams, to write to Notify.
void clear_assert_handler()
Removes the installed assert handler and restores default behavior of nassertr() and nassertv().
void set_assert_handler(AssertHandler *assert_handler)
Sets a pointer to a C function that will be called when an assertion test fails.
NotifyCategory * get_top_category()
Returns the topmost Category in the hierarchy.
bool assert_failure(const std::string &expression, int line, const char *source_file)
This function is not intended to be called directly by user code.
void config_initialized()
Intended to be called only by Config, this is a callback that indicates to Notify when Config has don...
std::ostream * get_ostream_ptr() const
Returns the system-wide ostream for all Notify messages.
static NotifySeverity string_severity(const std::string &string)
Given a string, one of "debug", "info", "warning", etc., return the corresponding Severity level,...
AssertHandler * get_assert_handler() const
Returns a pointer to the user-installed assert handler, if one was installed, or NULL otherwise.
static std::ostream & null()
A convenient way to get an ostream that doesn't do anything.
NotifyCategory * get_category(const std::string &basename, NotifyCategory *parent_category)
Finds or creates a new Category given the basename of the category and its parent in the category hie...
static Notify * ptr()
Returns the pointer to the global Notify object.
bool has_assert_handler() const
Returns true if a user assert handler has been installed, false otherwise.
static ios_fmtflags get_literal_flag()
Returns a flag that may be set on the Notify stream via setf() that, when set, enables "literal" mode...
void set_ostream_ptr(std::ostream *ostream_ptr, bool delete_later)
Changes the ostream that all subsequent Notify messages will be written to.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.