Logging in Go
This repository contains examples of
Logging with Zerolog,
Logging with Zap,
and
Logging with Slog
in a simple Go web application (Wikipedia Search) to give you an idea of how you
can get started with logging in your own projects.
Here are the accompanying tutorials for each package:
🟢 Prerequisites
You must have the latest version of Go installed
on your machine. This project was tested against v1.20.
📦 Getting started
- Clone this repo to your machine:
git clone https://github.com/betterstack-community/go-logging
cd
into the project folder and switch to the relevant branch:
cd go-logging
git checkout zerolog
# or
git checkout zap
# or
git checkout slog
- Run
go mod tidy
to download dependencies.
- Execute the command below to start the development server on port 3000:
go build -o bin/logging && ./bin/logging
# or provide a different port like this
go build -o bin/logging && PORT=4000 ./bin/logging
- Visit http://localhost:3000 in your browser.
- Enter a search query, and view the corresponding logs in your console and in
the
logs/app.log
file.
âš– License
The code used in this project and in the linked tutorial are licensed under the
Apache License, Version 2.0.