Skip to content

Structured logging library for Go applications with built-in security features and industry-leading performance

License

Notifications You must be signed in to change notification settings

cloudresty/emit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

29 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Emit

A lightweight, structured logging library for Go applications with built-in security features and industry-leading performance. Emit provides automatic PII/sensitive data masking while outperforming all major logging libraries.

Β 

Go Reference Go Tests Go Report Card GitHub Tag License

Β 

  • Automatic data protection - PII and sensitive data masked by default
  • Elegant API - emit.Info.Msg() for simplicity, emit.Info.Field() for structure

Β 

Why Choose Emit?

Clean, Simple API

// Payment logging with built-in PCI DSS compliance
emit.Info.Field("Payment processed",
    emit.NewFields().
        String("transaction_id", "txn_abc123").
        String("card_number", "4111-1111-1111-1111").   // Auto-masked
        String("cardholder", "John Doe").               // Auto-masked
        Float64("amount", 99.99).
        String("currency", "USD").
        Bool("success", true))

πŸ” back to top

Β 

// Crystal clear intent - no cryptic function names
emit.Info.Field("User authenticated",
    emit.NewFields().
        String("user_id", "12345").
        String("email", "[email protected]"). // Auto-masked: "***PII***"
        Bool("success", true))

// Simple key-value pairs
emit.Error.KeyValue("Payment failed",
    "transaction_id", "txn_123",
    "amount", 99.99,
    "card_number", "4111-1111-1111-1111")    // Auto-masked: "***PII***"

πŸ” back to top

Β 

Zero-Config Security

Automatic protection of sensitive data without any configuration:

emit.Info.Field("User registration",
    emit.NewFields().
        String("email", "[email protected]").      // β†’ "***PII***"
        String("password", "secret123").          // β†’ "***MASKED***"
        String("api_key", "sk-1234567890").       // β†’ "***MASKED***"
        String("username", "john_doe").           // β†’ "john_doe" (safe)
        Int("user_id", 12345))                    // β†’ 12345 (safe)

πŸ” back to top

Β 

Installation

go get github.com/cloudresty/emit

πŸ” back to top

Β 

Quick Start

package main

import (
    "time"
    "github.com/cloudresty/emit"
)

func main() {

    // Clean, self-documenting API ✨

    // Structured logging with clear intent
    emit.Info.Field("User registration",
        emit.NewFields().
            String("email", "[email protected]").     // Auto-masked
            String("username", "john_doe").
            Int("user_id", 67890).
            Bool("newsletter", true).
            Time("created_at", time.Now()))

    // Simple key-value pairs
    emit.Error.KeyValue("Payment failed",
        "transaction_id", "txn_123",
        "amount", 29.99,
        "currency", "USD")

    // Ultra-fast structured field logging
    emit.Warn.StructuredFields("High memory usage",
        emit.ZString("service", "database"),
        emit.ZFloat64("memory_percent", 87.5))

    // Memory-pooled high-performance logging
    emit.Debug.Pool("Database operation", func(pf *emit.PooledFields) {
        pf.String("query", "SELECT * FROM users").
           Int("rows", 1234).
           Float64("duration_ms", 15.7)
    })

    // Simple messages
    emit.Info.Msg("Application started successfully")
}

Β 

JSON Output (Production):

{"timestamp":"2025-06-11T10:30:45.123456789Z","level":"info","message":"User registration","fields":{"email":"***PII***","username":"john_doe","user_id":67890,"newsletter":true,"created_at":"2025-06-11T10:30:45.123456789Z"}}
{"timestamp":"2025-06-11T10:30:45.124567890Z","level":"error","message":"Payment failed","fields":{"transaction_id":"txn_123","amount":29.99,"currency":"USD"}}

πŸ” back to top

Β 

Elegant API Overview

Every logging level (Info, Error, Warn, Debug) provides the same clean, consistent interface:

// All levels support the same methods
emit.Info.Msg(msg)                           // Simple message
emit.Info.Field(msg, fields)                 // Structured fields
emit.Info.StructuredFields(msg, zfields...)  // Ultra-fast structured fields (Zap-compatible)
emit.Info.KeyValue(msg, k, v, ...)           // Key-value pairs
emit.Info.Pool(msg, func)                    // Memory-pooled performance

// Same elegant API for all levels
emit.Error.Field(msg, fields)                // Error with structured data
emit.Warn.KeyValue(msg, k, v, ...)           // Warning with key-values
emit.Debug.StructuredFields(msg, zfields...) // Debug with structured fields

πŸ” back to top

Β 

Key Features

Built-in Security

  • Automatic PII masking - Emails, phone numbers, addresses protected by default
  • Sensitive data protection - Passwords, API keys, tokens automatically masked
  • GDPR/CCPA compliant - Built-in compliance with privacy regulations
  • Zero data leaks - Impossible to accidentally log sensitive information

Β 

