Skip to content

Repository files navigation

slogan

DocumentationRelease

slogan is a Go module that provides a slog Handler implementation for submitting log records to Azure Application Insights.

Prerequisites

This module requires Go version 1.23 or higher.

Getting Started

Install this module using the following command.

go get github.com/openclosed-dev/slogan

Usage

The code below shows how to use the handler in appinsights package.

import (
"fmt""log/slog""os""github.com/openclosed-dev/slogan/appinsights"
)
funcmain() {
// The connection string provided by your Application Insights resource.connectionString:=os.Getenv("APPLICATIONINSIGHTS_CONNECTION_STRING")
// Creates a handler for Application Insights using the default options.handler, err:=appinsights.NewHandler(connectionString, nil)
iferr!=nil {
fmt.Print(err)
return
}
// The handler should be closed to flush log records before the application exits.deferhandler.Close()
// Creates a slog.Logger with the handler.logger:=slog.New(handler)
// Makes the logger as the system-wide default if you prefer.slog.SetDefault(logger)
slog.Info("hello", "count", 3)
}

CLI

A command line program appinsights is available for sending the lines you type to Azure Application Insights. The following command will install the program.

go install github.com/openclosed-dev/slogan/cmd/appinsights

Before invoking the command, you must define your Application Insights connection string in the environment variable APPLICATIONINSIGHTS_CONNECTION_STRING

Known Issue

This module depends on the module github.com/microsoft/ApplicationInsights-Go developed by Microsoft, that is not actively maintained for several years. While there seems to be no functional problem in the module, we need to constantly check the status of the project.

About

slogan is a slog Handler for submitting log records to Azure Application Insights

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages