Rosetta  2020.46
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
basic::TracerImpl Class Reference

Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for all your regular io. Channel argument must be related to the location of the source file. For example if you create Tracer object in src/basic/scoring/myfile.cc, then channel must be something like 'src.basic.scoring.myfile'. More...

#include <TracerImpl.hh>

Inheritance diagram for basic::TracerImpl:
Inheritance graph
[legend]

Classes

class  TracerProxyImpl
 Small inner class acting as a proxy to an object that hold it. More...
 

Public Types

typedef std::ostream * OstreamPointer
 

Public Member Functions

 TracerImpl (std::string const &channel="", TracerPriority priority=t_info, bool muted_by_default=false)
 Create Tracer object with given channel and priority. More...
 
 TracerImpl (std::string const &channel, utility::CSI_Sequence const &channel_color, utility::CSI_Sequence const &channel_name_color=utility::CSI_Nothing(), TracerPriority priority=t_info, bool muted_by_default=false)
 Create Tracer object with channel color, channel name color and given channel and priority. More...
 
 ~TracerImpl () override
 
void init (TracerImpl const &tr)
 re-init using data from another tracer object. More...
 
void flush_all_channels ()
 flush tracer buffer and flush buffers of all sub-channels ie: Fatal, Error, Warning, Info, Debug, Trace More...
 
bool visible ()
 Is this tracer currently visible?. More...
 
bool visible (int priority)
 is this tracer visible, if it used the given priority value? More...
 
int priority () const
 get/set tracer priority level. More...
 
TracerImploperator() (int priority)
 
void priority (int priority)
 
std::string const & channel () const
 
utility::CSI_Sequence const & channel_color ()
 Get the channel color. More...
 
void channel_color (utility::CSI_Sequence const &color)
 Set the channel color. More...
 
utility::CSI_Sequence const & channel_name_color ()
 
void channel_name_color (utility::CSI_Sequence const &color)
 
void set_local_print_channel_name (bool const setting)
 Set whether we're printing the channel name. More...
 
bool get_local_print_channel_name () const
 Get whether we're printing the channel name. More...
 
TracerProxyImplget_proxy_by_priority (TracerPriority priority)
 
- Public Member Functions inherited from basic::basic_otstream< CharT, Traits >
 basic_otstream ()
 
 ~basic_otstream () override
 
bool is_flushed () const
 Return true if inner string buffer is empty. More...
 

Static Public Member Functions

static void set_new_final_stream (std::ostream *new_final_stream)
 set ios hook for final tracer stream (deafult is std::cout). More...
 
static void set_default_final_stream ()
 
static void set_ios_hook (otstreamOP tr, std::string const &monitoring_channels_list, bool raw=false)
 set ios hook for all tracer io operation. More...
 
static std::string const & get_all_channels_string ()
 
static void set_tracer_options (TracerOptions const &to)
 set tracer options - global options for Tracer IO. More...
 
static bool super_mute ()
 global super mute flag that allow to mute all io no matter what. More...
 
static void super_mute (bool f)
 
static void output_prefix (std::string const &)
 set/get globale string-prefix for all Tracer output strings More...
 
static std::string output_prefix ()
 

Public Attributes

TracerProxyImpl Fatal
 channels with predefined priority levels. More...
 
TracerProxyImpl Error
 
TracerProxyImpl Warning
 
TracerProxyImpl Info
 
TracerProxyImpl Debug
 
TracerProxyImpl Trace
 

Static Public Attributes

static utility::CSI_Sequence Reset
 
static utility::CSI_Sequence Bold
 
static utility::CSI_Sequence Underline
 
static utility::CSI_Sequence Black
 
static utility::CSI_Sequence Red
 
static utility::CSI_Sequence Green
 
static utility::CSI_Sequence Yellow
 
static utility::CSI_Sequence Blue
 
static utility::CSI_Sequence Magenta
 
static utility::CSI_Sequence Cyan
 
static utility::CSI_Sequence White
 
static utility::CSI_Sequence bgBlack
 
static utility::CSI_Sequence bgRed
 
static utility::CSI_Sequence bgGreen
 
static utility::CSI_Sequence bgYellow
 
static utility::CSI_Sequence bgBlue
 
static utility::CSI_Sequence bgMagenta
 
static utility::CSI_Sequence bgCyan
 
static utility::CSI_Sequence bgWhite
 

Protected Member Functions

void t_flush (std::string const &) override
 overload member function. More...
 