Performance Optimized

  • 63.0 ns/op simple logging - 23% faster than Zap
  • 96.0 ns/op structured fields - 33% faster than Zap with zero allocations
  • Zero-allocation API - StructuredFields() methods achieve 0 B/op, 0 allocs/op
  • Memory pooling - Pool() methods for high-throughput scenarios

Β 

Developer Friendly

  • Elegant API - Clear, self-documenting method names
  • IDE-friendly - Perfect autocomplete with emit.Info. discovery
  • Zero dependencies - Uses only Go standard library
  • Environment-aware - JSON for production, plain text for development

πŸ” back to top

Β 

Documentation

Β 

Complete Guides

πŸ” back to top

Β 

Environment Configuration

# Production (secure by default)
export EMIT_FORMAT=json
export EMIT_LEVEL=info
# PII and sensitive masking enabled automatically

# Development (show data for debugging)
export EMIT_FORMAT=plain
export EMIT_LEVEL=debug
export EMIT_MASK_SENSITIVE=false
export EMIT_MASK_PII=false

πŸ” back to top

Β 

Programmatic Setup

// Quick setup
emit.SetComponent("user-service")
emit.SetVersion("v2.1.0")
emit.SetLevel("info")

// Production mode (secure, JSON, info level)
emit.SetProductionMode()

// Development mode (show data, plain text, debug level)
emit.SetDevelopmentMode()

πŸ” back to top

Β 

Real-World Examples

Microservice Logging

// Service initialization
emit.SetComponent("auth-service")
emit.SetVersion("v1.2.3")

// Request logging with automatic security
emit.Info.Field("API request",
    emit.NewFields().
        String("method", "POST").
        String("endpoint", "/api/login").
        String("user_email", userEmail).        // Auto-masked
        String("client_ip", clientIP).          // Auto-masked
        Int("status_code", 200).
        Duration("response_time", duration))

πŸ” back to top

Β 

Payment Processing

// Payment logging with built-in PCI DSS compliance
emit.Info.Field("Payment processed",
    emit.NewFields().
        String("transaction_id", "txn_abc123").
        String("card_number", "4111-1111-1111-1111").  // Auto-masked
        String("cardholder", "John Doe").              // Auto-masked
        Float64("amount", 99.99).
        String("currency", "USD").
        Bool("success", true))

πŸ” back to top

Β 

High-Performance Logging

// Ultra-fast logging for hot paths
func processRequest() {
    start := time.Now()

    // ... request processing

    emit.Debug.StructuredFields("Request processed",
        emit.ZString("endpoint", "/api/data"),
        emit.ZInt("status", 200),
        emit.ZDuration("duration", time.Since(start)))
}

πŸ” back to top

Β 

Migration from Other Loggers

From Standard Log

// Before (UNSAFE)
log.Printf("User %s with password %s logged in", username, password)

// After (SECURE)
emit.Info.KeyValue("User logged in",
    "username", username,      // Auto-protected if PII
    "password", password)      // Auto-masked

πŸ” back to top

Β 

From Logrus

// Before (manual security)
logrus.WithFields(logrus.Fields{
    "email": maskEmail(email),  // Manual masking required!
}).Info("User action")

// After (automatic security)
emit.Info.Field("User action",
    emit.NewFields().
        String("email", email))  // Auto-masked

πŸ” back to top

Β 

From Zap

// Before (complex, manual security)
logger.Info("Payment",
    zap.String("email", maskPII(email)),     // Manual masking!
    zap.String("card", maskSensitive(card))) // Manual masking!

// After (simple, automatic security)
emit.Info.KeyValue("Payment processed",
    "email", email,    // Auto-masked
    "card", card)      // Auto-masked

πŸ” back to top

Β 

Compliance & Security

Automatic Compliance

  • βœ… GDPR - EU personal data automatically protected
  • βœ… CCPA - California privacy law compliance
  • βœ… HIPAA - Healthcare data protection (with custom fields)
  • βœ… PCI DSS - Payment card data automatically masked

πŸ” back to top

Β 

Protected Data Types

PII (Automatically Masked as ***PII***)

  • Email addresses, phone numbers, names
  • Addresses, IP addresses, credit cards
  • SSN, passport numbers, driver licenses

Sensitive Data (Automatically Masked as ***MASKED***)

  • Passwords, PINs, API keys
  • Access tokens, private keys, certificates
  • Session IDs, authorization headers

πŸ” back to top

Β 

Why Emit is the Secure Choice

Traditional Loggers

  • ❌ Manual data protection required
  • ❌ Easy to accidentally log sensitive data
  • ❌ Complex setup for production security
  • ❌ Risk of compliance violations

Β 

Emit in a Nutshell

  • βœ… Automatic data protection out of the box
  • βœ… Impossible to accidentally expose PII/sensitive data
  • βœ… Zero-config security for production
  • βœ… Built-in compliance with privacy regulations
  • βœ… Elegant, developer-friendly API
  • βœ… Performance optimized for production workloads

