Refactor logging, improve error handling workflow, clang-format. (#3385)

This commit is contained in:
Daniel Patterson
2016-12-06 12:30:46 -08:00
committed by GitHub
parent 6f4c6e84ae
commit 468d8c0031
62 changed files with 1778 additions and 1607 deletions
+5 -4
View File
@@ -2,8 +2,9 @@
#define OSRM_STORAGE_IO_HPP_
#include "util/exception.hpp"
#include "util/exception_utils.hpp"
#include "util/fingerprint.hpp"
#include "util/simple_logger.hpp"
#include "util/log.hpp"
#include <boost/filesystem/fstream.hpp>
#include <boost/iostreams/seek.hpp>
@@ -55,7 +56,7 @@ class FileReader
if (flag == VerifyFingerprint && !ReadAndCheckFingerprint())
{
throw util::exception("Fingerprint mismatch in " + filepath.string());
throw util::exception("Fingerprint mismatch in " + filepath_.string() + SOURCE_REF);
}
}
@@ -77,9 +78,9 @@ class FileReader
if (result.eof())
{
throw util::exception("Error reading from " + filepath.string() +
": Unexpected end of file");
": Unexpected end of file " + SOURCE_REF);
}
throw util::exception("Error reading from " + filepath.string());
throw util::exception("Error reading from " + filepath.string() + " " + SOURCE_REF);
}
}
+3 -3
View File
@@ -8,7 +8,7 @@
#include "storage/io.hpp"
#include "util/exception.hpp"
#include "util/fingerprint.hpp"
#include "util/simple_logger.hpp"
#include "util/log.hpp"
#include "util/static_graph.hpp"
#include <boost/filesystem/fstream.hpp>
@@ -44,8 +44,8 @@ inline HSGRHeader readHSGRHeader(io::FileReader &input_file)
const auto fingerprint_loaded = input_file.ReadOne<util::FingerPrint>();
if (!fingerprint_loaded.TestGraphUtil(fingerprint_valid))
{
util::SimpleLogger().Write(logWARNING) << ".hsgr was prepared with different build.\n"
"Reprocess to get rid of this warning.";
util::Log(logWARNING) << ".hsgr was prepared with different build.\n"
"Reprocess to get rid of this warning.";
}
HSGRHeader header;
+6 -5
View File
@@ -2,7 +2,8 @@
#define SHARED_DATA_TYPE_HPP
#include "util/exception.hpp"
#include "util/simple_logger.hpp"
#include "util/exception_utils.hpp"
#include "util/log.hpp"
#include <array>
#include <cstdint>
@@ -175,13 +176,13 @@ struct DataLayout
bool end_canary_alive = std::equal(CANARY, CANARY + sizeof(CANARY), end_canary_ptr);
if (!start_canary_alive)
{
throw util::exception(std::string("Start canary of block corrupted. (") +
block_id_to_name[bid] + ")");
throw util::exception("Start canary of block corrupted. (" +
std::string(block_id_to_name[bid]) + ")" + SOURCE_REF);
}
if (!end_canary_alive)
{
throw util::exception(std::string("End canary of block corrupted. (") +
block_id_to_name[bid] + ")");
throw util::exception("End canary of block corrupted. (" +
std::string(block_id_to_name[bid]) + ")" + SOURCE_REF);
}
}
+13 -14
View File
@@ -2,7 +2,8 @@
#define SHARED_MEMORY_HPP
#include "util/exception.hpp"
#include "util/simple_logger.hpp"
#include "util/exception_utils.hpp"
#include "util/log.hpp"
#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
@@ -62,8 +63,7 @@ class SharedMemory
{
shm = boost::interprocess::xsi_shared_memory(boost::interprocess::open_only, key);
util::SimpleLogger().Write(logDEBUG) << "opening " << shm.get_shmid() << " from id "
<< id;
util::Log(logDEBUG) << "opening " << shm.get_shmid() << " from id " << id;
region = boost::interprocess::mapped_region(shm, access);
}
@@ -72,14 +72,14 @@ class SharedMemory
{
shm = boost::interprocess::xsi_shared_memory(
boost::interprocess::open_or_create, key, size);
util::SimpleLogger().Write(logDEBUG) << "opening/creating " << shm.get_shmid()
<< " from id " << id << " with size " << size;
util::Log(logDEBUG) << "opening/creating " << shm.get_shmid() << " from id " << id
<< " with size " << size;
#ifdef __linux__
if (-1 == shmctl(shm.get_shmid(), SHM_LOCK, nullptr))
{
if (ENOMEM == errno)
{
util::SimpleLogger().Write(logWARNING) << "could not lock shared memory to RAM";
util::Log(logWARNING) << "could not lock shared memory to RAM";
}
}
#endif
@@ -133,7 +133,7 @@ class SharedMemory
static bool Remove(const boost::interprocess::xsi_key &key)
{
boost::interprocess::xsi_shared_memory xsi(boost::interprocess::open_only, key);
util::SimpleLogger().Write(logDEBUG) << "deallocating prev memory " << xsi.get_shmid();
util::Log(logDEBUG) << "deallocating prev memory " << xsi.get_shmid();
return boost::interprocess::xsi_shared_memory::remove(xsi.get_shmid());
}
@@ -173,8 +173,7 @@ class SharedMemory
shm.truncate(size);
region = boost::interprocess::mapped_region(shm, access);
util::SimpleLogger().Write(logDEBUG) << "writeable memory allocated " << size
<< " bytes";
util::Log(logDEBUG) << "writeable memory allocated " << size << " bytes";
}
}
@@ -221,7 +220,7 @@ class SharedMemory
static bool Remove(char *key)
{
util::SimpleLogger().Write(logDEBUG) << "deallocating prev memory for key " << key;
util::Log(logDEBUG) << "deallocating prev memory for key " << key;
return boost::interprocess::shared_memory_object::remove(key);
}
@@ -242,7 +241,7 @@ makeSharedMemory(const IdentifierT &id, const uint64_t size = 0, bool read_write
{
if (0 == size)
{
throw util::exception("lock file does not exist, exiting");
throw util::exception("lock file does not exist, exiting" + SOURCE_REF);
}
else
{
@@ -253,9 +252,9 @@ makeSharedMemory(const IdentifierT &id, const uint64_t size = 0, bool read_write
}
catch (const boost::interprocess::interprocess_exception &e)
{
util::SimpleLogger().Write(logWARNING) << "caught exception: " << e.what() << ", code "
<< e.get_error_code();
throw util::exception(e.what());
util::Log(logERROR) << "Error while attempting to allocate shared memory: " << e.what()
<< ", code " << e.get_error_code();
throw util::exception(e.what() + SOURCE_REF);
}
}
}