A minimal logger and web server
Project description
ML3Log
A minimal Python logging package that provides both console logging and a web interface to view logs.
Features
- Standard Python logger compatible
- Web server for viewing logs in real-time
- Minimal footprint with no external dependencies
- Configurable port (default: 6020)
- Monkey patching support for standard logging module
- Command-line interface for quick server startup
Installation
pip install ml3log
Usage
Starting the server
From Python code
import ml3log
# Start the server on the default port (6020)
ml3log.start_server()
# Or specify a custom port
ml3log.start_server(port=8080)
From the command line
ML3Log can be started directly from the command line:
# Using the ml3log command (after installation)
ml3log
# Or with custom host and port
ml3log --host 0.0.0.0 --port 8080
# Alternatively, using the Python module syntax
python -m ml3log
Using the logger
import ml3log
import logging
# Get a logger with default settings
logger = ml3log.get_logger("my_app")
# Or customize the logger
logger = ml3log.get_logger(
name="my_app",
level=logging.DEBUG,
host="localhost",
port=6020
)
# Alternatively, monkey patch the standard logging module
# to capture logs from libraries using standard logging
ml3log.monkey_patch_logging()
# Use like a standard Python logger
logger.info("This is an info message")
logger.warning("This is a warning")
logger.error("This is an error")
logger.debug("This is a debug message")
# Log exceptions
try:
1/0
except Exception as e:
logger.exception("An error occurred")
Sending logs from JavaScript
You can send logs directly from JavaScript to ML3Log using a simple fetch request:
// Minimal example to send a log event to ML3Log
async function sendLog(message, level = 'INFO', loggerName = 'js-client') {
const logEntry = {
levelname: level,
name: loggerName,
message: message,
created: Date.now() / 1000 // Current time in seconds
};
try {
const response = await fetch('http://localhost:6020/traces', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(logEntry)
});
return response.ok;
} catch (error) {
console.error('Failed to send log:', error);
return false;
}
}
// Usage examples
sendLog('User clicked submit button');
sendLog('API request failed', 'ERROR');
sendLog('Debug information', 'DEBUG', 'frontend-app');
Viewing logs
Open your browser and navigate to:
http://localhost:6020
The web interface will automatically update with new logs as they arrive.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ml3log-0.1.1.tar.gz.
File metadata
- Download URL: ml3log-0.1.1.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23e0fb15c80c2c4a8ec95bc9de438b92e85a7c349282b75685702f364248ceed
|
|
| MD5 |
11616f968539ab7affe613eb98939643
|
|
| BLAKE2b-256 |
7104c7c305391006be7689a00f169520a244e065e84397d12c6e1644c995d416
|
File details
Details for the file ml3log-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ml3log-0.1.1-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63fa9de6edc7e72a6d1503051f53b45ff2e9849af9c387844d2a99ee2f05c7c1
|
|
| MD5 |
031186bee7faaab82749acbe2bf38634
|
|
| BLAKE2b-256 |
270df056bc330e101238a3ebe144bc310f6bc8a60c0418c45ac096339c428415
|