Rosetta
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 bool & super_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_
 @which 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

◆ OstreamPointer

typedef std::ostream* basic::TracerImpl::OstreamPointer

Constructor & Destructor Documentation

◆ TracerImpl() [1/3]

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 channel(), utility::CSI_Nothing(), init(), and priority().

◆ TracerImpl() [2/3]

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 channel(), channel_color(), channel_name_color(), init(), and priority().

◆ ~TracerImpl()

basic::TracerImpl::~TracerImpl ( )
override

◆ TracerImpl() [3/3]

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

copy constructor.

Functions

Member Function Documentation

◆ calculate_tracer_level()

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 kmeans_adaptive_kernel_density_bb_dependent_rotlib::flag, create_a3b_hbs::i, ObjexxFCL::len(), ObjexxFCL::lowercased(), res, docking::s, safe_output(), subloop_histogram::size, utility::string2int(), utility::string_split(), basic::t_debug, basic::t_error, basic::t_fatal, basic::t_info, basic::t_trace, basic::t_warning, and kmeans_adaptive_kernel_density_bb_dependent_rotlib::v.

Referenced by calculate_visibility().

◆ calculate_visibility() [1/2]

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().

◆ calculate_visibility() [2/2]

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(), channel(), in(), utility::mpi_nprocs(), utility::mpi_rank(), mpi_rank_, priority(), tracer_options_, and visible().

◆ channel()

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

◆ channel_color() [1/2]

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

Get the channel color.

References channel_color_.

Referenced by init(), and TracerImpl().

◆ channel_color() [2/2]

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_.

◆ channel_name_color() [1/2]

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

References channel_name_color_.

Referenced by init(), and TracerImpl().

◆ channel_name_color() [2/2]

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

References channel_name_color_.

◆ final_stream()

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

◆ flush_all_channels()

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, create_a3b_hbs::i, Info, Trace, kmeans_adaptive_kernel_density_bb_dependent_rotlib::v, and Warning.

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

◆ get_all_channels_string()

std::string const & basic::TracerImpl::get_all_channels_string ( )
static

◆ get_local_print_channel_name()

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().

◆ get_proxy_by_priority()

TracerImpl::TracerProxyImpl & basic::TracerImpl::get_proxy_by_priority ( TracerPriority  priority)

◆ in()

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 create_a3b_hbs::i, docking::s, subloop_histogram::size, and kmeans_adaptive_kernel_density_bb_dependent_rotlib::v.

Referenced by calculate_visibility(), and t_flush().

◆ init() [1/2]

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().

◆ init() [2/2]

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(), basic::Tracer::channel_, channel_, mute_level_, muted_, basic::Tracer::priority_, priority_, tr, and visible_.

◆ ios_hook()

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

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

static data members

References execute::hook.

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

◆ monitoring_list_()

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().

◆ operator()()

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

References priority().

◆ output_prefix() [1/2]

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

References output_prefix_.

◆ output_prefix() [2/2]

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_.

◆ prepend_channel_name()

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, str(), basic::t_error, basic::t_fatal, basic::t_warning, utility::timestamp(), basic::thread_manager::RosettaThreadManager::total_threads(), and tracer_options_.

◆ priority() [1/2]

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

get/set tracer priority level.

References priority_.

Referenced by calculate_visibility(), get_proxy_by_priority(), init(), operator()(), priority(), TracerImpl(), and visible().

◆ priority() [2/2]

void basic::TracerImpl::priority ( int  priority)

◆ safe_output()

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(), ios_hook(), and pyrosetta.utility.array::message.

Referenced by calculate_tracer_level().

◆ set_default_final_stream()

void basic::TracerImpl::set_default_final_stream ( )
static

◆ set_ios_hook()

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 pyrosetta.logging_support.PythonLoggingSink::__del__(), test.T007_TracerIO.MyPyTracer::__del__(), and basic::Tracer::set_ios_hook().

