Convert Figma logo to code with AI

golang logoglog

Leveled execution logs for Go

3,539
906
3,539
2

Top Related Projects

24,641

Structured, pluggable logging for Go.

21,865

Blazing fast, structured, leveled logging in Go.

10,498

Zero Allocation JSON Logger

1,103

Structured, composable logging for Go

1,365

Structured logging package for Go.

lumberjack is a log rolling package for Go

Quick Overview

Glog is a leveled execution log package for Go, inspired by Google's C++ implementation. It provides a simple and efficient way to add logging to Go applications, with support for different log levels, log file rotation, and various output options.

Pros

  • Easy to use and integrate into existing Go projects
  • Supports multiple log levels (INFO, WARNING, ERROR, FATAL)
  • Offers log file rotation and automatic log management
  • Provides flexible configuration options for log output

Cons

  • Not actively maintained (last commit was in 2018)
  • Lacks some advanced features found in more modern logging libraries
  • May not be the best choice for new projects due to its age

Code Examples

  1. Basic logging:
import "github.com/golang/glog"

func main() {
    glog.Info("This is an informational message")
    glog.Warning("This is a warning message")
    glog.Error("This is an error message")
    glog.Flush() // Ensure all logs are written before exiting
}
  1. Logging with formatting:
import "github.com/golang/glog"

func main() {
    name := "Alice"
    age := 30
    glog.Infof("User %s is %d years old", name, age)
    glog.Flush()
}
  1. Conditional logging:
import "github.com/golang/glog"

func main() {
    if glog.V(1) {
        glog.Info("This is a verbose log message")
    }
    glog.Flush()
}

Getting Started

To use glog in your Go project, follow these steps:

  1. Install the package:

    go get -u github.com/golang/glog
    
  2. Import the package in your Go file:

    import "github.com/golang/glog"
    
  3. Use glog functions to log messages:

    glog.Info("Hello, glog!")
    glog.Warning("This is a warning")
    glog.Error("An error occurred")
    
  4. Remember to call glog.Flush() before your program exits to ensure all logs are written.

  5. Run your program with desired flags, e.g.:

    go run main.go -log_dir=/tmp/logs -v=2
    

Competitor Comparisons

24,641

Structured, pluggable logging for Go.

Pros of logrus

  • More feature-rich with structured logging, hooks, and customizable formatters
  • Active development and community support
  • Better performance in high-load scenarios

Cons of logrus

  • Slightly more complex API compared to glog's simplicity
  • Larger dependency footprint
  • May require more configuration for basic use cases

Code Comparison

glog:

import "github.com/golang/glog"

glog.Info("This is an info log")
glog.Errorf("An error occurred: %v", err)

logrus:

import "github.com/sirupsen/logrus"

log := logrus.New()
log.WithFields(logrus.Fields{
    "animal": "walrus",
}).Info("A walrus appears")

Summary

glog is a simple, lightweight logging package that follows Google's logging conventions. It's easy to use but lacks some advanced features. logrus, on the other hand, offers more flexibility and features like structured logging and hooks. It's more suitable for complex applications but may be overkill for simpler projects. The choice between the two depends on the specific requirements of your project and your preference for simplicity versus feature richness.

21,865

Blazing fast, structured, leveled logging in Go.

Pros of zap

  • Significantly faster performance and lower allocation overhead
  • More flexible and customizable logging options
  • Structured logging with type-safe field construction

Cons of zap

  • Steeper learning curve due to more complex API
  • Requires more setup and configuration compared to glog's simplicity

Code Comparison

glog example:

import "github.com/golang/glog"

glog.Info("Informational message")
glog.Errorf("Error: %v", err)

zap example:

import "go.uber.org/zap"

logger, _ := zap.NewProduction()
defer logger.Sync()

logger.Info("Informational message")
logger.Error("Error occurred", zap.Error(err))

Summary

zap offers superior performance and more advanced features compared to glog, making it suitable for high-performance applications that require structured logging. However, glog provides a simpler API and easier setup, which may be preferable for smaller projects or developers who prioritize ease of use. The choice between the two depends on the specific requirements of the project and the team's preferences.

10,498

Zero Allocation JSON Logger

Pros of zerolog

  • Offers structured logging with a focus on performance and low allocation
  • Provides a fluent API for easier and more readable log construction
  • Supports JSON output format natively, which is beneficial for log parsing

Cons of zerolog

  • Requires more setup and configuration compared to glog's simpler approach
  • May have a steeper learning curve for developers new to structured logging
  • Less integrated with Google's internal tooling and practices

Code Comparison

glog:

import "github.com/golang/glog"

glog.Info("Informational message")
glog.Errorf("Error occurred: %v", err)

zerolog:

import "github.com/rs/zerolog"

