MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Logger.cc File Reference
#include <Logger.h>
#include <CMakeDefinitions.h>
#include <cstdlib>
#include <iostream>

Go to the source code of this file.

Functions

static void printMessage (std::string module, std::string msg)
 
static void printError (std::string module, std::string msg)
 

Variables

LL< Log::FATAL > FATAL
 Fatal log level. More...
 
LL< Log::ERROR > ERROR
 Error log level. More...
 
LL< Log::WARN > WARN
 Warning log level. More...
 
LL< Log::INFO > INFO
 Info log level. More...
 
LL< Log::DEFAULT > DEFAULT
 Default log level. More...
 
LL< Log::VERBOSE > VERBOSE
 Verbose information. More...
 
LL< Log::DEBUG > DEBUG
 Debug information. More...
 
Logger< MERCURY_LOGLEVELlogger ("MercuryKernel")
 
LoggerOutput loggerOutputDefaultImpl
 
LoggerOutputloggerOutput = &loggerOutputDefaultImpl
 Declaration of the output functions. If the output needs to be redirected, please swap the loggerOutput pointer to your preferred LoggerOutput instance, and make sure this exists until AFTER an std::exit() invocation. (e.g. clean up with std::atexit()) More...
 

Function Documentation

static void printError ( std::string  module,
std::string  msg 
)
static

Definition at line 42 of file Logger.cc.

42  {
43  std::cerr << "Module " << module << ":\n" << msg << std::endl;
44 #if MERCURY_STACKTRACE_SHOW
45  std::cerr << "\n-----------------[Stack Trace]-----------------\n";
46 
47 
48  void* stackBuffer[64]; //This should be enough for all purposes..
49  //First, we retrieve the addresses of the entire stack...
50  int nStackFrames = backtrace(stackBuffer, 64);
51 #if !MERCURY_STACKTRACE_DEMANGLE
52  //We don't have the demangling infra, so just use backtrace_symbols.
53  char** functionNames = backtrace_symbols(stackBuffer, nStackFrames);
54  for( int i = 0; i < nStackFrames; i++ )
55  {
56  std::cerr << '\t' << functionNames[i] << '\n';
57  }
58  std::cerr << "Exiting.\n" << std::endl;
59 
60  //DO NOT USE DELETE HERE. THIS SHOULD BE free()'d!
61  // -- dducks
62  free(functionNames);
63 #else
64  //We request the symbol information ourselves, in order to be able to demangle it.
65  //And request the function names using dladdr.
66  Dl_info infoStruct;
67  for ( int i = 4; i < nStackFrames; i++ )
68  {
69  if (dladdr(stackBuffer[i], &infoStruct))
70  { // We succesfully loaded the address...
71  int demangleStatus;
72  char* fnDemangled = abi::__cxa_demangle(infoStruct.dli_sname, NULL, NULL, &demangleStatus);
73  if (infoStruct.dli_sname == nullptr)
74  continue;
75 
76  //We even succesfully demangled the symbol...
77  if (demangleStatus == 0)
78  {
79  std::cerr << fnDemangled << " +" << (void*)((char*)stackBuffer[i] - (char*)infoStruct.dli_saddr) << "\t("
80  << infoStruct.dli_fname << ")\n";
81  free(fnDemangled);
82  }
83  else
84  { //Well, we tried. Lets output at least our raw symbol name.
85  std::cerr << infoStruct.dli_sname << " +" << (void*)((char*)stackBuffer[i] - (char*)infoStruct.dli_saddr) << "\t("
86  << infoStruct.dli_fname << ")\n";
87  }
88  }
89  else
90  { //Name lookup failed.
91  std::cerr << stackBuffer[i] << ": ?????" << std::endl;
92  }
93  }
94 #endif
95 #endif
96  std::exit(2);
97 }
static void printMessage ( std::string  module,
std::string  msg 
)
static

Definition at line 37 of file Logger.cc.

37  {
38  std::cout << "Module " << module << ":\n" << msg << std::endl;
39 }

Variable Documentation

LL<Log::DEBUG> DEBUG

Debug information.

Only used for internal development. Can be very cryptic, as it is only meant for finding bugs / oddities by the internal development team.

