Skip to content

Commit

Permalink
fixed logs printer dev tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Feb 26, 2024
1 parent 53ee521 commit f1a6c19
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
- Updated the `cron.Start()` to start the ticker at the `00` second of the cron interval ([#4394](https://github.com/pocketbase/pocketbase/discussions/4394)).
_Note that the cron format has only minute granularity and there is still no guarantee that the sheduled job will be always executed at the `00` second._

- Fixed cron auto backups not taking in consideration the latest settings change ([#4431](https://github.com/pocketbase/pocketbase/discussions/4431)).

- Upgraded to `aws-sdk-go-v2` and added special handling for GCS to workaround the previous [GCS headers signature issue](https://github.com/pocketbase/pocketbase/issues/2231) that we had with v2.
_This should also fix the SVG/JSON zero response when using Cloudflare R2 ([#4287](https://github.com/pocketbase/pocketbase/issues/4287#issuecomment-1925168142), [#2068](https://github.com/pocketbase/pocketbase/discussions/2068), [#2952](https://github.com/pocketbase/pocketbase/discussions/2952))._
_If you are using S3 for uploaded files or backups, please verify that you have a green check in the Admin UI for your S3 configuration (I've tested the new version with GCS, MinIO, Cloudflare R2 and Wasabi)._
Expand Down
35 changes: 22 additions & 13 deletions core/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,10 +599,10 @@ func (app *BaseApp) RefreshSettings() error {
return err
}

// reload handler level (if initialized and not in dev mode)
if !app.IsDev() && app.Logger() != nil {
// reload handler level (if initialized)
if app.Logger() != nil {
if h, ok := app.Logger().Handler().(*logger.BatchHandler); ok {
h.SetLevel(slog.Level(app.settings.Logs.MinLevel))
h.SetLevel(app.getLoggerMinLevel())
}
}

Expand Down Expand Up @@ -1184,25 +1184,34 @@ func (app *BaseApp) registerDefaultHooks() {
}
}

func (app *BaseApp) initLogger() error {
duration := 3 * time.Second
ticker := time.NewTicker(duration)
done := make(chan bool)
// getLoggerMinLevel returns the logger min level based on the
// app configurations (dev mode, settings, etc.).

// Apply the min level only if it is not in develop
// to allow printing the logs to the console.
//
// DB logs are still filtered but the checks for the min level are done
// in the BatchOptions.BeforeAddFunc instead of the slog.Handler.Enabled() method.
// If not in dev mode - returns the level from the app settings.
//
// If the app is in dev mode it returns -9999 level allowing to print
// practically all logs to the terminal.
// In this case DB logs are still filtered but the checks for the min level are done
// in the BatchOptions.BeforeAddFunc instead of the slog.Handler.Enabled() method.
func (app *BaseApp) getLoggerMinLevel() slog.Level {
var minLevel slog.Level

if app.IsDev() {
minLevel = -9999
} else if app.Settings() != nil {
minLevel = slog.Level(app.Settings().Logs.MinLevel)
}

return minLevel
}

func (app *BaseApp) initLogger() error {
duration := 3 * time.Second
ticker := time.NewTicker(duration)
done := make(chan bool)

handler := logger.NewBatchHandler(logger.BatchOptions{
Level: minLevel,
Level: app.getLoggerMinLevel(),
BatchSize: 200,
BeforeAddFunc: func(ctx context.Context, log *logger.Log) bool {
if app.IsDev() {
Expand Down
7 changes: 6 additions & 1 deletion core/base_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,12 @@ func (app *BaseApp) initAutobackupHooks() error {
// make sure that app.Settings() is always up to date
//
// @todo remove with the refactoring as core.App and daos.Dao will be one.
app.RefreshSettings()
if err := app.RefreshSettings(); err != nil {
app.Logger().Debug(
"[Backup cron] Failed to get the latest app settings",
slog.String("error", err.Error()),
)
}

rawSchedule := app.Settings().Backups.Cron
if rawSchedule == "" || !isServe || !app.IsBootstrapped() {
Expand Down

0 comments on commit f1a6c19

Please sign in to comment.