Private Member Functions

void init (std::string const &channel, utility::CSI_Sequence const &channel_color, utility::CSI_Sequence const &channel_name_color, TracerPriority priority, bool muted_by_default)
 init Tracer object with given parameters. This is a helper function to be called from various constructors More...
 
 TracerImpl (TracerImpl const &tr)=delete
 copy constructor. More...
 
template<class out_stream >
void prepend_channel_name (out_stream &sout, std::string const &str)
 helper function for t_flush() – do not call from elsewhere (without caution) More...
 
void calculate_visibility ()
 calculate visibility of the current object depending of the channel name and priority. More...
 

Static Private Member Functions

static OstreamPointerfinal_stream ()
 
static bool in (utility::vector1< std::string > const &, std::string const &channel, bool strict)
 return true if channel is inside vector, some logic apply. More...
 
static bool calculate_tracer_level (utility::vector1< std::string > const &v, std::string const &ch, bool strict, int &res)
 calculate channel priority with hierarchy in mind. More...
 
static void calculate_visibility (std::string const &channel, int priority, bool &visible, bool &muted, int &mute_level_, bool muted_by_default)
 
static void safe_output (std::string const &)
 Output a message in a manner that is safe if the Tracers/output are poorly initialized. More...
 
static otstreamOPios_hook ()
 link to Tracer like object where all output for selecting channels should go. More...
 
static utility::vector1
< std::string > & 
monitoring_list_ ()
 list of channels for which outout should be redirected. More...
 
static boolsuper_mute_ ()
 global super mute flag that allow to mute all io no matter what. More...
 

Private Attributes

std::string channel_
 Data members. More...
 
bool local_print_channel_name_
 Allows local override of whether channel name is printed. This is true by default, in which case the global setting is used. Setting this to false prevents channel name from being printed for this tracer only. More...
 
utility::CSI_Sequence channel_color_
 default colors for tracer output and tracer channel-name string (ie color of string such as: 'core.pose:') More...
 
utility::CSI_Sequence channel_name_color_
 
int priority_ = t_info
 channel output priority level More...
 
int mute_level_ = t_info
 channel muted priority level (above which level is channel muted), calculated using user suppied -level and -levels options More...
 
bool visible_ = true
 is channel visible? More...
 
bool muted_ = false
 is channel muted ? More...
 
bool muted_by_default_ = false
 is channel muted by default? More...
 

Static Private Attributes

static TracerOptionsOP tracer_options_
 global option collection for Tracer IO. More...
 
static int mpi_rank_
 Mpi rank is this process More...
 
static std::string output_prefix_
 global prefix for all tracer output More...
 

Detailed Description

Class for handling user debug/warnings/errors. Use instance of this class instead of 'std::cout' for all your regular io. Channel argument must be related to the location of the source file. For example if you create Tracer object in src/basic/scoring/myfile.cc, then channel must be something like 'src.basic.scoring.myfile'.

Member Typedef Documentation

Constructor & Destructor Documentation

basic::TracerImpl::TracerImpl ( std::string const &  channel = "",
TracerPriority  priority = t_info,
bool  muted_by_default = false 
)

Create Tracer object with given channel and priority.

Constructor of Tracer object. Since most of the Tracer object will be created as static - they Constuctor will be called before Option system is initialized. So we can't really calculate any vizibility or priority here. Such calculation should be done later, whe first IO operation happend.

Todo:
Default Tracer level should probably be modified to t_info here and in options defn.

References utility::CSI_Nothing(), and init().

basic::TracerImpl::TracerImpl ( std::string const &  channel,
utility::CSI_Sequence const &  channel_color,
utility::CSI_Sequence const &  channel_name_color = utility::CSI_Nothing(),
TracerPriority  priority = t_info,
bool  muted_by_default = false 
)

Create Tracer object with channel color, channel name color and given channel and priority.

Ex: static basic::Tracer Blue("blue", CSI_Blue());

References init().

basic::TracerImpl::~TracerImpl ( )
override
basic::TracerImpl::TracerImpl ( TracerImpl const &  tr)
privatedelete

copy constructor.

Functions

Member Function Documentation

bool basic::TracerImpl::calculate_tracer_level ( utility::vector1< std::string > const &  v,
std::string const &  ch,
bool  strict,
int res 
)
staticprivate

calculate channel priority with hierarchy in mind.

