slogan

module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2026 License: Apache-2.0

README

slogan

Documentation Release

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"
)

func main() {

	// 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)
	if err != nil {
		fmt.Print(err)
		return
	}
	// The handler should be closed to flush log records before the application exits.
	defer handler.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.

Directories

Path Synopsis
Package appinsights provides a slog Handler to submit log records to Application Insights.
Package appinsights provides a slog Handler to submit log records to Application Insights.
cmd
appinsights command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL