PLearn 0.1
Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Attributes
PLearn::PL_Log Class Reference

#include <pl_log.h>

Collaboration diagram for PLearn::PL_Log:
Collaboration graph
[legend]

List of all members.

Classes

struct  Heading
 Support stuff for heading manipulator. More...

Public Member Functions

 PL_Log (PP< PL_LogPlugin > plugin)
 Constructor (Use default destructor, copy constructor, etc.)
void verbosity (int v)
 Set the actual runtime verbosity.
int verbosity () const
 Return the current runtime verbosity.
void outmode (PStream::mode_t outmode)
 Changes the output_stream outmode.
PStreamlogger (int requested_verbosity)
 Underlying logging function.
PStreamnamedLogger (const string &module_name, int requested_verbosity)
 Underlying named logging function.
void enableNamedLogging (const vector< string > &module_names)
 Named logging support.
void enableNamedLogging (const string &comma_separated_module_names)
 Shortcut for enableNamedLogging: first split the module names by comma and call enableNamedLogging -- convenient for in-code logging enabling.
vector< string > namedLogging () const
 Return the list of modules for which named logging is enabled.
bool loggingEnabled (const string &module_name) const
 Return true if logging is enabled for the given module.
long loggerCount () const
 Return number of times logger() has been called.
PP< PL_LogPlugingetCurrentPlugin ()
 Return the current plugin.
void setPlugin (PP< PL_LogPlugin > plugin)
 Set a new plugin.

Static Public Member Functions

static PL_Loginstance ()
 Return system-wide PL_Log.
static VerbosityLevel vlevelFromString (const string &v)
 Parses a string to see whether or not it names a VerbosityLevel.

Protected Types

enum  { AllModules = 0, NoModules = 1, SomeModules = 2 }

Protected Attributes

int runtime_verbosity
PP< PL_LogPluginm_plugin
 Used to obtain the actual logging stream.
PStream null_stream
 Used when there is nothing to output.
PStream::mode_t m_outmode
 Formatting instructions for logging.
long logger_count
 Number of times logger() has been called.
set< string > enabled_modules
 Modules for which logging is enabled.
enum PLearn::PL_Log:: { ... }  named_logging_kind

Detailed Description

Definition at line 193 of file pl_log.h.


Member Enumeration Documentation

anonymous enum [protected]
Enumerator:
AllModules 

Named logging enabled for all modules.

NoModules 

Named logging enabled for no modules.

SomeModules 

Named logging enabled for some modules.

Definition at line 282 of file pl_log.h.


Constructor & Destructor Documentation

PLearn::PL_Log::PL_Log ( PP< PL_LogPlugin plugin)

Constructor (Use default destructor, copy constructor, etc.)

Definition at line 189 of file pl_log.cc.


Member Function Documentation

void PLearn::PL_Log::enableNamedLogging ( const vector< string > &  module_names)

Named logging support.

Enable named logging for the specified modules.

Enable logging for the specified list of modules. If the special "__ALL__" keyword is used, then all named logging is enabled. If the special "__NONE__" keyword is used, then no named logging is enabled. (Default = "__NONE__")

Watch if one of the elements is one of the special keywords __ALL__ or __NONE__, and handle them accordingly.

Definition at line 237 of file pl_log.cc.

References AllModules, enabled_modules, i, n, named_logging_kind, NoModules, and SomeModules.

Referenced by enableNamedLogging(), PLearn::global_options(), PLearn::Plide::loggingControl(), PLearn::ConjRosenbrock::perform(), PLearn::RunCommand::run(), and PLearn::PyPLearnScript::run().

{
    enabled_modules.clear();
    named_logging_kind = SomeModules;
    for (int i=0, n=int(module_names.size()) ; i<n ; ++i) {
        if (module_names[i] == "__ALL__") {
            named_logging_kind = AllModules;
            break;
        }
        else if (module_names[i] == "__NONE__") {
            named_logging_kind = NoModules;
            break;
        }
        else
            enabled_modules.insert(module_names[i]);
    }
}

Here is the caller graph for this function:

