Loading...
Searching...
No Matches
by::enablesZone Class Reference

Temporary scope-based enable/disable zone for logging streams. More...

#include <enablesZone.hpp>

Public Member Functions

 enablesZone (nbool newVal)
 Constructs an enablesZone and immediately sets all logging streams to the specified enable state, without capturing their previous states.
 
const enables & getPrev () const
 
mesetPrev ()
 Captures the current enable states of all streams as the new "previous" state. This state will be restored when the enablesZone object is destroyed.
 
merel ()
 Manually releases the enablesZone, preventing restoration of stream states on destruction.
 
mesetEnable (nbool newVal)
 Sets the enable state for all streams managed by the logger.
 
mesetEnable (const std::string &streamName, nbool newVal)
 Sets the enable state for a specific named stream.
 

Detailed Description

Temporary scope-based enable/disable zone for logging streams.

The logger class has multiple stream objects, and you can control output destinations by enabling or disabling specific streams. However, it's very common to need to control streams only within a specific code block or function, then restore the original state when leaving that block.

enablesZone is designed for this use case. Implemented using the RAII idiom, it records the enable state of streams upon object creation, then restores each stream's enable status to its initial state when the enablesZone is destroyed.

Usage

Typical usage pattern:

// Assume all streams in logger are enabled
{
logger& log = logger::get();
log.getStream(0).setEnable(false); // Disable stream 0
logger::getStream("consoleStream").setEnable(false); // Disable console logging
BY_E("error message1"); // This log won't go to stream 0 or console
logger::setEnable(false); // Disable all streams
BY_E("this message won't log on any stream");
}
BY_E("this message will definitely be log on entire stream"); // Back to normal
Temporary scope-based enable/disable zone for logging streams.
Definition enablesZone.hpp:39
Main logging interface for the byeol language system.
Definition logger.hpp:79
static logger & get()
Get singleton logger instance.
#define BY_E(fmt,...)
Log macro: prints debug log on console and file.
Definition macro.hpp:22
Rich logging support with polymorphic type conversion.
Definition richLog.hpp:34

Constructor & Destructor Documentation

◆ enablesZone()

by::enablesZone::enablesZone ( nbool newVal)

Constructs an enablesZone and immediately sets all logging streams to the specified enable state, without capturing their previous states.

Parameters
newValThe new enable state for all streams (true for enabled, false for disabled).

Member Function Documentation

◆ rel()

me & by::enablesZone::rel ( )

Manually releases the enablesZone, preventing restoration of stream states on destruction.

Returns
A reference to this enablesZone instance.

◆ setEnable() [1/2]

me & by::enablesZone::setEnable ( const std::string & streamName,
nbool newVal )

Sets the enable state for a specific named stream.

Parameters
streamNameThe name of the stream to modify.
newValThe new enable state (true for enabled, false for disabled).
Returns
A reference to this enablesZone instance.

◆ setEnable() [2/2]

me & by::enablesZone::setEnable ( nbool newVal)

Sets the enable state for all streams managed by the logger.

Parameters
newValThe new enable state (true for enabled, false for disabled).
Returns
A reference to this enablesZone instance.

◆ setPrev()

me & by::enablesZone::setPrev ( )

Captures the current enable states of all streams as the new "previous" state. This state will be restored when the enablesZone object is destroyed.

Returns
A reference to this enablesZone instance.

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