Logger SDK Installation
Before you begin
You'll need:
- A ByteHide account and project token
- Go 1.19 or higher
- Go modules enabled in your project
Installation
Add the ByteHide Logger SDK to your Go project using go get:
Bash
go get github.com/bytehide/bytehide-logs-gogo get github.com/bytehide/bytehide-logs-goThis command will download the latest version of the SDK and update your go.mod file.
Verify Installation
Check that the dependency was added to your go.mod:
Bash
cat go.mod | grep bytehide-logs-gocat go.mod | grep bytehide-logs-goYou should see output similar to:
CODE
require github.com/bytehide/bytehide-logs-go v1.0.0require github.com/bytehide/bytehide-logs-go v1.0.0Basic Integration Example
Go
package main
import (
"fmt"
logs "github.com/bytehide/bytehide-logs-go"
)
func main() {
// Set your project token
logs.SetProjectToken("your-project-token")
// Enable console output
logs.SetConsoleEnabled(true)
// Start logging
logs.Info("Application started successfully!")
}package main
import (
"fmt"
logs "github.com/bytehide/bytehide-logs-go"
)
func main() {
// Set your project token
logs.SetProjectToken("your-project-token")
// Enable console output
logs.SetConsoleEnabled(true)
// Start logging
logs.Info("Application started successfully!")
}Verify Installation
After installing the SDK, you can verify it's working by running a simple test:
Go
package main
import (
"fmt"
logs "github.com/bytehide/bytehide-logs-go"
)
func main() {
// Configure the logger
logs.SetProjectToken("your-project-token")
logs.SetConsoleEnabled(true)
logs.SetMinimumLevel(logs.LogLevelDebug)
// Test logging
logs.Info("ByteHide Logger initialized successfully!")
logs.Debug("Debug message - visible with debug level")
logs.Warn("Warning message")
logs.Error("Error message for testing", nil)
fmt.Println("Logger is working correctly!")
}package main
import (
"fmt"
logs "github.com/bytehide/bytehide-logs-go"
)
func main() {
// Configure the logger
logs.SetProjectToken("your-project-token")
logs.SetConsoleEnabled(true)
logs.SetMinimumLevel(logs.LogLevelDebug)
// Test logging
logs.Info("ByteHide Logger initialized successfully!")
logs.Debug("Debug message - visible with debug level")
logs.Warn("Warning message")
logs.Error("Error message for testing", nil)
fmt.Println("Logger is working correctly!")
}To run this test:
Bash
go run main.gogo run main.goYou should see output in your console confirming the logger is working.
Go Version Compatibility
ByteHide Logger requires Go 1.19 or higher. This ensures compatibility with:
- Go 1.19+: Full logging capabilities including file persistence
- Standard library: Uses only Go standard library dependencies
- Modules: Compatible with Go modules for dependency management
Check Your Go Version
Bash
go versiongo versionIf you have an older version of Go, update it:
Bash
# macOS with Homebrew
brew upgrade go
# Or download from golang.org
# https://golang.org/dl/# macOS with Homebrew
brew upgrade go
# Or download from golang.org
# https://golang.org/dl/Environment Variables
The SDK can automatically load your project token from environment variables:
Bash
export BYTEHIDE_LOGS_TOKEN=your-project-token
# or
export BYTEHIDE_PROJECT_TOKEN=your-project-token
# or
export PROJECT_TOKEN=your-project-tokenexport BYTEHIDE_LOGS_TOKEN=your-project-token
# or
export BYTEHIDE_PROJECT_TOKEN=your-project-token
# or
export PROJECT_TOKEN=your-project-tokenIn your code:
Go
logs.SetProject() // Automatically loads from environment variablelogs.SetProject() // Automatically loads from environment variableImport Statement
Use this import statement in your Go files:
Go
import logs "github.com/bytehide/bytehide-logs-go"import logs "github.com/bytehide/bytehide-logs-go"Then use the package-level functions:
Go
logs.Info("message")
logs.Debug()
logs.Warn()
logs.Error("message", err)
logs.Critical()logs.Info("message")
logs.Debug()
logs.Warn()
logs.Error("message", err)
logs.Critical()