void PLearn::PL_Log::enableNamedLogging ( const string &  comma_separated_module_names)

Shortcut for enableNamedLogging: first split the module names by comma and call enableNamedLogging -- convenient for in-code logging enabling.

Definition at line 260 of file pl_log.cc.

References enableNamedLogging(), and PLearn::split().

{
    vector<string> module_names = split(comma_separated_module_names,
                                        ", \t\n\r");
    enableNamedLogging(module_names);
}

Here is the call graph for this function:

PP<PL_LogPlugin> PLearn::PL_Log::getCurrentPlugin ( ) [inline]

Return the current plugin.

Definition at line 248 of file pl_log.h.

References m_plugin.

Referenced by PLearn::Plide::run().

    {
        return m_plugin;
    }

Here is the caller graph for this function:

PL_Log & PLearn::PL_Log::instance ( ) [static]

Return system-wide PL_Log.

Definition at line 296 of file pl_log.cc.

References PLearn::get_perr().

Referenced by PLearn::PLearnService::connectToServers(), PLearn::global_options(), PLearn::Plide::loggingControl(), PLearn::PLLogTest::perform(), PLearn::ConjRosenbrock::perform(), PLearn::AutoVMatrixTest::perform(), PLearn::PyPLearnScript::process(), PLearn::RunCommand::run(), PLearn::PyPLearnScript::run(), and PLearn::Plide::run().

