Skip to main content

Collaborative, beautiful logging system for distributed developers

Project description

🧠 LogMachine

Collaborative, beautiful logging system for distributed developers

logmachine helps teams log smarter. It’s a fully pluggable logging system that supports colored output, JSON parsing, structured log forwarding via HTTP or Socket.IO, and log centralization — all from a standard Python logging interface.


🚀 Features

  • 🔥 Color-coded terminal logs (DEBUG, INFO, WARNING, ERROR, SUCCESS)
  • 📤 Log forwarding to a central HTTP or Socket.IO server
  • 🪵 Custom log levels (add your own with .new_level(...))
  • 👥 User identity tracking for team-based logs
  • 🧩 Pluggable backends: send logs to a central server or local files
  • 📦 Simple JSON output for web dashboards or collectors
  • 🧽 Strips ANSI escape codes from logs for clean parsing
  • 🧠 Automatically resolves usernames and saves them in ~/.cl_username

⚙️ Installation

pip install logmachine

🧰 Usage

Basic Setup

from logmachine import LogMachine

# Create a simple logger without central logging
# Providing a non-empty string initializes the logger with that name, else the root logger is used to collect every single log in the python process.
logger = LogMachine("myapp", debug_level=1)

logger.info("Hello, world!")
logger.error("An error occurred!")
logger.success("Operation completed successfully!")
logger.debug("Debugging information here.")
logger.warning("This is a warning message.")

With Central Logging (HTTP or Socket.IO)

You can use the default logger with central logging pointing to "https://logmachine.bufferpunk.com"

from logmachine import default_logger
logger = default_logger()
logger.info("This log is sent to the LogMachine default central server!")

This is the default central logging server for logmachine, and you can create your own room there for free. To use your own central logging server, provide the configuration as shown below:

logger_config = {
    "url": "https://logmachine.bufferpunk.com",  # Base server URL
    "room": "team_alpha",                # Your organization or room
    "endpoint": "/api/logs",             # Optional, defaults to /api/logs for HTTP or /api/socket.io/ for Socket.IO transport.
    "headers": {"Authorization": "Bearer token"}, # The central server should know your username based on the token you provide here. This is optional and depends on your central server's authentication mechanism.
}
logger = LogMachine("with_central", debug_level=0, central=logger_config, socketio=True)
logger.success("Central logging is working!")

🎨 Log Format

Every log includes:

  • ✅ Username (resolved automatically or via server)
  • 📁 Module directory
  • ⏱️ Timestamp
  • 📦 Level (INFO, ERROR, etc.)
  • 📝 Message

Sample (terminal):

(username @ myapp) 🤌 CL Timing: [ 2025-08-04T11:23:52 ]
[ INFO ] Server started on port 8000
🏁

🛠️ Advanced

Add Your Own Log Level

logger.new_level("CRITICAL_HACK", 60)
logger.new_level("CRITICAL_HACK", 60, color="\033[38;5;13m")  # Optional color... does your girlfriend love pink? Maybe you should be in a relationship with your terminal.
logger.critical_hack("Zero day found!")

📤 Parse & Export

Convert Logs to JSON

This is useful for sending logs to web dashboards or log collectors that expect JSON. It reads the your log files, parses the log entries, and outputs them as JSON objects.

json_logs = log.jsonifier()
for entry in json_logs:
    print(entry)

📡 Central Server Compatibility

To use Socket.IO, your central server must support this event:

  • log: Receives log payloads: { room: string, data: object }

For central username resolution, your server should expose an endpoint like:

  • GET /api/get_username?base=localname: Returns { "username": "..." }

🤖 Environment Variables

  • CL_USERNAME: Manually override detected username
  • Automatically stored in ~/.cl_username for persistent identity

🔐 Security

  • HTTP headers (e.g. Authorization) can be injected
  • Central log transmission is fully customizable

🔧 Configuration Summary

Param Type Description
url str Central server base URL
room str Logical group or org name
endpoint str HTTP endpoint for POST logs (default: /api/logs or /api/socket.io/ for Socket.IO)
headers dict Extra headers to send (e.g. auth token)

📄 License

MIT License


🙋‍♂️ Author

Mugabo Gusenga logmachine.bufferpunk.com GitHub


❤️ Contribute

PRs and issues are welcome! This tool is built for devs who want beautiful logs with distributed brains. Let’s make debugging fun again.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

logmachine-2.3.2.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

logmachine-2.3.2-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file logmachine-2.3.2.tar.gz.

File metadata

  • Download URL: logmachine-2.3.2.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for logmachine-2.3.2.tar.gz
Algorithm Hash digest
SHA256 05fac61feff3b909ec9a4696d1674befb88b06935f13040235ea4454a015f173
MD5 dccdd4516fb442956af70dc508ee2edc
BLAKE2b-256 0ed8c93751b449b2209e590e81022b2e29b0de5eb6542315410f6866f8d39aae

See more details on using hashes here.

File details

Details for the file logmachine-2.3.2-py3-none-any.whl.

File metadata

  • Download URL: logmachine-2.3.2-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for logmachine-2.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 23dbf8ee05a2e5e8e728513a68c1d5d0a1c86351f143f9d6ce3b0294bcfcb7a2
MD5 1665a1de7ec6745c2def669ec0e89422
BLAKE2b-256 9759ad27aa3f8bc9d62ae095ec9a8eb8d880808bd1ca1ea14344fe49c7db417b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page