Example: Collission found between Particle #38201 and Wall #5

Default behaviour: ignore.

Definition at line 31 of file Logger.cc.

Referenced by BaseHandler< T >::BaseHandler(), and BaseHandler< T >::~BaseHandler().

LL<Log::DEFAULT> DEFAULT

Default log level.

Only useful for defining the loglevel of the logger itself. Should not actually be used.

Definition at line 29 of file Logger.cc.

LL<Log::ERROR> ERROR

Error log level.

Error, as in, the program has found a severe problem which it cannot resolve any further. It does not know how to recover in a sane way.

Example: Negative timestep, Infinite end time and no override of the continuation function.

Default behaviour: log to std::cerr, followed by std::exit().

Definition at line 26 of file Logger.cc.

Referenced by BaseHandler< T >::getDPMBase(), BaseHandler< T >::getObject(), BaseHandler< T >::getObjectById(), helpers::getSaveCountFromNumberOfSavesAndTimeMaxAndTimestep(), main(), Species< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::mixAll(), and BaseHandler< T >::removeObject().

LL<Log::FATAL> FATAL

Fatal log level.

These are the loglevels which should be used to control the logger. They are declared here but defined in Logger.cpp

Fatal, as in, the program has suffered from the worst possible failure and there is no way it can gracefully recover.

Example: No memory allocations possible

Default behaviour: log to std::cerr, followed by std::exit().

Definition at line 25 of file Logger.cc.

Referenced by main(), and transformMercuryToVTK().

LL<Log::INFO> INFO

Info log level.

Useful information, small oddities found which should be of no real effect to the user. Also information about the current state and progress of the program.

Example: Finished inserting particles.

Default behaviour: log to std::cout, returns afterwards.

Definition at line 28 of file Logger.cc.

Referenced by transformMercuryToVTK().

Logger<MERCURY_LOGLEVEL> logger("MercuryKernel")

Default logger. Use this for general logging.

For very specific modules, define your own logger. If you want to make extensive use of Debug messages, please use a custom logger as well, to prevent polluting the output.