πŸ” back to top

Β 

Real-World Impact Summary

Security: The Hidden Cost of Traditional Loggers

When choosing a logging library, most developers focus solely on performance metrics. However, security vulnerabilities in logging are among the most common causes of data breaches in production applications:

  • Data Breach Risk: Traditional loggers like Zap and Logrus require developers to manually mask sensitive data. A single oversight can expose passwords, API keys, or PII in log files.
  • Compliance Violations: GDPR fines can reach €20M or 4% of annual revenue. CCPA violations cost up to $7,500 per record. Emit's automatic masking prevents these costly violations.
  • Developer Burden: Manual masking increases development time and introduces bugs. Emit eliminates this overhead entirely.

πŸ” back to top

Β 

Performance: Security Without Compromise

Traditional Assumption: "Security features must sacrifice performance" Emit Reality: Built-in security with industry-leading speed

Our benchmarks demonstrate that Emit's automatic security features add zero performance overhead compared to manual implementations: Benchmark results.

Key Insight: Emit with automatic security (213 ns/op) is significantly faster than Logrus without any security protection (2,872 ns/op), and competitive with Zap's unsafe mode (171 ns/op) while providing complete data protection.

πŸ” back to top

Β 

Production Impact: Beyond Benchmarks

Traditional Logging Workflow

  1. Write logging code
  2. Manually identify sensitive fields
  3. Implement custom masking functions
  4. Review code for security issues
  5. Test masking implementations
  6. Monitor for data leaks in production
  7. Risk: One missed field = potential breach

πŸ” back to top

Β 

Emit Workflow

  1. Write logging code
  2. Done - Security is automatic and guaranteed

πŸ” back to top

Β 

Cost Analysis

Medium-sized application (10 developers, 2-year development cycle):

Traditional Loggers:
- Security implementation time: 40 hours/developer = 400 hours
- Security review overhead: 20% of logging code reviews = 80 hours
- Bug fixes for missed masking: 20 hours
- Total: 500 hours Γ— $150/hour = $75,000

Emit:
- Security implementation time: 0 hours (automatic)
- Security review overhead: 0 hours (automatic)
- Bug fixes: 0 hours (impossible to leak data)
- Total: $0

ROI: $75,000 saved + zero breach risk

πŸ” back to top

Β 

When to Choose Each Approach

Choose Emit when:

  • Building production applications with sensitive data
  • Compliance requirements (GDPR, CCPA, HIPAA, PCI DSS)
  • Team includes junior developers
  • Performance is critical
  • Development speed matters

Choose traditional loggers when:

  • Working with completely non-sensitive data
  • You have dedicated security experts on your team
  • You enjoy implementing custom security solutions
  • Vendor lock-in concerns outweigh security benefits

Bottom Line: Emit delivers the security of enterprise logging solutions with the performance of the fastest libraries and the simplicity of modern APIs.

πŸ” back to top

Β 

Get Started

  1. Install: go get github.com/cloudresty/emit
  2. Basic usage: emit.Info.Msg("Hello, secure world!")
  3. Add structure: emit.Info.KeyValue("User action", "user_id", 123)
  4. Go advanced: emit.Info.Field("Complex event", emit.NewFields()...)
  5. Optimize performance: emit.Info.StructuredFields("Hot path", emit.ZString(...))

Choose emit for secure, compliant, and elegant logging in your Go applications.

πŸ” back to top

Β 

Performance Breakthrough: Zero-Allocation Structured Fields

Emit achieves what was previously thought impossible in Go logging - zero heap allocations for structured field logging while maintaining full compatibility with Zap-style APIs.

// Zero-allocation structured logging (Zap-compatible API)
emit.Info.StructuredFields("User action",          // 96 ns/op, 0 B/op, 0 allocs/op
    emit.ZString("user_id", "12345"),
    emit.ZString("action", "login"),
    emit.ZString("email", "[email protected]"),      // β†’ "***MASKED***" (automatic)
    emit.ZBool("success", true))

// Compare with Zap (requires heap allocations)
zapLogger.Info("User action",                      // 143 ns/op, 259 B/op, 1 allocs/op
    zap.String("user_id", "12345"),
    zap.String("action", "login"),
    zap.String("email", "[email protected]"),        // β†’ "[email protected]" (exposed!)
    zap.Bool("success", true))

πŸ” back to top

Β 

Performance Comparison:

  • 33% faster than Zap's structured logging
  • Zero memory allocations vs Zap's heap allocations
  • Built-in security vs manual implementation required

πŸ” back to top

Β 

License

MIT License - see LICENSE file for details.

Β 


Β 

An open source project brought to you by the Cloudresty team.

Website Β |Β  LinkedIn Β |Β  BlueSky Β |Β  GitHub

Β 

About

Structured logging library for Go applications with built-in security features and industry-leading performance

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published