Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
LogFlex, a robust and flexible logging extension for Python, enhances the standard logging module by providing streamlined configuration via environmental variables and TOML files. This library supports comprehensive log management with features like dynamic log levels, multiple output handlers (console, file, and Syslog), and automatic log rotation. Ideal for developers looking to implement advanced logging practices easily in any Python application.
LogFlex is a flexible and powerful logging extension for Python applications, enhancing the built-in logging capabilities with advanced configuration options and support for multiple output handlers.
Install LogFlex using pip:
pip install logflex
LogFlex uses a combination of a TOML configuration file and environment variables to customize its behavior. Here is how you can set up your logging:
config.toml
)Create a config.toml
in your project root or specify its path during logger initialization. Here's an example configuration:
[general]
log_level = "DEBUG"
verbose = false
trace = false
[general.color_settings]
enable_color = true
datefmt = "%Y-%m-%d %H:%M:%S"
reset = true
log_colors.DEBUG = "cyan"
log_colors.INFO = "green"
log_colors.WARNING = "yellow"
log_colors.ERROR = "red"
log_colors.CRITICAL = "red,bg_white"
style = "%"
[file_handler]
logdir = "./logs"
logfile = "app.log"
dedicate_error_logfile = true
[syslog_handler]
use_syslog = true
syslog_address = "localhost"
syslog_port = 514 # UDP Port
syslog_facility = 'LOG_USER'
You can also configure LogFlex using environment variables, which override the settings from config.toml
. Here are some of the variables you can set:
GENERAL_LOG_LEVEL=DEBUG
GENERAL_VERBOSE=false
GENERAL_TRACE=false
FILEHANDLER_LOGDIR=/var/log/myapp
FILEHANDLER_LOGFILE=app.log
SYSLOGHANDLER_USE_SYSLOG=true
SYSLOGHANDLER_SYSLOG_ADDRESS=localhost
SYSLOGHANDLER_SYSLOG_PORT=514
COLOR_ENABLE_COLOR=true
COLOR_DATEFMT="%Y-%m-%d %H:%M:%S"
COLOR_RESET=true
COLOR_LOG_COLORS_DEBUG="cyan"
COLOR_LOG_COLORS_INFO="green"
COLOR_LOG_COLORS_WARNING="yellow"
COLOR_LOG_COLORS_ERROR="red"
COLOR_LOG_COLORS_CRITICAL="red,bg_white"
COLOR_STYLE="%"
FILEHANDLER_LOGDIR="./logs"
FILEHANDLER_LOGFILE="app.log"
FILEHANDLER_WHEN='midnight'
FILEHANDLER_INTERVAL=7
FILEHANDLER_BACKUP_COUNT=7
FILEHANDLER_DEDICATE_ERROR_LOGFILE=true
SYSLOGHANDLER_USE_SYSLOG=true
SYSLOGHANDLER_SYSLOG_ADDRESS='localhost'
SYSLOGHANDLER_SYSLOG_PORT=514
SYSLOGHANDLER_SYSLOG_FACILITY='LOG_USER'
from logflex import CustomLogger
# Initialize logger with default settings
logger = CustomLogger('exampleModule', loglevel='INFO')
# Write logs
logger.info("This is an info message")
logger.error("This is an error message")
from logflex import CustomLogger
# Initialize logger for console output with debug level
logger = CustomLogger('exampleModule', loglevel='DEBUG', verbose=true, trace=False, color_enable=true)
# Console output
logger.debug("This message will appear in the console.")
from logflex import CustomLogger
# Initialize logger with file output
logger = CustomLogger('exampleModule', loglevel='WARNING', file_logdir='./log', file_logfile='app.log',
file_when='midnight', file_interval=7, file_backup_count=7, file_dedicate_error_logfile=False)
logger.warning("This message will be logged to a file.")
from logflex import CustomLogger
# Initialize logger with Syslog handler
logger = CustomLogger('exampleModule', loglevel='CRITICAL', use_syslog=true, syslog_address='localhost', syslog_port=514,
syslog_facility='LOG_LOCAL0')
# Syslog output
logger.critical("This critical message will be sent to the configured Syslog server.")
Contributions to LogFlex are welcome! Please fork the repository and submit a pull request with your changes or improvements.
LogFlex is released under the MIT License. See the LICENSE file for more details.
For support, please open an issue on the GitHub repository or contact the maintainers directly.
FAQs
LogFlex, a robust and flexible logging extension for Python, enhances the standard logging module by providing streamlined configuration via environmental variables and TOML files. This library supports comprehensive log management with features like dynamic log levels, multiple output handlers (console, file, and Syslog), and automatic log rotation. Ideal for developers looking to implement advanced logging practices easily in any Python application.
We found that logflex demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.