logger := zerolog.New(os.Stdout)
logger.Info().Msg("Informational message")
logger.Error().Err(err).Msg("Error occurred")

Summary

zerolog offers more advanced features and better performance for structured logging, while glog provides a simpler, more traditional logging approach. The choice between them depends on project requirements, team expertise, and integration needs with existing systems.

1,103

Structured, composable logging for Go

Pros of log15

  • Structured logging with key-value pairs
  • Flexible output formatting (JSON, logfmt, etc.)
  • Support for logging contexts and child loggers

Cons of log15

  • Less integrated with standard library compared to glog
  • May require more setup and configuration

Code Comparison

glog:

import "github.com/golang/glog"

glog.Info("Starting application")
glog.Errorf("Failed to connect: %v", err)

log15:

import "github.com/inconshreveable/log15"

log := log15.New()
log.Info("Starting application")
log.Error("Failed to connect", "error", err)

Key Differences

  • glog uses a global logger, while log15 encourages creating logger instances
  • log15 supports structured logging with key-value pairs
  • glog integrates more closely with Go's flag package for configuration

Use Cases

  • glog: Better suited for simple logging needs and projects closely aligned with Google's practices
  • log15: Ideal for applications requiring structured logging and more flexible output formatting

Community and Maintenance

  • glog: Maintained by Google, part of the official Go project
  • log15: Community-driven project with active maintenance

Both libraries offer logging capabilities for Go applications, but they cater to different needs and preferences in terms of features and usage patterns.

1,365

Structured logging package for Go.

Pros of apex/log

  • More flexible and customizable logging levels and handlers
  • Supports structured logging with key-value pairs
  • Offers a variety of output formats, including JSON and CLI-friendly formats

Cons of apex/log

  • Less mature and less widely adopted compared to glog
  • May have a steeper learning curve for developers familiar with glog
  • Lacks some advanced features like automatic log rotation

Code Comparison

glog:

import "github.com/golang/glog"

glog.Info("This is an info log")
glog.Errorf("An error occurred: %v", err)

apex/log:

import "github.com/apex/log"

log.Info("This is an info log")
log.WithError(err).Error("An error occurred")

Both libraries provide logging functionality, but apex/log offers a more modern API with structured logging support. glog uses a more traditional approach with severity levels, while apex/log allows for more flexible logging with fields and contexts. The choice between the two depends on specific project requirements and developer preferences.

lumberjack is a log rolling package for Go

Pros of Lumberjack

  • Provides log file rotation and compression
  • Simple and lightweight, focusing on a single responsibility
  • Easy integration with Go's standard library log package

Cons of Lumberjack

  • Limited to file-based logging only
  • Lacks built-in log levels and formatting options
  • Requires additional configuration for advanced logging features

Code Comparison

Lumberjack:

log.SetOutput(&lumberjack.Logger{
    Filename:   "/var/log/myapp/foo.log",
    MaxSize:    500, // megabytes
    MaxBackups: 3,
    MaxAge:     28, // days
    Compress:   true,
})
log.Println("This is a log message")

Glog:

flag.Parse()
glog.Info("This is an info log message")
glog.Warning("This is a warning log message")
glog.Error("This is an error log message")
glog.Flush()

Key Differences

  • Lumberjack focuses on log rotation and compression, while Glog provides a more comprehensive logging solution with built-in log levels.
  • Glog offers command-line flag integration for configuration, whereas Lumberjack requires programmatic setup.
  • Lumberjack works seamlessly with Go's standard log package, while Glog introduces its own logging functions and types.

Use Cases

  • Choose Lumberjack when you need simple log rotation and compression for file-based logging.
  • Opt for Glog when you require a full-featured logging solution with multiple log levels and flexible output options.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

glog

PkgGoDev

Leveled execution logs for Go.

This is an efficient pure Go implementation of leveled logs in the manner of the open source C++ package glog.

By binding methods to booleans it is possible to use the log package without paying the expense of evaluating the arguments to the log. Through the -vmodule flag, the package also provides fine-grained control over logging at the file level.

The comment from glog.go introduces the ideas:

Package glog implements logging analogous to the Google-internal C++ INFO/ERROR/V setup. It provides the functions Info, Warning, Error, Fatal, plus formatting variants such as Infof. It also provides V-style loggingcontrolled by the -v and -vmodule=file=2 flags.

Basic examples:

glog.Info("Prepare to repel boarders")
	
glog.Fatalf("Initialization failed: %s", err)

See the documentation for the V function for an explanation of these examples:

if glog.V(2) {
	glog.Info("Starting transaction...")
}
glog.V(2).Infoln("Processed", nItems, "elements")

The repository contains an open source version of the log package used inside Google. The master copy of the source lives inside Google, not here. The code in this repo is for export only and is not itself under development. Feature requests will be ignored.

Send bug reports to golang-nuts@googlegroups.com.