Same as before but return integer value for matched channel or closest match (we asume that 'v' in levels format, ie like: <channel name>="">:level )

References ObjexxFCL::len(), ObjexxFCL::lowercased(), basic::options::OptionKeys::in::file::s, safe_output(), amino_acids::size, utility::string2int(), utility::string_split(), basic::t_debug, basic::t_error, basic::t_fatal, basic::t_info, basic::t_trace, and basic::t_warning.

Referenced by calculate_visibility().

void basic::TracerImpl::calculate_visibility ( )
private

calculate visibility of the current object depending of the channel name and priority.

Calculate visibility of current Tracer object and all of its proxies

References basic::TracerImpl::TracerProxyImpl::calculate_visibility(), channel_, utility::io::oc::cout, Debug, Error, Fatal, Info, mute_level_, muted_, muted_by_default_, priority_, Trace, tracer_options_, visible_, and Warning.

Referenced by basic::TracerImpl::TracerProxyImpl::calculate_visibility(), and init().

void basic::TracerImpl::calculate_visibility ( std::string const &  channel,
int  priority,
bool visible,
bool muted,
int mute_level,
bool  muted_by_default 
)
staticprivate

Calculate visibility (static version) of current Tracer object using channel name and priority. result stored in 'muted' and 'visible'.

References calculate_tracer_level(), in(), utility::mpi_nprocs(), utility::mpi_rank(), mpi_rank_, tracer_options_, and visible().

std::string const& basic::TracerImpl::channel ( ) const
inline

References channel_.

Referenced by basic::Tracer::channel(), and init().

utility::CSI_Sequence const& basic::TracerImpl::channel_color ( )
inline

Get the channel color.

References channel_color_.

Referenced by init().

void basic::TracerImpl::channel_color ( utility::CSI_Sequence const &  color)
inline

Set the channel color.

This can be done in a stream like this: TR << TR.bgWhite << TR.Black << "Example" << TR.Reset << std::endl;

References channel_color_.

utility::CSI_Sequence const& basic::TracerImpl::channel_name_color ( )
inline

References channel_name_color_.

Referenced by init().

void basic::TracerImpl::channel_name_color ( utility::CSI_Sequence const &  color)
inline

References channel_name_color_.

TracerImpl::OstreamPointer & basic::TracerImpl::final_stream ( )
staticprivate
void basic::TracerImpl::flush_all_channels ( )

flush tracer buffer and flush buffers of all sub-channels ie: Fatal, Error, Warning, Info, Debug, Trace

References Debug, Error, Fatal, Info, Trace, test.T850_SubClassing::v, and Warning.

Referenced by basic::Tracer::flush_all_channels().

std::string const & basic::TracerImpl::get_all_channels_string ( )
static
bool basic::TracerImpl::get_local_print_channel_name ( ) const
inline

Get whether we're printing the channel name.

This gets the local setting, but does not look at the global setting. (In practice, if the local setting is true then the global setting is used.)

Author
Vikram K. Mulligan (vmull.nosp@m.igan.nosp@m.@flat.nosp@m.iron.nosp@m.insti.nosp@m.tute.nosp@m..org)

References local_print_channel_name_.

Referenced by basic::Tracer::get_local_print_channel_name().

TracerImpl::TracerProxyImpl & basic::TracerImpl::get_proxy_by_priority ( TracerPriority  priority)
bool basic::TracerImpl::in ( utility::vector1< std::string > const &  v,
std::string const &  ch,
bool  strict 
)
staticprivate

return true if channel is inside vector, some logic apply.

Check if string representing channel 'ch' is in vector<string> v. Return true if channel is in vector, false otherwise. Two mode of operation: Strict: strict==true - channels compared verbatim. Regular: strict==false - comparing with hierarchy in mind, ie: ch='basic.pose' v[0]='basic' –> will yield true.

References basic::options::OptionKeys::in::file::s, and amino_acids::size.

Referenced by calculate_visibility(), and t_flush().

void basic::TracerImpl::init ( std::string const &  channel,
utility::CSI_Sequence const &  channel_color,
utility::CSI_Sequence const &  channel_name_color,
TracerPriority  priority,
bool  muted_by_default 
)
private

init Tracer object with given parameters. This is a helper function to be called from various constructors

References calculate_visibility(), channel(), channel_, channel_color(), channel_color_, channel_name_color(), channel_name_color_, local_print_channel_name_, mute_level_, muted_, muted_by_default_, priority(), priority_, and visible_.

