Fixed a missing Unlocked mutex
Random log updates
This commit is contained in:
parent
160d140cf6
commit
6eaba2a3d5
@ -57,15 +57,15 @@ func stringexists(needle string, haystack []string) bool {
|
||||
func getSettings() {
|
||||
c, err := ioutil.ReadFile("config.jsonc")
|
||||
if err != nil {
|
||||
logFatal.Fatal("Unable to open config.jsonc, exiting: ", err)
|
||||
logFatal("Unable to open config.jsonc, exiting: ", err)
|
||||
}
|
||||
jsoncbin := jsonc.ToJSON(c) // Calling jsonc.ToJSON() to convert JSONC to JSON
|
||||
if jsonc.Valid(jsoncbin) == false {
|
||||
logFatal.Fatal("Invalid jsonc, exiting.")
|
||||
logFatal("Invalid jsonc, exiting.")
|
||||
}
|
||||
|
||||
err = json.Unmarshal(jsoncbin, &settings)
|
||||
if err != nil {
|
||||
logFatal.Fatal("Unable to parse config.jsonc, exiting: ", err)
|
||||
logFatal("Unable to parse config.jsonc, exiting: ", err)
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
)
|
||||
|
||||
@ -13,7 +14,7 @@ func getDbPool() *pgxpool.Pool {
|
||||
dburl := os.Getenv("DATABASE_URL")
|
||||
pool, err := pgxpool.Connect(context.Background(), dburl)
|
||||
if err != nil {
|
||||
logFatal.Fatal("Unable to connect to database:", err)
|
||||
logFatal("Unable to connect to database:", err)
|
||||
}
|
||||
return pool
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ var ri_mutex = &sync.Mutex{}
|
||||
|
||||
func startpprof() {
|
||||
logInfo("Starting http/pprof on :7777")
|
||||
logFatal.Fatal(http.ListenAndServe("127.0.0.1:7777", nil))
|
||||
logFatal(http.ListenAndServe("127.0.0.1:7777", nil))
|
||||
}
|
||||
|
||||
func statusReportHandler() {
|
||||
|
@ -54,7 +54,7 @@ func BuildClient(endpoint string) http.Client {
|
||||
proxyuri := fmt.Sprintf("socks5://%s:%d", settings.Proxies[ridx].Host, settings.Proxies[ridx].Port)
|
||||
proxy, err := url.Parse(proxyuri)
|
||||
if err != nil {
|
||||
logFatal.Fatal("Error: ", err)
|
||||
logFatal("Error: ", err)
|
||||
}
|
||||
tr.Proxy = http.ProxyURL(proxy)
|
||||
}
|
||||
@ -175,7 +175,7 @@ func LogInstance(endpoint string, o shared.RunningInstance) bool {
|
||||
|
||||
_, err = pool.Exec(context.Background(), "INSERT INTO instances (endpoint, state, software) VALUES($1, $2, $3)", endpoint, "", o.Software)
|
||||
if err != nil {
|
||||
logWarn("Error inserting %s into `instances`: "+endpoint, err)
|
||||
logWarn("Error inserting ", endpoint+" into `instances`: ", err)
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -6,49 +6,53 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
_logInfo *log.Logger
|
||||
_logInfo *log.Logger
|
||||
_logErr *log.Logger
|
||||
_logWarn *log.Logger
|
||||
_logConn *log.Logger
|
||||
_logDebug *log.Logger
|
||||
logFatal *log.Logger
|
||||
_logFatal *log.Logger
|
||||
)
|
||||
|
||||
func logInit() {
|
||||
_logInfo = log.New(os.Stdout, "INFO: ", log.Lmsgprefix|log.Ldate|log.Ltime)
|
||||
_logErr = log.New(os.Stdout, "ERR: ", log.Lmsgprefix|log.Ldate|log.Ltime)
|
||||
_logWarn = log.New(os.Stdout, "WARN: ", log.Lmsgprefix|log.Ldate|log.Ltime)
|
||||
_logConn = log.New(os.Stdout, "CONN: ", log.Lmsgprefix|log.Ldate|log.Ltime)
|
||||
_logInfo = log.New(os.Stdout, "INFO: ", log.Lmsgprefix|log.Ldate|log.Ltime)
|
||||
_logErr = log.New(os.Stdout, "ERR: ", log.Lmsgprefix|log.Ldate|log.Ltime)
|
||||
_logWarn = log.New(os.Stdout, "WARN: ", log.Lmsgprefix|log.Ldate|log.Ltime)
|
||||
_logConn = log.New(os.Stdout, "CONN: ", log.Lmsgprefix|log.Ldate|log.Ltime)
|
||||
_logDebug = log.New(os.Stdout, "DEBUG: ", log.Lmsgprefix|log.Ldate|log.Ltime)
|
||||
logFatal = log.New(os.Stdout, "FATAL: ", log.Lmsgprefix|log.Ldate|log.Ltime)
|
||||
_logFatal = log.New(os.Stdout, "FATAL: ", log.Lmsgprefix|log.Ldate|log.Ltime)
|
||||
}
|
||||
|
||||
func logInfo(s ...interface{}) {
|
||||
if (settings.LogLevel >= 1) {
|
||||
if settings.LogLevel >= 1 {
|
||||
_logInfo.Print(s...)
|
||||
}
|
||||
}
|
||||
|
||||
func logErr(s ...interface{}) {
|
||||
if (settings.LogLevel >= 2) {
|
||||
if settings.LogLevel >= 2 {
|
||||
_logErr.Print(s...)
|
||||
}
|
||||
}
|
||||
|
||||
func logWarn(s ...interface{}) {
|
||||
if (settings.LogLevel >= 3) {
|
||||
if settings.LogLevel >= 3 {
|
||||
_logWarn.Print(s...)
|
||||
}
|
||||
}
|
||||
|
||||
func logConn(s ...interface{}) {
|
||||
if (settings.LogLevel >= 4) {
|
||||
if settings.LogLevel >= 4 {
|
||||
_logConn.Print(s...)
|
||||
}
|
||||
}
|
||||
|
||||
func logDebug(s ...interface{}) {
|
||||
if (settings.LogLevel >= 5) {
|
||||
_logConn.Print(s...)
|
||||
if settings.LogLevel >= 5 {
|
||||
_logDebug.Print(s...)
|
||||
}
|
||||
}
|
||||
|
||||
func logFatal(s ...interface{}) {
|
||||
_logFatal.Fatal(s...)
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ func PollMastodonPleroma(endpoint string, o *shared.RunningInstance) {
|
||||
req, err := http.NewRequest("GET", api_timeline, nil)
|
||||
req.Header.Set("User-Agent", "Tusky")
|
||||
if err != nil {
|
||||
logFatal.Fatal("Unable to create new request for "+endpoint+": ", err)
|
||||
logFatal("Unable to create new request for "+endpoint+": ", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -162,7 +162,7 @@ func check_activity(uri string) {
|
||||
}
|
||||
_, err = pool.Exec(context.Background(), "INSERT INTO activities (document, normalized, instance, hashtags, bot) VALUES($1, $2, $3, $4, $5)", jsondocument, activityjson.normalized, activityjson.instance, hashtags, activityjson.bot)
|
||||
if err != nil {
|
||||
logWarn("Error inserting %s into `activities`: "+uri, err)
|
||||
logWarn("Error inserting ", uri, " into `activities`: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -200,6 +200,7 @@ func check_actor(uri string) *ActorJson {
|
||||
o.Recentactors.Mu.Lock()
|
||||
i, cachedactorjson := o.Recentactors.Contains(uri)
|
||||
if i != -1 {
|
||||
o.Recentactors.Mu.Unlock()
|
||||
cachedactorjson := cachedactorjson.(*ActorJson)
|
||||
return cachedactorjson
|
||||
}
|
||||
@ -208,7 +209,6 @@ func check_actor(uri string) *ActorJson {
|
||||
selectRet := pool.QueryRow(context.Background(), "SELECT document FROM actors WHERE document->>'id' = $1", uri)
|
||||
err := selectRet.Scan(&actorjson)
|
||||
if err == nil {
|
||||
logWarn(actorjson)
|
||||
return actorjson // Actor already in database, good!
|
||||
}
|
||||
|
||||
@ -255,7 +255,7 @@ func check_actor(uri string) *ActorJson {
|
||||
|
||||
_, err = pool.Exec(context.Background(), "INSERT INTO actors (document, instance, bot) VALUES($1, $2, $3)", jsondocument, actorjson.instance, bot)
|
||||
if err != nil {
|
||||
logWarn("Error inserting %s into `actors`: "+uri, err)
|
||||
logWarn("Error inserting ", uri, " into `actors`: ", err)
|
||||
return nil // Unable to insert actor
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ func StreamMastodon(endpoint string, o *shared.RunningInstance) {
|
||||
req, err := http.NewRequest("GET", api_timeline, nil)
|
||||
req.Header.Set("User-Agent", "Tusky")
|
||||
if err != nil {
|
||||
logFatal.Fatal("Unable to create new request for " + endpoint + ", exiting.")
|
||||
logFatal("Unable to create new request for " + endpoint + ", exiting.")
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user