logger

package
v0.1.0-beta.4 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package logger provides comprehensive logging capabilities for the AhaSend CLI.

This package implements multi-level logging with security-aware features:

  • Structured logging using logrus with JSON formatting
  • HTTP transport logging for API debugging (request/response details)
  • Security-aware log sanitization (API keys and sensitive headers redacted)
  • Two-level logging: --verbose (API summaries) and --debug (full details)
  • Configuration operation logging for troubleshooting
  • Performance monitoring with request timing and metrics
  • Color-coded output with --no-color flag support

The logger automatically detects and redacts sensitive information while providing comprehensive debugging information for development and support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APICall

func APICall(method, endpoint string, duration time.Duration)

func APIError

func APIError(method, endpoint string, statusCode int, err error, duration time.Duration)

func ConfigOperation

func ConfigOperation(operation, profile string, details map[string]interface{})

func Debug

func Debug(args ...interface{})

Global convenience functions

func Error

func Error(args ...interface{})

func HTTPRequest

func HTTPRequest(method, url string, headers http.Header, body interface{})

func HTTPResponse

func HTTPResponse(statusCode int, status string, headers http.Header, body interface{}, duration time.Duration)

func Info

func Info(args ...interface{})

func Initialize

func Initialize(cmd *cobra.Command)

Initialize sets up the global logger based on CLI flags

func RateLimitHit

func RateLimitHit(waitTime time.Duration)

func RetryAttempt

func RetryAttempt(attempt int, maxAttempts int, err error, delay time.Duration)

func Warn

func Warn(args ...interface{})

Types

type HTTPTransport

type HTTPTransport struct {
	// contains filtered or unexported fields
}

HTTPTransport is a custom RoundTripper that logs HTTP requests and responses

func NewHTTPTransport

func NewHTTPTransport(transport http.RoundTripper, logger *Logger) *HTTPTransport

NewHTTPTransport creates a new HTTP transport with logging

func (*HTTPTransport) RoundTrip

func (t *HTTPTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface

type Logger

type Logger struct {
	*logrus.Logger
	// contains filtered or unexported fields
}

Logger wraps logrus with CLI-specific functionality

func Get

func Get() *Logger

Get returns the global logger instance

func NewLogger

func NewLogger(debugMode, verboseMode, noColor bool) *Logger

NewLogger creates a new logger instance

func NewLoggerWithFormat

func NewLoggerWithFormat(debugMode, verboseMode, noColor, isJSONMode bool) *Logger

NewLoggerWithFormat creates a new logger instance with JSON mode awareness

func (*Logger) APICall

func (l *Logger) APICall(method, endpoint string, duration time.Duration)

APICall logs API call details at info level (for verbose mode)

func (*Logger) APIError

func (l *Logger) APIError(method, endpoint string, statusCode int, err error, duration time.Duration)

APIError logs API errors

func (*Logger) ConfigOperation

func (l *Logger) ConfigOperation(operation, profile string, details map[string]interface{})

ConfigOperation logs configuration operations

func (*Logger) HTTPRequest

func (l *Logger) HTTPRequest(method, url string, headers http.Header, body interface{})

HTTPRequest logs HTTP request details

func (*Logger) HTTPResponse

func (l *Logger) HTTPResponse(statusCode int, status string, headers http.Header, body interface{}, duration time.Duration)

HTTPResponse logs HTTP response details

func (*Logger) IsDebugEnabled

func (l *Logger) IsDebugEnabled() bool

IsDebugEnabled returns true if debug mode is enabled

func (*Logger) IsVerboseEnabled

func (l *Logger) IsVerboseEnabled() bool

IsVerboseEnabled returns true if verbose mode is enabled

func (*Logger) RateLimitHit

func (l *Logger) RateLimitHit(waitTime time.Duration)

RateLimitHit logs when rate limiting is applied

func (*Logger) RetryAttempt

func (l *Logger) RetryAttempt(attempt int, maxAttempts int, err error, delay time.Duration)

RetryAttempt logs retry attempts

Jump to

Keyboard shortcuts

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