Referenced by PossibleContactList::add_PossibleContact(), IntersectionOfWalls::addObject(), MaserBoundary::addParticleToMaser(), AxisymmetricIntersectionOfWalls::AxisymmetricIntersectionOfWalls(), BaseHandler< T >::BaseHandler(), BaseParticle::BaseParticle(), BaseWall::BaseWall(), BoundaryHandler::BoundaryHandler(), MercuryBase::checkParticleForInteraction(), Chute::Chute(), Chute::cleanChute(), BaseWall::clear(), Coil::Coil(), ParticleHandler::computeLargestParticle(), ParticleSpecies::computeMass(), ParticleHandler::computeSmallestParticle(), Chute::createBottom(), Vec3D::getComponent(), AxisymmetricIntersectionOfWalls::getDistanceAndNormal(), BaseHandler< T >::getDPMBase(), ParticleHandler::getFastestParticle(), ParticleHandler::getHighestPositionComponentParticle(), ParticleHandler::getHighestVelocityComponentParticle(), ParticleHandler::getLargestParticle(), ParticleHandler::getLightestParticle(), ParticleHandler::getLowestPositionComponentParticle(), ParticleHandler::getLowestVelocityComponentParticle(), ParticleSpecies::getMassFromRadius(), SpeciesHandler::getMixedObject(), PossibleContact::getNext(), BaseHandler< T >::getObject(), BaseHandler< T >::getObjectById(), PossibleContact::getPrevious(), helpers::getSaveCountFromNumberOfSavesAndTimeMaxAndTimestep(), ParticleHandler::getSmallestParticle(), ChuteWithHopper::getTimeStepRatio(), BaseParticle::getVolume(), HGrid::HGrid(), Mercury2D::hGridHasParticleContacts(), MercuryBase::hGridNeedsRebuilding(), MercuryBase::hGridRebuild(), InfiniteWall::InfiniteWall(), HGrid::insertParticleToHgrid(), InteractionHandler::InteractionHandler(), IntersectionOfWalls::IntersectionOfWalls(), main(), ChuteBottom::makeRoughBottom(), Mercury2D::Mercury2D(), Mercury3D::Mercury3D(), MercuryBase::MercuryBase(), Species< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::mixAll(), InfiniteWall::move(), SpeciesHandler::operator=(), InteractionHandler::operator=(), BoundaryHandler::operator=(), ParticleHandler::operator=(), WallHandler::operator=(), IntersectionOfWalls::operator=(), ParticleHandler::ParticleHandler(), PossibleContactList::PossibleContactList(), HGridOptimiser::radius2Cell(), BaseHandler< T >::read(), DPMBase::read(), SpeciesHandler::readObject(), BoundaryHandler::readObject(), WallHandler::readObject(), ParticleHandler::readObject(), SpeciesHandler::readOldObject(), WallHandler::readOldObject(), ParticleHandler::readOldObject(), PossibleContactList::remove_ParticlePosibleContacts(), BaseHandler< T >::removeLastObject(), BaseHandler< T >::removeObject(), Screw::Screw(), InfiniteWall::set(), Chute::setChuteAngle(), Chute::setChuteAngleAndMagnitudeOfGravity(), ChuteWithHopper::setChuteLength(), Vec3D::setComponent(), ParticleSpecies::setDensity(), Chute::setFixedParticleRadius(), ChuteWithHopper::setHopper(), ChuteWithHopper::setHopperShift(), BaseParticle::setIndSpecies(), BaseParticle::setInertia(), Chute::setInflowParticleRadius(), Chute::setInflowVelocity(), Chute::setInflowVelocityVariance(), BaseParticle::setMass(), Chute::setMaxInflowParticleRadius(), Chute::setMinInflowParticleRadius(), PossibleContact::setNextPosition(), PossibleContact::setPreviousPosition(), Chute::setRoughBottomType(), ChuteBottom::setThickness(), ChuteBottom::setupInitialConditions(), Chute::setupInitialConditions(), SpeciesHandler::SpeciesHandler(), transformMercuryToVTK(), MercuryBase::userHGridCellSize(), WallHandler::WallHandler(), AxisymmetricIntersectionOfWalls::~AxisymmetricIntersectionOfWalls(), BaseHandler< T >::~BaseHandler(), BaseParticle::~BaseParticle(), BaseWall::~BaseWall(), BoundaryHandler::~BoundaryHandler(), Coil::~Coil(), HGrid::~HGrid(), InfiniteWall::~InfiniteWall(), InteractionHandler::~InteractionHandler(), IntersectionOfWalls::~IntersectionOfWalls(), MercuryBase::~MercuryBase(), ParticleHandler::~ParticleHandler(), Screw::~Screw(), SpeciesHandler::~SpeciesHandler(), and WallHandler::~WallHandler().

Declaration of the output functions. If the output needs to be redirected, please swap the loggerOutput pointer to your preferred LoggerOutput instance, and make sure this exists until AFTER an std::exit() invocation. (e.g. clean up with std::atexit())

Definition at line 110 of file Logger.cc.

Referenced by DPMBase::constructor().

LoggerOutput loggerOutputDefaultImpl
Initial value:
= {
printMessage
}
static void printError(std::string module, std::string msg)
Definition: Logger.cc:42
static void printMessage(std::string module, std::string msg)
Definition: Logger.cc:37

Definition at line 100 of file Logger.cc.

LL<Log::VERBOSE> VERBOSE

Verbose information.

Information which is not useful to anybody except those looking for weird behaviour and statistics. These should however still be clear in meaning.

Example: Inserted 381 particles in Insertion Boundary #1.

Default behaviour: ignore.

Definition at line 30 of file Logger.cc.

Referenced by main(), and BaseHandler< T >::read().

LL<Log::WARN> WARN

Warning log level.

Warning, as in, the program has detected a problem but does know a solution. The simulation can continue with this fix, but the user should look at fixing his / her simulation so this won't occur in the future.

Example: Setting a smaller Xmax than Xmin.

Default behaviour: log to std::cerr, returns afterwards.

Definition at line 27 of file Logger.cc.

Referenced by BaseHandler< T >::removeLastObject(), and transformMercuryToVTK().