Referenced by TracerImpl().

void basic::TracerImpl::init ( TracerImpl const &  tr)

re-init using data from another tracer object.

re-init using data from another tracer object.

References calculate_visibility(), channel_, mute_level_, muted_, priority_, and visible_.

otstreamOP & basic::TracerImpl::ios_hook ( )
staticprivate

link to Tracer like object where all output for selecting channels should go.

static data members

Referenced by safe_output(), set_ios_hook(), and t_flush().

utility::vector1< std::string > & basic::TracerImpl::monitoring_list_ ( )
staticprivate

list of channels for which outout should be redirected.

Referenced by set_ios_hook(), and t_flush().

TracerImpl & basic::TracerImpl::operator() ( int  priority)

References priority().

void basic::TracerImpl::output_prefix ( std::string const &  new_output_prefix)
static

set/get globale string-prefix for all Tracer output strings

References output_prefix_.

std::string basic::TracerImpl::output_prefix ( )
static

References output_prefix_.

template<class out_stream >
void basic::TracerImpl::prepend_channel_name ( out_stream &  sout,
std::string const &  str 
)
private

helper function for t_flush() – do not call from elsewhere (without caution)

Write the contents of str to sout prepending the channel name on each line if the print_channel_name flag is set.

References Bold, channel_, channel_color_, channel_name_color_, utility::SingletonBase< RosettaThreadManager >::get_instance(), local_print_channel_name_, mpi_rank_, output_prefix_, priority_, Red, Reset, basic::t_error, basic::t_fatal, basic::t_warning, utility::timestamp(), and tracer_options_.

int basic::TracerImpl::priority ( ) const
inline

get/set tracer priority level.

References priority_.

Referenced by init(), operator()(), and priority().

void basic::TracerImpl::priority ( int  priority)
void basic::TracerImpl::safe_output ( std::string const &  message)
staticprivate

Output a message in a manner that is safe if the Tracers/output are poorly initialized.

References utility::io::oc::cerr, final_stream(), and ios_hook().

Referenced by calculate_tracer_level().

void basic::TracerImpl::set_default_final_stream ( )
static
void basic::TracerImpl::set_ios_hook ( otstreamOP  tr,
std::string const &  monitoring_channels_list,
bool  raw = false 
)
static

set ios hook for all tracer io operation.

Parameters
monitoring_channels_listis space separated list of channels.i
rawis ignored

Set OStringStream object to which all Tracers output listed in the monitoring_channels_list should be copied.

The boolean parameter is left for backward compatibility. (It used to control the ability to ignore visibility settings.)

References ios_hook(), monitoring_list_(), utility::split(), tr, and utility_exit_with_message.

Referenced by basic::Tracer::set_ios_hook().

void basic::TracerImpl::set_local_print_channel_name ( bool const  setting)

Set whether we're printing the channel name.

This overrides the local setting, but does not alter the global setting.

Author
Vikram K. Mulligan (vmull.nosp@m.igan.nosp@m.@flat.nosp@m.iron.nosp@m.insti.nosp@m.tute.nosp@m..org)

References local_print_channel_name_.

Referenced by basic::Tracer::set_local_print_channel_name().

void basic::TracerImpl::set_new_final_stream ( std::ostream *  new_final_stream)
static

set ios hook for final tracer stream (deafult is std::cout).

References final_stream(), and utility_exit_with_message.

void basic::TracerImpl::set_tracer_options ( TracerOptions const &  to)
static

set tracer options - global options for Tracer IO.

References utility::io::oc::cout, and tracer_options_.

static bool basic::TracerImpl::super_mute ( )
inlinestatic

global super mute flag that allow to mute all io no matter what.

References super_mute_().

Referenced by basic::Tracer::super_mute().

static void basic::TracerImpl::super_mute ( bool  f)
inlinestatic
bool & basic::TracerImpl::super_mute_ ( )
staticprivate

global super mute flag that allow to mute all io no matter what.

References basic::options::OptionKeys::out::mute.

Referenced by super_mute(), and t_flush().

void basic::TracerImpl::t_flush ( std::string const &  str)
overrideprotectedvirtual

overload member function.

Inform Tracer that is contents was modified, and IO is in order.

Reimplemented from basic::basic_otstream< CharT, Traits >.

References channel_, final_stream(), get_all_channels_string(), in(), ios_hook(), monitoring_list_(), super_mute_(), and visible().

