Skip to main content

A zero-dependency single-file logging library.

Project description

10 languages Zero deps License Copy paste

🐞 LogX

One file. Ten languages. Zero dependencies.
Copy. Paste. Log.


What if logging were this easy?

from logx import info, warn, error

info("Server started on port %d", 8080)
warn("Memory at %.1f%%", 74.2)
error("Connection lost")
LOGX_INFO("Server started on port %d", 8080);
LOGX_WARN("Memory at %.1f%%", 74.2);
LOGX_ERROR("Connection lost");
logx_info!("Server started on port {}", 8080);
logx_warn!("Memory at {:.1}%", 74.2);
logx_error!("Connection lost");

That's it. No installs. No config files. No npm install hunting down 200 transitive deps.


Why LogX?

Logging should be as easy as print(). But print() doesn't give you levels, timestamps, colors, or file output.

Most logging libraries give you all that — and also give you a headache. Setup, configuration, dependencies, framework lock-in...

LogX is the opposite. One file per language. Same API philosophy everywhere. Drop it in, include it, done.

Why not just print()?

Feature print() LogX
Log levels ✅ TRACE, INFO, WARN, ERROR, FATAL
Timestamps [HH:MM:SS.mmm]
File & line ✅ Automatic
Colored output ✅ Auto TTY detection
File logging ✅ Optional, one call
Thread safe ✅ Mutex-guarded
Level filtering LOG_LEVEL=WARN ./app
Still one file

Quick Start

Language File Include
Python python/logx.py from logx import info
JavaScript js/logx.js const { info } = require('./logx')
TypeScript ts/logx.ts import { info } from './logx'
C c/logx.h #include "logx.h"LOGX_INFO(...)
C++ cpp/logx.h #include "logx.h"LOGX_INFO << ...
Rust rust/logx.rs #[macro_use] mod logx;logx_info!(...)
Go go/logx.go import "yourmodule/logx"logx.Info(...)
Java java/logx.java import Logx;Logx.info(...)
Zig zig/logx.zig @import("logx.zig")logx.log(.info, ...)
Assembly asm/logx.asm %include "logx.asm"log_info "..."

Install via pip (Python)

pip install python-logx
from logx import trace, info, warn, error, fatal, set_log_file

info("hello %d", 42)
error("something broke")

set_log_file("/tmp/app.log")  # redirect to file

JavaScript (Node)

const { trace, info, warn, error, fatal, setLogFile } = require('./logx');

info('hello %d', 42);
error('something broke');

TypeScript

import { trace, info, warn, error, fatal, setLogFile } from './logx';

info('hello %d', 42);
error('something broke');

C

#include "logx.h"

int main() {
    LOGX_INFO("hello %d", 42);
    LOGX_ERROR("something broke");
}
// Optional: log to file
lx_set_log_file("/tmp/app.log");
gcc -std=c11 main.c -o app -lpthread

C++

#include "logx.h"

int main() {
    LOGX_INFO << "hello " << 42;
    LOGX_ERROR << "something broke";
}
// Optional: log to file
Logx::setLogFile("/tmp/app.log");
Logx::setLogFile();  // back to terminal
g++ -std=c++11 main.cpp -o app

Rust

#[macro_use] mod logx;

fn main() {
    logx_info!("hello {}", 42);
    logx_error!("something broke");
}
// Optional: log to file
logx::set_log_file("/tmp/app.log");
[dependencies]
libc = "0.2"

Go

package main

import "yourmodule/logx"

func main() {
    logx.Info("hello %d", 42)
    logx.Error("something broke")
}
// Optional: log to file
logx.SetLogFile("/tmp/app.log")

Java

public class Main {
    public static void main(String[] args) {
        Logx.info("hello %d", 42);
        Logx.error("something broke");
    }
}
// Optional: log to file
Logx.setLogFile("/tmp/app.log");
javac Logx.java Main.java && java Main

Zig

const logx = @import("logx.zig");

pub fn main() void {
    logx.log(.info, "hello 42", @src());
    logx.log(.error, "something broke", @src());
}
// Optional: log to file
try logx.setLogFile("/tmp/app.log");

x86-64 Assembly (Linux, NASM)

%include "logx.asm"

section .data
log_str(msg_hello, "hello 42")
log_str(msg_error, "something broke")

section .text
global _start
_start:
    call log_init
    log_info msg_hello
    log_error msg_error
    call log_close

    mov rax, 60
    xor rdi, rdi
    syscall
; Optional: log to file (define before including)
%define LOG_FILE_PATH "/tmp/app.log"
%include "logx.asm"
nasm -felf64 main.asm -o main.o && ld main.o -o main

Environment Variables

Variable Values Default
LOG_LEVEL TRACE, INFO, WARN, ERROR, FATAL TRACE
LOG_COLOR 0, 1, yes Auto (enabled if both stdout/stderr are TTYs)

Output Format

[HH:MM:SS.mmm][LEVEL] filename:line -> message

Philosophy

LogX is not trying to replace OpenTelemetry. It is built for:

  • Prototypes & hackathons
  • CLI tools & scripts
  • Game jams
  • Students learning a new language
  • Small-to-medium projects
  • Anyone who just wants to log without ceremony

"If you can write print(), you already know how to use LogX."

License

BSD 2-Clause. See LICENSE.

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

python_logx-1.0.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

python_logx-1.0.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file python_logx-1.0.0.tar.gz.

File metadata

  • Download URL: python_logx-1.0.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for python_logx-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0542317af0f7cb8c31a1b6a1d001ec8f887767e4508ac69feed27943df3d42c1
MD5 5fa3618caacf49342d7779f012f18931
BLAKE2b-256 0978492c5cd65d4283594b590a874a4bbe574b36a8811f6ee5465fd9d0d019be

See more details on using hashes here.

File details

Details for the file python_logx-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: python_logx-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for python_logx-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6dcf79e9edf872f6773e25a1aa883095721f1cb0d18bd0d09c421e6d7d18b9b3
MD5 b01ee12e012c725d98d07923fb228308
BLAKE2b-256 666a3a75179dace7fbaac0f9edf78b2bb1092eddc62828b1b412b2b95c0ff1f1

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