{
    static PP<PL_LogPlugin> global_plugin = new PL_LogPluginPStream(get_perr());
    static PL_Log global_logger(global_plugin);
    return global_logger;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PStream & PLearn::PL_Log::logger ( int  requested_verbosity)

Underlying logging function.

Return a logger object given verbosity only.

If "requested_verbosity" is less than or equal to verbosity, then output_stream is returned; otherwise null_stream is returned.

Definition at line 202 of file pl_log.cc.

References logger_count, m_outmode, m_plugin, null_stream, PLASSERT, and runtime_verbosity.

{
    static const string module_name;         // Empty string
    PLASSERT( m_plugin );
    logger_count++;
    if (requested_verbosity <= runtime_verbosity)
        return m_plugin->getStream(m_outmode, module_name, requested_verbosity);
    else
        return null_stream;
}
long PLearn::PL_Log::loggerCount ( ) const [inline]

Return number of times logger() has been called.

Definition at line 245 of file pl_log.h.

References logger_count.

{ return logger_count; }
bool PLearn::PL_Log::loggingEnabled ( const string &  module_name) const

Return true if logging is enabled for the given module.

Return true if logging is enabled for the specified module.

Definition at line 288 of file pl_log.cc.

References AllModules, enabled_modules, named_logging_kind, and SomeModules.

{
    return (named_logging_kind == AllModules ||
            (named_logging_kind == SomeModules &&
             enabled_modules.find(module_name) != enabled_modules.end()));
}
PStream & PLearn::PL_Log::namedLogger ( const string &  module_name,
int  requested_verbosity 
)

Underlying named logging function.

Return a logger if logging is enabled for the specified module name.

Use this in conjunction with the MODULE_LOG define. If logging is enabled for the specified module, then return output_stream; otherwise return null_stream.

Definition at line 217 of file pl_log.cc.

References AllModules, enabled_modules, logger_count, m_outmode, m_plugin, named_logging_kind, null_stream, runtime_verbosity, and SomeModules.

{
    logger_count++;
    if (requested_verbosity <= runtime_verbosity &&
        (named_logging_kind == AllModules ||
         (named_logging_kind == SomeModules &&
          enabled_modules.find(module_name) != enabled_modules.end())))
    {
        return m_plugin->getStream(m_outmode, module_name, requested_verbosity);
    }

    return null_stream;
}
vector< string > PLearn::PL_Log::namedLogging ( ) const

Return the list of modules for which named logging is enabled.

Definition at line 271 of file pl_log.cc.

References AllModules, std::copy(), enabled_modules, named_logging_kind, and NoModules.

{
    vector<string> r;
    if (named_logging_kind == AllModules)
        r.push_back("__ALL__");
    else if (named_logging_kind == NoModules)
        r.push_back("__NONE__");
    else
        copy(enabled_modules.begin(), enabled_modules.end(), back_inserter(r));

    return r;
}

Here is the call graph for this function:

void PLearn::PL_Log::outmode ( PStream::mode_t  outmode) [inline]

Changes the output_stream outmode.

Definition at line 209 of file pl_log.h.

References m_outmode, and outmode().

Referenced by outmode(), PLearn::AutoVMatrixTest::perform(), and PLearn::Plide::run().

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::PL_Log::setPlugin ( PP< PL_LogPlugin plugin) [inline]

Set a new plugin.

Definition at line 254 of file pl_log.h.

References m_plugin.

Referenced by PLearn::Plide::run().

    {
        m_plugin = plugin;
    }

Here is the caller graph for this function:

int PLearn::PL_Log::verbosity ( ) const [inline]

Return the current runtime verbosity.

Definition at line 206 of file pl_log.h.

References runtime_verbosity.

{ return runtime_verbosity; }
void PLearn::PL_Log::verbosity ( int  v) [inline]

Set the actual runtime verbosity.

This is a verbosity threshold; any "requested_verbosity" less than or equal to this verbosity is displayed by PL_LOG.

Definition at line 203 of file pl_log.h.

References runtime_verbosity.

Referenced by PLearn::global_options(), PLearn::Plide::loggingControl(), PLearn::PLLogTest::perform(), PLearn::ConjRosenbrock::perform(), PLearn::AutoVMatrixTest::perform(), PLearn::RunCommand::run(), and PLearn::PyPLearnScript::run().

Here is the caller graph for this function:

VerbosityLevel PLearn::PL_Log::vlevelFromString ( const string &  v) [static]

Parses a string to see whether or not it names a VerbosityLevel.

If it doesn't, tries the cast to an int.

Definition at line 308 of file pl_log.cc.

References return, PLearn::toint(), PLearn::VLEVEL_DBG, PLearn::VLEVEL_EXTREME, PLearn::VLEVEL_IMP, PLearn::VLEVEL_MAND, and PLearn::VLEVEL_NORMAL.

Referenced by PLearn::global_options().

{
    static map<string, VerbosityLevel> _vlevels;
    if ( _vlevels.size() == 0 )
    {
        _vlevels["VLEVEL_MAND"]    = VLEVEL_MAND;
        _vlevels["VLEVEL_IMP"]     = VLEVEL_IMP;
        _vlevels["VLEVEL_NORMAL"]  = VLEVEL_NORMAL ;
        _vlevels["VLEVEL_DBG"]     = VLEVEL_DBG    ;
        _vlevels["VLEVEL_EXTREME"] = VLEVEL_EXTREME;
    }
  
    map<string, VerbosityLevel>::iterator it = _vlevels.find(v);
    if ( it != _vlevels.end() )
        return it->second;
    return (VerbosityLevel)toint(v);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

set<string> PLearn::PL_Log::enabled_modules [protected]

Modules for which logging is enabled.

Definition at line 280 of file pl_log.h.

Referenced by enableNamedLogging(), loggingEnabled(), namedLogger(), and namedLogging().

long PLearn::PL_Log::logger_count [protected]

Number of times logger() has been called.

Definition at line 279 of file pl_log.h.

Referenced by logger(), loggerCount(), and namedLogger().

Formatting instructions for logging.

Definition at line 278 of file pl_log.h.

Referenced by logger(), namedLogger(), and outmode().

Used to obtain the actual logging stream.

Definition at line 276 of file pl_log.h.

Referenced by getCurrentPlugin(), logger(), namedLogger(), and setPlugin().

enum { ... } PLearn::PL_Log::named_logging_kind [protected]

Used when there is nothing to output.

Definition at line 277 of file pl_log.h.

Referenced by logger(), and namedLogger().

Definition at line 275 of file pl_log.h.

Referenced by logger(), namedLogger(), and verbosity().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines