WillAbides / actionslog

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

actionslog

Go Reference

Contributions welcome.

go get github.com/willabides/actionslog

actionslog's creation was blogged here

actionslog provides a wrapper around a Handler for Go's log/slog that outputs logs as GitHub Actions workflow commands that will cause the logs to show up in the GitHub UI -- optionally with links to the source code.

It can wrap any slog.Handler, but it also provides human.Handler which is meant to be a little easier for human's to read. human.Handler's output is roughly <message>\n <vars as yaml>, so output for logger.Info("hello", slog.String("object", "world"), slog.Any("list", []string{"a", "b", "c")) would look like:

hello
  object: world
  list:
    - a
    - b
    - c

actionslog.Wrapper implements slog.Handler from "log/slog" when built with go 1.21 or higher. When built with go earlier versions that predate "log/slog", it implements slog.Handler from "golang.org/x/exp/slog".

Usage

package main

import (
	"log/slog"

	"github.com/willabides/actionslog"
	"github.com/willabides/actionslog/human"
)

func main() {
	logger := slog.New(&actionslog.Wrapper{
		Handler: human.Handler{}.WithOutput
	})
	logger.Info("hello", slog.String("object", "world"))
}

Screenshots

This is what the output of ./internal/example looks like in the GitHub UI.

Run Log

run log

Workflow Summary

workflow summary

Inline Code Annotations

inline code annotations

About

License:MIT License


Languages

Language:Go 100.0%