Referenced by basic::MemTracerImpl::t_flush().

bool basic::TracerImpl::visible ( )
inline

Is this tracer currently visible?.

References visible_.

Referenced by calculate_visibility(), basic::MemTracerImpl::t_flush(), t_flush(), and basic::Tracer::visible().

bool basic::TracerImpl::visible ( int  priority)

is this tracer visible, if it used the given priority value?

References mute_level_, and muted_.

Member Data Documentation

utility::CSI_Sequence basic::TracerImpl::bgBlack
static
utility::CSI_Sequence basic::TracerImpl::bgBlue
static
utility::CSI_Sequence basic::TracerImpl::bgCyan
static
utility::CSI_Sequence basic::TracerImpl::bgGreen
static
utility::CSI_Sequence basic::TracerImpl::bgMagenta
static
utility::CSI_Sequence basic::TracerImpl::bgRed
static
utility::CSI_Sequence basic::TracerImpl::bgWhite
static
utility::CSI_Sequence basic::TracerImpl::bgYellow
static
utility::CSI_Sequence basic::TracerImpl::Black
static
utility::CSI_Sequence basic::TracerImpl::Blue
static
utility::CSI_Sequence basic::TracerImpl::Bold
static

Referenced by prepend_channel_name().

std::string basic::TracerImpl::channel_
private
utility::CSI_Sequence basic::TracerImpl::channel_color_
private

default colors for tracer output and tracer channel-name string (ie color of string such as: 'core.pose:')

Referenced by channel_color(), init(), and prepend_channel_name().

utility::CSI_Sequence basic::TracerImpl::channel_name_color_
private
utility::CSI_Sequence basic::TracerImpl::Cyan
static
TracerProxyImpl basic::TracerImpl::Debug
TracerProxyImpl basic::TracerImpl::Error
TracerProxyImpl basic::TracerImpl::Fatal

channels with predefined priority levels.

Referenced by calculate_visibility(), flush_all_channels(), get_proxy_by_priority(), and ~TracerImpl().

utility::CSI_Sequence basic::TracerImpl::Green
static
TracerProxyImpl basic::TracerImpl::Info
bool basic::TracerImpl::local_print_channel_name_
private

Allows local override of whether channel name is printed. This is true by default, in which case the global setting is used. Setting this to false prevents channel name from being printed for this tracer only.

Author
Vikram K. Mulligan (vmull.nosp@m.igan.nosp@m.@flat.nosp@m.iron.nosp@m.insti.nosp@m.tute.nosp@m..org).

Referenced by get_local_print_channel_name(), init(), prepend_channel_name(), and set_local_print_channel_name().

utility::CSI_Sequence basic::TracerImpl::Magenta
static
int basic::TracerImpl::mpi_rank_
staticprivate

Mpi rank is this process

Referenced by calculate_visibility(), and prepend_channel_name().

int basic::TracerImpl::mute_level_ = t_info
private

channel muted priority level (above which level is channel muted), calculated using user suppied -level and -levels options

Referenced by calculate_visibility(), init(), priority(), and visible().

bool basic::TracerImpl::muted_ = false
private

is channel muted ?

Referenced by calculate_visibility(), init(), priority(), and visible().

bool basic::TracerImpl::muted_by_default_ = false
private

is channel muted by default?

Referenced by calculate_visibility(), and init().

std::string basic::TracerImpl::output_prefix_
staticprivate

global prefix for all tracer output

Referenced by output_prefix(), and prepend_channel_name().

int basic::TracerImpl::priority_ = t_info
private
utility::CSI_Sequence basic::TracerImpl::Red
static

Referenced by prepend_channel_name().

utility::CSI_Sequence basic::TracerImpl::Reset
static

Static objects holding various ASCII CSI codes (see utility/CSI_Sequence.hh)

Referenced by prepend_channel_name().

TracerProxyImpl basic::TracerImpl::Trace
TracerOptionsOP basic::TracerImpl::tracer_options_
staticprivate

global option collection for Tracer IO.

Referenced by calculate_visibility(), prepend_channel_name(), and set_tracer_options().

utility::CSI_Sequence basic::TracerImpl::Underline
static
bool basic::TracerImpl::visible_ = true
private
TracerProxyImpl basic::TracerImpl::Warning
utility::CSI_Sequence basic::TracerImpl::White
static
utility::CSI_Sequence basic::TracerImpl::Yellow
static

The documentation for this class was generated from the following files: