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

Go to the source code of this file.

Functions

static void printInfo (std::string module, std::string msg)
 
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 76 of file Logger.cc.

77 {
78  std::cerr << "Module " << module << ":\n" << msg << std::endl;
79 #ifdef MERCURY_STACKTRACE_SHOW
80  std::cerr << "\n-----------------[Stack Trace]-----------------\n";
81 
82  void* stackBuffer[64]; //This should be enough for all purposes..
83  //First, we retrieve the addresses of the entire stack...
84  int nStackFrames = backtrace(stackBuffer, 64);
85 #ifndef MERCURY_STACKTRACE_DEMANGLE
86  //We don't have the demangling infra, so just use backtrace_symbols.
87  char** functionNames = backtrace_symbols(stackBuffer, nStackFrames);
88  for( int i = 0; i < nStackFrames; i++ )
89  {
90  std::cerr << '\t' << functionNames[i] << '\n';
91  }
92  std::cerr << "Exiting.\n" << std::endl;
93 
94  //DO NOT USE DELETE HERE. THIS SHOULD BE free()'d!
95  // -- dducks
96  free(functionNames);
97 #else
98  //We request the symbol information ourselves, in order to be able to demangle it.
99  //And request the function names using dladdr.
100  Dl_info infoStruct;
101  for (int i = 4; i < nStackFrames; i++)
102  {
103  if (dladdr(stackBuffer[i], &infoStruct))
104  { // We succesfully loaded the address...
105  int demangleStatus;
106  char* fnDemangled = abi::__cxa_demangle(infoStruct.dli_sname, NULL, NULL, &demangleStatus);
107  if (infoStruct.dli_sname == nullptr)
108  continue;
109 
110  //We even succesfully demangled the symbol...
111  if (demangleStatus == 0)
112  {
113  std::cerr << fnDemangled << " +" << (void*) ((char*) stackBuffer[i] - (char*) infoStruct.dli_saddr) << "\t(" << infoStruct.dli_fname << ")\n";
114  free(fnDemangled);
115  }
116  else
117  { //Well, we tried. Lets output at least our raw symbol name.
118  std::cerr << infoStruct.dli_sname << " +" << (void*) ((char*) stackBuffer[i] - (char*) infoStruct.dli_saddr) << "\t(" << infoStruct.dli_fname << ")\n";
119  }
120  }
121  else
122  { //Name lookup failed.
123  std::cerr << stackBuffer[i] << ": ?????" << std::endl;
124  }
125  }
126 #endif
127 #endif
128  //send a signal first, in case a debugger can catch it
129  std::raise(SIGTERM);
130  std::exit(2);
131 }
static void printInfo ( std::string  module,
std::string  msg 
)
static

Definition at line 63 of file Logger.cc.

64 {
65  std::cout << msg << std::endl;
66 }
static void printMessage ( std::string  module,
std::string  msg 
)
static

Definition at line 69 of file Logger.cc.

70 {
71  std::cout << "Module " << module << ":\n" << msg << std::endl;
72 }

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 56 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 54 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 51 of file Logger.cc.

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

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 50 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 53 of file Logger.cc.

