mirror of
https://github.com/jc21/nginx-proxy-manager.git
synced 2024-08-30 18:22:48 +00:00
Remove sentry and error reporting
This commit is contained in:
parent
6d6021c9bb
commit
fd7095ad88
@ -16,7 +16,6 @@ import (
|
|||||||
|
|
||||||
var commit string
|
var commit string
|
||||||
var version string
|
var version string
|
||||||
var sentryDSN string
|
|
||||||
|
|
||||||
var cloudfrontURL = "https://ip-ranges.amazonaws.com/ip-ranges.json"
|
var cloudfrontURL = "https://ip-ranges.amazonaws.com/ip-ranges.json"
|
||||||
var cloudflare4URL = "https://www.cloudflare.com/ips-v4"
|
var cloudflare4URL = "https://www.cloudflare.com/ips-v4"
|
||||||
@ -24,7 +23,7 @@ var cloudflare6URL = "https://www.cloudflare.com/ips-v6"
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
config.InitArgs(&version, &commit)
|
config.InitArgs(&version, &commit)
|
||||||
if err := config.InitIPRanges(&version, &commit, &sentryDSN); err != nil {
|
if err := config.InitIPRanges(&version, &commit); err != nil {
|
||||||
fmt.Printf("# Config ERROR: %v\n", err)
|
fmt.Printf("# Config ERROR: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"npm/internal/database"
|
"npm/internal/database"
|
||||||
"npm/internal/entity/certificate"
|
"npm/internal/entity/certificate"
|
||||||
"npm/internal/entity/host"
|
"npm/internal/entity/host"
|
||||||
"npm/internal/entity/setting"
|
|
||||||
"npm/internal/entity/user"
|
"npm/internal/entity/user"
|
||||||
"npm/internal/errors"
|
"npm/internal/errors"
|
||||||
"npm/internal/jobqueue"
|
"npm/internal/jobqueue"
|
||||||
@ -20,11 +19,10 @@ import (
|
|||||||
|
|
||||||
var commit string
|
var commit string
|
||||||
var version string
|
var version string
|
||||||
var sentryDSN string
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
config.InitArgs(&version, &commit)
|
config.InitArgs(&version, &commit)
|
||||||
config.Init(&version, &commit, &sentryDSN)
|
config.Init(&version, &commit)
|
||||||
|
|
||||||
database.Migrate(func() {
|
database.Migrate(func() {
|
||||||
if err := jwt.LoadKeys(); err != nil {
|
if err := jwt.LoadKeys(); err != nil {
|
||||||
@ -32,7 +30,6 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
setting.ApplySettings()
|
|
||||||
checkSetup()
|
checkSetup()
|
||||||
|
|
||||||
// Internal Job Queue
|
// Internal Job Queue
|
||||||
@ -79,9 +76,6 @@ func checkSetup() {
|
|||||||
config.IsSetup = true
|
config.IsSetup = true
|
||||||
logger.Info("Application is setup")
|
logger.Info("Application is setup")
|
||||||
}
|
}
|
||||||
if config.ErrorReporting {
|
|
||||||
logger.Warn("Error reporting is enabled - Application Errors WILL be sent to Sentry, you can disable this in the Settings interface")
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
logger.Error("DatabaseError", errors.ErrDatabaseUnavailable)
|
logger.Error("DatabaseError", errors.ErrDatabaseUnavailable)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "HealthObject",
|
"description": "HealthObject",
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"required": ["version", "commit", "healthy", "setup", "error_reporting"],
|
"required": ["version", "commit", "healthy", "setup"],
|
||||||
"properties": {
|
"properties": {
|
||||||
"version": {
|
"version": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@ -22,10 +22,6 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"description": "Is the application set up?"
|
"description": "Is the application set up?"
|
||||||
},
|
},
|
||||||
"error_reporting": {
|
|
||||||
"type": "boolean",
|
|
||||||
"description": "Will the application send any error reporting?"
|
|
||||||
},
|
|
||||||
"acme.sh": {
|
"acme.sh": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Acme.sh version",
|
"description": "Acme.sh version",
|
||||||
|
@ -22,8 +22,7 @@
|
|||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"commit": "9f119b6",
|
"commit": "9f119b6",
|
||||||
"healthy": true,
|
"healthy": true,
|
||||||
"setup": true,
|
"setup": true
|
||||||
"error_reporting": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -33,8 +32,7 @@
|
|||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"commit": "9f119b6",
|
"commit": "9f119b6",
|
||||||
"healthy": false,
|
"healthy": false,
|
||||||
"setup": true,
|
"setup": true
|
||||||
"error_reporting": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,14 +30,6 @@ INSERT INTO `setting` (
|
|||||||
`description`,
|
`description`,
|
||||||
`value`
|
`value`
|
||||||
) VALUES
|
) VALUES
|
||||||
-- Default error reporting setting
|
|
||||||
(
|
|
||||||
ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000),
|
|
||||||
ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000),
|
|
||||||
"error-reporting",
|
|
||||||
"If enabled, any application errors are reported to Sentry. Sensitive information is not sent.",
|
|
||||||
"true" -- remember this is json
|
|
||||||
),
|
|
||||||
-- Default site
|
-- Default site
|
||||||
(
|
(
|
||||||
ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000),
|
ROUND(UNIX_TIMESTAMP(CURTIME(4)) * 1000),
|
||||||
|
@ -30,14 +30,6 @@ INSERT INTO "setting" (
|
|||||||
"description",
|
"description",
|
||||||
"value"
|
"value"
|
||||||
) VALUES
|
) VALUES
|
||||||
-- Default error reporting setting
|
|
||||||
(
|
|
||||||
EXTRACT(EPOCH FROM TIMESTAMP '2011-05-17 10:40:28.876944') * 1000,
|
|
||||||
EXTRACT(EPOCH FROM TIMESTAMP '2011-05-17 10:40:28.876944') * 1000,
|
|
||||||
'error-reporting',
|
|
||||||
'If enabled, any application errors are reported to Sentry. Sensitive information is not sent.',
|
|
||||||
'true' -- remember this is json
|
|
||||||
),
|
|
||||||
-- Default site
|
-- Default site
|
||||||
(
|
(
|
||||||
EXTRACT(EPOCH FROM TIMESTAMP '2011-05-17 10:40:28.876944') * 1000,
|
EXTRACT(EPOCH FROM TIMESTAMP '2011-05-17 10:40:28.876944') * 1000,
|
||||||
|
@ -23,21 +23,6 @@ INSERT INTO `capability` (
|
|||||||
("streams.manage"),
|
("streams.manage"),
|
||||||
("users.manage");
|
("users.manage");
|
||||||
|
|
||||||
-- Default error reporting setting
|
|
||||||
INSERT INTO `setting` (
|
|
||||||
created_at,
|
|
||||||
updated_at,
|
|
||||||
name,
|
|
||||||
description,
|
|
||||||
value
|
|
||||||
) VALUES (
|
|
||||||
unixepoch() * 1000,
|
|
||||||
unixepoch() * 1000,
|
|
||||||
"error-reporting",
|
|
||||||
"If enabled, any application errors are reported to Sentry. Sensitive information is not sent.",
|
|
||||||
"true" -- remember this is json
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Default site
|
-- Default site
|
||||||
INSERT INTO `setting` (
|
INSERT INTO `setting` (
|
||||||
created_at,
|
created_at,
|
||||||
|
@ -9,7 +9,6 @@ require (
|
|||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||||
github.com/drexedam/gravatar v0.0.0-20210327211422-e94eea8c338e
|
github.com/drexedam/gravatar v0.0.0-20210327211422-e94eea8c338e
|
||||||
github.com/fatih/color v1.15.0
|
github.com/fatih/color v1.15.0
|
||||||
github.com/getsentry/sentry-go v0.21.0
|
|
||||||
github.com/glebarez/sqlite v1.8.0
|
github.com/glebarez/sqlite v1.8.0
|
||||||
github.com/go-chi/chi/v5 v5.0.8
|
github.com/go-chi/chi/v5 v5.0.8
|
||||||
github.com/go-chi/cors v1.2.1
|
github.com/go-chi/cors v1.2.1
|
||||||
|
@ -20,8 +20,6 @@ github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkp
|
|||||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||||
github.com/getsentry/sentry-go v0.21.0 h1:c9l5F1nPF30JIppulk4veau90PK6Smu3abgVtVQWon4=
|
|
||||||
github.com/getsentry/sentry-go v0.21.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
|
|
||||||
github.com/glebarez/go-sqlite v1.21.1 h1:7MZyUPh2XTrHS7xNEHQbrhfMZuPSzhkm2A1qgg0y5NY=
|
github.com/glebarez/go-sqlite v1.21.1 h1:7MZyUPh2XTrHS7xNEHQbrhfMZuPSzhkm2A1qgg0y5NY=
|
||||||
github.com/glebarez/go-sqlite v1.21.1/go.mod h1:ISs8MF6yk5cL4n/43rSOmVMGJJjHYr7L2MbZZ5Q4E2E=
|
github.com/glebarez/go-sqlite v1.21.1/go.mod h1:ISs8MF6yk5cL4n/43rSOmVMGJJjHYr7L2MbZZ5Q4E2E=
|
||||||
github.com/glebarez/sqlite v1.8.0 h1:02X12E2I/4C1n+v90yTqrjRa8yuo7c3KeHI3FRznCvc=
|
github.com/glebarez/sqlite v1.8.0 h1:02X12E2I/4C1n+v90yTqrjRa8yuo7c3KeHI3FRznCvc=
|
||||||
@ -32,7 +30,6 @@ github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
|
|||||||
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
|
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
|
||||||
github.com/go-chi/jwtauth/v5 v5.1.0 h1:wJyf2YZ/ohPvNJBwPOzZaQbyzwgMZZceE1m8FOzXLeA=
|
github.com/go-chi/jwtauth/v5 v5.1.0 h1:wJyf2YZ/ohPvNJBwPOzZaQbyzwgMZZceE1m8FOzXLeA=
|
||||||
github.com/go-chi/jwtauth/v5 v5.1.0/go.mod h1:MA93hc1au3tAQwCKry+fI4LqJ5MIVN4XSsglOo+lSc8=
|
github.com/go-chi/jwtauth/v5 v5.1.0/go.mod h1:MA93hc1au3tAQwCKry+fI4LqJ5MIVN4XSsglOo+lSc8=
|
||||||
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
|
||||||
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||||
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
|
||||||
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
|
||||||
@ -108,7 +105,6 @@ github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7P
|
|||||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
||||||
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
|
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
@ -8,12 +8,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type healthCheckResponse struct {
|
type healthCheckResponse struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
Commit string `json:"commit"`
|
Commit string `json:"commit"`
|
||||||
AcmeShVersion string `json:"acme.sh"`
|
AcmeShVersion string `json:"acme.sh"`
|
||||||
Healthy bool `json:"healthy"`
|
Healthy bool `json:"healthy"`
|
||||||
IsSetup bool `json:"setup"`
|
IsSetup bool `json:"setup"`
|
||||||
ErrorReporting bool `json:"error_reporting"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Health returns the health of the api
|
// Health returns the health of the api
|
||||||
@ -21,12 +20,11 @@ type healthCheckResponse struct {
|
|||||||
func Health() func(http.ResponseWriter, *http.Request) {
|
func Health() func(http.ResponseWriter, *http.Request) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
health := healthCheckResponse{
|
health := healthCheckResponse{
|
||||||
Version: config.Version,
|
Version: config.Version,
|
||||||
Commit: config.Commit,
|
Commit: config.Commit,
|
||||||
Healthy: true,
|
Healthy: true,
|
||||||
IsSetup: config.IsSetup,
|
IsSetup: config.IsSetup,
|
||||||
AcmeShVersion: acme.GetAcmeShVersion(),
|
AcmeShVersion: acme.GetAcmeShVersion(),
|
||||||
ErrorReporting: config.ErrorReporting,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h.ResultResponseJSON(w, r, http.StatusOK, health)
|
h.ResultResponseJSON(w, r, http.StatusOK, health)
|
||||||
|
@ -12,15 +12,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
r = NewRouter()
|
r = NewRouter()
|
||||||
version = "3.0.0"
|
version = "3.0.0"
|
||||||
commit = "abcdefgh"
|
commit = "abcdefgh"
|
||||||
sentryDSN = ""
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tear up/down
|
// Tear up/down
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
config.Init(&version, &commit, &sentryDSN)
|
config.Init(&version, &commit)
|
||||||
code := m.Run()
|
code := m.Run()
|
||||||
os.Exit(code)
|
os.Exit(code)
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,14 @@ package config
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
golog "log"
|
golog "log"
|
||||||
"runtime"
|
|
||||||
|
|
||||||
"npm/internal/logger"
|
"npm/internal/logger"
|
||||||
|
|
||||||
"github.com/getsentry/sentry-go"
|
|
||||||
"github.com/vrischmann/envconfig"
|
"github.com/vrischmann/envconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Init will parse environment variables into the Env struct
|
// Init will parse environment variables into the Env struct
|
||||||
func Init(version, commit, sentryDSN *string) {
|
func Init(version, commit *string) {
|
||||||
// ErrorReporting is enabled until we load the status of it from the DB later
|
|
||||||
ErrorReporting = true
|
|
||||||
|
|
||||||
Version = *version
|
Version = *version
|
||||||
Commit = *commit
|
Commit = *commit
|
||||||
|
|
||||||
@ -23,23 +18,22 @@ func Init(version, commit, sentryDSN *string) {
|
|||||||
fmt.Printf("%+v\n", err)
|
fmt.Printf("%+v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
initLogger(*sentryDSN)
|
initLogger()
|
||||||
logger.Info("Build Version: %s (%s)", Version, Commit)
|
logger.Info("Build Version: %s (%s)", Version, Commit)
|
||||||
createDataFolders()
|
createDataFolders()
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitIPRanges will initialise the config for the ipranges command
|
// InitIPRanges will initialise the config for the ipranges command
|
||||||
func InitIPRanges(version, commit, sentryDSN *string) error {
|
func InitIPRanges(version, commit *string) error {
|
||||||
ErrorReporting = true
|
|
||||||
Version = *version
|
Version = *version
|
||||||
Commit = *commit
|
Commit = *commit
|
||||||
err := envconfig.InitWithPrefix(&Configuration, "NPM")
|
err := envconfig.InitWithPrefix(&Configuration, "NPM")
|
||||||
initLogger(*sentryDSN)
|
initLogger()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init initialises the Log object and return it
|
// Init initialises the Log object and return it
|
||||||
func initLogger(sentryDSN string) {
|
func initLogger() {
|
||||||
// this removes timestamp prefixes from logs
|
// this removes timestamp prefixes from logs
|
||||||
golog.SetFlags(0)
|
golog.SetFlags(0)
|
||||||
|
|
||||||
@ -57,16 +51,6 @@ func initLogger(sentryDSN string) {
|
|||||||
err := logger.Configure(&logger.Config{
|
err := logger.Configure(&logger.Config{
|
||||||
LogThreshold: logLevel,
|
LogThreshold: logLevel,
|
||||||
Formatter: Configuration.Log.Format,
|
Formatter: Configuration.Log.Format,
|
||||||
SentryConfig: sentry.ClientOptions{
|
|
||||||
// This is the jc21 NginxProxyManager Sentry project,
|
|
||||||
// errors will be reported here (if error reporting is enable)
|
|
||||||
// and this project is private. No personal information should
|
|
||||||
// be sent in any error messages, only stacktraces.
|
|
||||||
Dsn: sentryDSN,
|
|
||||||
Release: Commit,
|
|
||||||
Dist: Version,
|
|
||||||
Environment: fmt.Sprintf("%s-%s", runtime.GOOS, runtime.GOARCH),
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -13,9 +13,6 @@ var Commit string
|
|||||||
// IsSetup defines whether we have an admin user or not
|
// IsSetup defines whether we have an admin user or not
|
||||||
var IsSetup bool
|
var IsSetup bool
|
||||||
|
|
||||||
// ErrorReporting defines whether we will send errors to Sentry
|
|
||||||
var ErrorReporting bool
|
|
||||||
|
|
||||||
var logLevel logger.Level
|
var logLevel logger.Level
|
||||||
|
|
||||||
type log struct {
|
type log struct {
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package setting
|
package setting
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"npm/internal/config"
|
|
||||||
"npm/internal/entity"
|
"npm/internal/entity"
|
||||||
"npm/internal/logger"
|
|
||||||
"npm/internal/model"
|
"npm/internal/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -55,16 +53,3 @@ func List(pageInfo model.PageInfo, filters []model.Filter) (entity.ListResponse,
|
|||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplySettings will load settings from the DB and apply them where required
|
|
||||||
func ApplySettings() {
|
|
||||||
logger.Debug("Applying Settings")
|
|
||||||
|
|
||||||
// Error-reporting
|
|
||||||
m, err := GetByName("error-reporting")
|
|
||||||
if err != nil {
|
|
||||||
logger.Error("ApplySettingsError", err)
|
|
||||||
} else {
|
|
||||||
config.ErrorReporting = m.Value.String() == "true"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -45,6 +45,6 @@ func (m *Model) Save() error {
|
|||||||
if result := db.Save(m); result.Error != nil {
|
if result := db.Save(m); result.Error != nil {
|
||||||
return result.Error
|
return result.Error
|
||||||
}
|
}
|
||||||
ApplySettings()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package logger
|
package logger
|
||||||
|
|
||||||
import "github.com/getsentry/sentry-go"
|
|
||||||
|
|
||||||
// Level type
|
// Level type
|
||||||
type Level int
|
type Level int
|
||||||
|
|
||||||
@ -21,7 +19,6 @@ const (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
LogThreshold Level
|
LogThreshold Level
|
||||||
Formatter string
|
Formatter string
|
||||||
SentryConfig sentry.ClientOptions
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Interface for a logger
|
// Interface for a logger
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/getsentry/sentry-go"
|
|
||||||
"github.com/rotisserie/eris"
|
"github.com/rotisserie/eris"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -113,13 +112,6 @@ func (l *Logger) Configure(c *Config) error {
|
|||||||
|
|
||||||
l.LogThreshold = c.LogThreshold
|
l.LogThreshold = c.LogThreshold
|
||||||
l.Formatter = c.Formatter
|
l.Formatter = c.Formatter
|
||||||
l.SentryConfig = c.SentryConfig
|
|
||||||
|
|
||||||
if c.SentryConfig.Dsn != "" {
|
|
||||||
if sentryErr := sentry.Init(c.SentryConfig); sentryErr != nil {
|
|
||||||
fmt.Printf("Sentry initialization failed: %v\n", sentryErr)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stdlog.SetFlags(0) // this removes timestamp prefixes from logs
|
stdlog.SetFlags(0) // this removes timestamp prefixes from logs
|
||||||
return nil
|
return nil
|
||||||
@ -228,21 +220,4 @@ func (l *Logger) Warn(format string, args ...interface{}) {
|
|||||||
// Attempts to log to bugsang.
|
// Attempts to log to bugsang.
|
||||||
func (l *Logger) Error(errorClass string, err error) {
|
func (l *Logger) Error(errorClass string, err error) {
|
||||||
l.logLevel(ErrorLevel, err.Error(), errorClass)
|
l.logLevel(ErrorLevel, err.Error(), errorClass)
|
||||||
l.notifySentry(errorClass, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *Logger) notifySentry(errorClass string, err error) {
|
|
||||||
if l.SentryConfig.Dsn != "" && l.SentryConfig.Dsn != "-" {
|
|
||||||
|
|
||||||
sentry.ConfigureScope(func(scope *sentry.Scope) {
|
|
||||||
scope.SetLevel(sentry.LevelError)
|
|
||||||
scope.SetTag("service", "backend")
|
|
||||||
scope.SetTag("error_class", errorClass)
|
|
||||||
})
|
|
||||||
|
|
||||||
sentry.CaptureException(err)
|
|
||||||
// Since sentry emits events in the background we need to make sure
|
|
||||||
// they are sent before we shut down
|
|
||||||
sentry.Flush(time.Second * 5)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/getsentry/sentry-go"
|
|
||||||
"github.com/rotisserie/eris"
|
"github.com/rotisserie/eris"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
@ -115,7 +114,6 @@ func TestConfigure(t *testing.T) {
|
|||||||
args: args{
|
args: args{
|
||||||
&Config{
|
&Config{
|
||||||
LogThreshold: InfoLevel,
|
LogThreshold: InfoLevel,
|
||||||
SentryConfig: sentry.ClientOptions{},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@ -123,9 +121,7 @@ func TestConfigure(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "invalid log level",
|
name: "invalid log level",
|
||||||
args: args{
|
args: args{
|
||||||
&Config{
|
&Config{},
|
||||||
SentryConfig: sentry.ClientOptions{},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user