Files
insights-go/logger.go
T
zeekay b4e1366340 rebrand: export Insights types instead of PostHog
Rename Go package from posthog to insights across all 80+ files.
Consumers now import as `insights "github.com/hanzoai/insights-go"`
and use insights.Client, insights.Config, insights.Capture, etc.

- Rename posthog.go -> insights.go, posthog_test.go -> insights_test.go
- Update package declaration from posthog to insights in all .go files
- Update SDKName from posthog-go to insights-go
- Update DefaultEndpoint from app.posthog.com to insights.hanzo.ai
- Update all FieldError/ConfigError type strings
- Update User-Agent headers, log prefixes, comments, and docs
- Update JSON test fixtures to match new SDK name
- Update CLI, examples, extras, and sdk_compliance_adapter
- Fix pre-existing go vet warnings (non-constant format strings)
2026-03-13 19:54:58 -07:00

67 lines
2.0 KiB
Go

package insights
import (
"log"
"os"
)
// Logger defines an interface for a logger used by the Insights client.
type Logger interface {
// Debugf is called by the Insights client to log debug messages about the
// operations it performs. Messages logged by this method are usually
// tagged with a `DEBUG` log level in common logging libraries.
Debugf(format string, args ...interface{})
// Logf is called by the Insights client to log regular messages about the
// operations it performs. Messages logged by this method are usually
// tagged with an `INFO` log level in common logging libraries.
Logf(format string, args ...interface{})
// Warnf is called by the Insights client to log warning messages about
// the operations it performs. Messages logged by this method are usually
// tagged with a `WARN` log level in common logging libraries.
Warnf(format string, args ...interface{})
// Errorf is called by the Insights client to log errors encountered
// while sending events to the backend servers.
// Messages logged by this method are usually tagged with an `ERROR` log
// level in common logging libraries.
Errorf(format string, args ...interface{})
}
// StdLogger creates an object that satisfies the insights.Logger
// interface and sends logs to the standard logger passed as argument.
func StdLogger(logger *log.Logger, verbose bool) Logger {
return stdLogger{
logger: logger,
verbose: verbose,
}
}
type stdLogger struct {
logger *log.Logger
verbose bool
}
func (l stdLogger) Debugf(format string, args ...interface{}) {
if l.verbose {
l.logger.Printf("DEBUG: "+format, args...)
}
}
func (l stdLogger) Logf(format string, args ...interface{}) {
l.logger.Printf("INFO: "+format, args...)
}
func (l stdLogger) Warnf(format string, args ...interface{}) {
l.logger.Printf("WARN: "+format, args...)
}
func (l stdLogger) Errorf(format string, args ...interface{}) {
l.logger.Printf("ERROR: "+format, args...)
}
func newDefaultLogger(verbose bool) Logger {
return StdLogger(log.New(os.Stderr, "insights ", log.LstdFlags), verbose)
}