Referenced by helpers::compare(), helpers::loadingTest(), main(), helpers::normalAndTangentialLoadingTest(), helpers::objectivenessTest(), helpers::readFromFile(), SinterNormalSpecies::setParhamiMcKeeping(), and 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(), ParticleHandler::addObject(), WallHandler::addObject(), IntersectionOfWalls::addObject(), MaserBoundary::addParticleToMaser(), AxisymmetricIntersectionOfWalls::AxisymmetricIntersectionOfWalls(), BaseHandler< T >::BaseHandler(), BaseInteractable::BaseInteractable(), BaseObject::BaseObject(), BaseParticle::BaseParticle(), BaseWall::BaseWall(), BoundaryHandler::BoundaryHandler(), helpers::check(), MaserBoundary::checkBoundaryAfterParticleMoved(), MercuryBase::checkParticleForInteractionLocal(), Chute::Chute(), Chute::cleanChute(), BaseWall::clear(), Coil::Coil(), helpers::compare(), ParticleHandler::computeLargestParticle(), ParticleSpecies::computeMass(), SinterInteraction::computeNormalForce(), ParticleHandler::computeSmallestParticle(), Chute::createBottom(), DeletionBoundary::DeletionBoundary(), FileReader::FileReader(), FilesAndRunNumber::FilesAndRunNumber(), Vec3D::getComponent(), AxisymmetricIntersectionOfWalls::getDistanceAndNormal(), IntersectionOfWalls::getDistanceAndNormal(), BaseHandler< T >::getDPMBase(), ChargedBondedInteraction::getElasticEnergy(), ParticleHandler::getFastestParticle(), ParticleHandler::getHighestPositionComponentParticle(), ParticleHandler::getHighestVelocityComponentParticle(), ReversibleAdhesiveSpecies::getInteractionDistance(), ParticleHandler::getLargestParticle(), ParticleHandler::getLightestParticle(), ParticleHandler::getLowestPositionComponentParticle(), ParticleHandler::getLowestVelocityComponentParticle(), SpeciesHandler::getMixedObject(), ParticleHandler::getNewObject(), PossibleContact::getNext(), BaseHandler< T >::getObject(), BaseHandler< T >::getObjectById(), PossibleContact::getPrevious(), helpers::getSaveCountFromNumberOfSavesAndTimeMaxAndTimestep(), ParticleHandler::getSmallestParticle(), ChuteWithHopper::getTimeStepRatio(), BaseParticle::getVolume(), ParticleSpecies::getVolumeFromRadius(), HGrid::HGrid(), MercuryBase::hGridActionsBeforeTimeStep(), Mercury2D::hGridHasParticleContacts(), MercuryBase::hGridInfo(), MercuryBase::hGridNeedsRebuilding(), MercuryBase::hGridRebuild(), InfiniteWall::InfiniteWall(), HGrid::info(), HGrid::insertParticleToHgrid(), InteractionHandler::InteractionHandler(), IntersectionOfWalls::IntersectionOfWalls(), BaseWall::intersectVTK(), helpers::loadingTest(), main(), ChuteBottom::makeRoughBottom(), Mercury2D::Mercury2D(), Mercury3D::Mercury3D(), MercuryBase::MercuryBase(), MindlinInteraction::MindlinInteraction(), Species< NormalForceSpecies, FrictionForceSpecies, AdhesiveForceSpecies >::mixAll(), InfiniteWall::move(), helpers::normalAndTangentialLoadingTest(), Vec3D::normalize(), helpers::objectivenessTest(), SpeciesHandler::operator=(), InteractionHandler::operator=(), BoundaryHandler::operator=(), ParticleHandler::operator=(), WallHandler::operator=(), IntersectionOfWalls::operator=(), TriangulatedWall::operator=(), operator>>(), ParticleHandler::ParticleHandler(), PeriodicBoundary::PeriodicBoundary(), PossibleContactList::PossibleContactList(), HGridOptimiser::radius2Cell(), ChargedBondedSpecies::read(), FileReader::read(), BaseHandler< T >::read(), Chute::read(), DPMBase::read(), helpers::readFromFile(), DPMBase::readNextDataFile(), SpeciesHandler::readObject(), InteractionHandler::readObject(), BoundaryHandler::readObject(), WallHandler::readObject(), ParticleHandler::readObject(), SpeciesHandler::readOldObject(), WallHandler::readOldObject(), ParticleHandler::readOldObject(), TriangulatedWall::readVTK(), PossibleContactList::remove_ParticlePosibleContacts(), BaseInteractable::removeInteraction(), BaseHandler< T >::removeLastObject(), BaseHandler< T >::removeObject(), RestrictedWall::RestrictedWall(), Screw::Screw(), PeriodicBoundary::set(), InfiniteWall::set(), Chute::setChuteAngle(), Chute::setChuteAngleAndMagnitudeOfGravity(), ChuteWithHopper::setChuteLength(), LinearViscoelasticNormalSpecies::setCollisionTimeAndRestitutionCoefficient(), Vec3D::setComponent(), ParticleSpecies::setDensity(), SinterNormalSpecies::setDissipation(), HertzianViscoelasticNormalSpecies::setElasticModulusAndRestitutionCoefficient(), Chute::setFixedParticleRadius(), ThermalSpecies< NormalForceSpecies >::setHeatCapacity(), ChuteWithHopper::setHopper(), ChuteWithHopper::setHopperShift(), BaseWall::setIndSpecies(), BaseParticle::setIndSpecies(), BaseParticle::setInertia(), Chute::setInflowParticleRadius(), Chute::setInflowVelocity(), Chute::setInflowVelocityVariance(), SinterNormalSpecies::setInverseSinterViscosity(), BaseParticle::setMass(), BaseParticle::setMassForP3Statistics(), Chute::setMaxInflowParticleRadius(), Chute::setMinInflowParticleRadius(), PossibleContact::setNextPosition(), SinterNormalSpecies::setParhamiMcKeeping(), DPMBase::setParticleDimensions(), PossibleContact::setPreviousPosition(), SphericalWall::setRadius(), Chute::setRoughBottomType(), SinterNormalSpecies::setSinterAdhesion(), SinterNormalSpecies::setSinterForceAndTime(), SinterNormalSpecies::setSinterRate(), SinterNormalSpecies::setSinterType(), BaseInteractable::setSpecies(), DPMBase::setSystemDimensions(), ThermalSpecies< NormalForceSpecies >::setThermalConductivity(), ChuteBottom::setThickness(), DPMBase::setTimeMax(), DPMBase::setTimeStep(), ChuteBottom::setupInitialConditions(), Chute::setupInitialConditions(), DPMBase::setXMax(), DPMBase::setXMin(), DPMBase::setYMax(), DPMBase::setYMin(), DPMBase::setZMax(), DPMBase::setZMin(), DPMBase::solve(), SpeciesHandler::SpeciesHandler(), SphericalWall::SphericalWall(), transformMercuryToVTK(), TriangulatedWall::TriangulatedWall(), MercuryBase::userHGridCellSize(), WallHandler::WallHandler(), WallHandler::writeVTK(), InteractionHandler::writeVTK(), BaseWall::writeVTK(), ParticleHandler::writeVTK(), DPMBase::writeVTK(), WallHandler::writeVTKBoundingBox(), WallHandler::writeVTKFile(), AxisymmetricIntersectionOfWalls::~AxisymmetricIntersectionOfWalls(), BaseHandler< T >::~BaseHandler(), BaseInteractable::~BaseInteractable(), BaseObject::~BaseObject(), BaseParticle::~BaseParticle(), BaseWall::~BaseWall(), BoundaryHandler::~BoundaryHandler(), Coil::~Coil(), DeletionBoundary::~DeletionBoundary(), FileReader::~FileReader(), FilesAndRunNumber::~FilesAndRunNumber(), HGrid::~HGrid(), InfiniteWall::~InfiniteWall(), InteractionHandler::~InteractionHandler(), IntersectionOfWalls::~IntersectionOfWalls(), MercuryBase::~MercuryBase(), ParticleHandler::~ParticleHandler(), PeriodicBoundary::~PeriodicBoundary(), RestrictedWall::~RestrictedWall(), Screw::~Screw(), SpeciesHandler::~SpeciesHandler(), SphericalWall::~SphericalWall(), TriangulatedWall::~TriangulatedWall(), 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 143 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:76
static void printInfo(std::string module, std::string msg)
Definition: Logger.cc:63
static void printMessage(std::string module, std::string msg)
Definition: Logger.cc:69

Definition at line 134 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 55 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 52 of file Logger.cc.

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