This Python script provides a simple logging configuration with configurable options. It includes a class LOG
that facilitates logging messages with different log levels, and a class LogConfig
to set up the logging configuration.
No specific installation is required. Simply include the provided script in your project, and you can start using the logging functionality.
To use the logging functionality in your Python script, follow these steps:
-
Import the script:
from logit import LOG, LogConfig
-
Create a
LogConfig
instance with desired configurations:log_config = LogConfig(headers=True, level='INFO', outputFile='MyLog.log')
-
Create a
LOG
instance with theLogConfig
:logger = LOG(log_config)
-
Log messages using the
log
method:logger.log('INFO', 'This is an informational message.')
The LogConfig
class is used to configure the logging settings. It has the following parameters:
headers
: Boolean (default:False
) - Whether to include headers in the log messages.level
: String (default:'DEBUG'
) - The logging level. Valid values are'DEBUG'
,'INFO'
,'WARN'
, and'ERROR'
.outputFile
: String (default:'Default.log'
) - The name of the log file where the messages will be stored.
The LOG
class is responsible for initializing the logging system and providing the log
method to log messages. It takes a LogConfig
instance as its configuration.
from logger import LOG, LogConfig
# Configure logging with default settings
log_config = LogConfig()
logger = LOG(log_config)
# Log a message
logger.log('INFO', 'This is an informational message.')
Example 2: Custom Configuration
python
Copy code
from logger import LOG, LogConfig
# Configure logging with custom settings
log_config = LogConfig(headers=True, level='WARN', outputFile='CustomLog.log')
logger = LOG(log_config)
# Log a warning message
logger.log('WARN', 'This is a warning message.')
Feel free to customize the LogConfig parameters to suit your project's logging requirements.