◆ set_local_print_channel_name()

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().

◆ set_new_final_stream()

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.

◆ set_tracer_options()

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_.

◆ super_mute() [1/2]

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().

◆ super_mute() [2/2]

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

References create_a3b_hbs::f, and super_mute_().

◆ super_mute_()

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().

◆ 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_(), str(), super_mute_(), and visible().

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

◆ visible() [1/2]

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().

◆ visible() [2/2]

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

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

References mute_level_, muted_, and priority().

Member Data Documentation

◆ bgBlack

utility::CSI_Sequence basic::TracerImpl::bgBlack
static

◆ bgBlue

utility::CSI_Sequence basic::TracerImpl::bgBlue
static

◆ bgCyan

utility::CSI_Sequence basic::TracerImpl::bgCyan
static

◆ bgGreen

utility::CSI_Sequence basic::TracerImpl::bgGreen
static

◆ bgMagenta

utility::CSI_Sequence basic::TracerImpl::bgMagenta
static

◆ bgRed

utility::CSI_Sequence basic::TracerImpl::bgRed
static

◆ bgWhite

utility::CSI_Sequence basic::TracerImpl::bgWhite
static

◆ bgYellow

utility::CSI_Sequence basic::TracerImpl::bgYellow
static

◆ Black

utility::CSI_Sequence basic::TracerImpl::Black
static

◆ Blue

utility::CSI_Sequence basic::TracerImpl::Blue
static

◆ Bold

utility::CSI_Sequence basic::TracerImpl::Bold
static

Referenced by prepend_channel_name().

◆ channel_

std::string basic::TracerImpl::channel_
private

◆ channel_color_

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().

◆ channel_name_color_

utility::CSI_Sequence basic::TracerImpl::channel_name_color_
private

◆ Cyan

utility::CSI_Sequence basic::TracerImpl::Cyan
static

◆ Debug

TracerProxyImpl basic::TracerImpl::Debug

◆ Error

TracerProxyImpl basic::TracerImpl::Error

◆ Fatal

TracerProxyImpl basic::TracerImpl::Fatal

channels with predefined priority levels.

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

◆ Green

utility::CSI_Sequence basic::TracerImpl::Green
static

◆ Info

TracerProxyImpl basic::TracerImpl::Info

◆ local_print_channel_name_

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().

◆ Magenta

utility::CSI_Sequence basic::TracerImpl::Magenta
static

◆ mpi_rank_

int basic::TracerImpl::mpi_rank_
staticprivate

@which Mpi rank is this process

Referenced by calculate_visibility(), and prepend_channel_name().

◆ mute_level_

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().

◆ muted_

bool basic::TracerImpl::muted_ = false
private

is channel muted ?

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

◆ muted_by_default_

bool basic::TracerImpl::muted_by_default_ = false
private

is channel muted by default?

Referenced by calculate_visibility(), and init().

◆ output_prefix_

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

global prefix for all tracer output

Referenced by output_prefix(), and prepend_channel_name().

◆ priority_

int basic::TracerImpl::priority_ = t_info
private

◆ Red

utility::CSI_Sequence basic::TracerImpl::Red
static

Referenced by prepend_channel_name().

◆ Reset

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

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

Referenced by prepend_channel_name().

◆ Trace

TracerProxyImpl basic::TracerImpl::Trace

◆ tracer_options_

TracerOptionsOP basic::TracerImpl::tracer_options_
staticprivate

global option collection for Tracer IO.

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

◆ Underline

utility::CSI_Sequence basic::TracerImpl::Underline
static

◆ visible_

bool basic::TracerImpl::visible_ = true
private

◆ Warning

TracerProxyImpl basic::TracerImpl::Warning

◆ White

utility::CSI_Sequence basic::TracerImpl::White
static

◆ Yellow

utility::CSI_Sequence basic::TracerImpl::Yellow
static

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