mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Added an option to specify metrics log file
Previously the metrics log file was hardcoded and the broker wasn't behaving properly if it was unable to open the file for logging. Added a commandline option to specify the logfile that defaults to Stdout. Fixed up some documentation and log output formatting
This commit is contained in:
parent
72e54bdc2e
commit
ba4fe1a73e
3 changed files with 26 additions and 19 deletions
|
@ -5,7 +5,6 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
@ -28,7 +27,7 @@ type Metrics struct {
|
|||
}
|
||||
|
||||
func (s CountryStats) Display() string {
|
||||
return fmt.Sprintln(s.counts)
|
||||
return fmt.Sprint(s.counts)
|
||||
}
|
||||
|
||||
func (m *Metrics) UpdateCountryStats(addr string) {
|
||||
|
@ -56,9 +55,7 @@ func (m *Metrics) UpdateCountryStats(addr string) {
|
|||
}
|
||||
|
||||
//update map of countries and counts
|
||||
if country != "" {
|
||||
m.countryStats.counts[country]++
|
||||
}
|
||||
m.countryStats.counts[country]++
|
||||
|
||||
return
|
||||
}
|
||||
|
@ -88,17 +85,9 @@ func (m *Metrics) LoadGeoipDatabases(geoipDB string, geoip6DB string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func NewMetrics() (*Metrics, error) {
|
||||
func NewMetrics(metricsLogger *log.Logger) (*Metrics, error) {
|
||||
m := new(Metrics)
|
||||
|
||||
f, err := os.OpenFile("metrics.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
metricsLogger := log.New(f, "", log.LstdFlags|log.LUTC)
|
||||
|
||||
m.countryStats = CountryStats{
|
||||
counts: make(map[string]int),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue