void GlobalDebug::log(::CPLErr code, int num, char const* msg) { std::ostringstream oss; if (code == CE_Failure || code == CE_Fatal) { oss <<"GDAL Failure number=" << num << ": " << msg; throw pdal::gdal_error(oss.str()); } else if (code == CE_Debug) { oss << "Global GDAL debug: " << msg; std::vector<LogPtr>::const_iterator i; std::map<std::ostream*, LogPtr> streams; for (i = m_logs.begin(); i != m_logs.end(); ++i) { streams.insert(std::pair<std::ostream*, LogPtr>((*i)->getLogStream(), *i)); } std::map<std::ostream*, LogPtr>::const_iterator t; for (t = streams.begin(); t != streams.end(); t++) { LogPtr l = t->second; if (l->getLevel() > logDEBUG) l->get(logDEBUG) << oss.str() << std::endl; } return; } else { return; } }
int App::execute(StringList& cmdArgs, LogPtr& log) { ProgramArgs args; addArgs(args); try { args.parseSimple(cmdArgs); } catch (arg_val_error const& e) { Utils::printError(e.what()); return -1; } log.reset(new Log("PDAL", m_log, m_logtiming)); if (m_logLevel != LogLevel::None) log->setLevel(m_logLevel); else if (m_debug) log->setLevel(LogLevel::Debug); log->get(LogLevel::Debug) << "Debugging..." << std::endl; PluginManager<Stage>::setLog(log); PluginManager<Kernel>::setLog(log); #ifndef _WIN32 if (m_debug) { signal(SIGSEGV, [](int sig) { logPtr->get(LogLevel::Debug) << "Segmentation fault (signal 11)\n"; StringList lines = Utils::backtrace(); for (const auto& l : lines) logPtr->get(LogLevel::Debug) << l << std::endl; exit(1); }); } #endif m_command = Utils::tolower(m_command); if (!m_command.empty()) { int ret = 0; std::string name("kernels." + m_command); Kernel *kernel = PluginManager<Kernel>::createObject(name); if (kernel) { if (m_help) cmdArgs.push_back("--help"); // This shouldn't throw. If it does, it's something awful, so // not cleaning up seems inconsequential. log->setLeader("pdal " + m_command); ret = kernel->run(cmdArgs, log); delete kernel; // IMPORTANT - The kernel must be destroyed before GDAL // drivers are unregistered or GDAL will attempt to destroy // resources more than once, resulting in a crash. gdal::unregisterDrivers(); } else log->get(LogLevel::Error) << "Command '" << m_command << "' not recognized" << std::endl << std::endl; return ret; } if (m_showVersion) outputVersion(); else if (m_showDrivers) outputDrivers(); else if (m_showOptions.size()) { if (m_showOptions == "all") outputOptions(); else outputOptions(m_showOptions, m_out); } else outputHelp(args); return 0; }