logs refactoring

This commit is contained in:
Gani Georgiev
2023-11-26 13:33:17 +02:00
parent ff5535f4de
commit 821aae4a62
109 changed files with 7320 additions and 3728 deletions
+8 -3
View File
@@ -12,7 +12,7 @@ import (
"errors"
"fmt"
"io"
"log"
"log/slog"
"net/http"
"os"
"path/filepath"
@@ -221,8 +221,13 @@ func (p *plugin) update(withBackup bool) error {
}
tryToRevertExecChanges := func() {
if revertErr := os.Rename(renamedOldExec, oldExec); revertErr != nil && p.app.IsDebug() {
log.Println(revertErr)
if revertErr := os.Rename(renamedOldExec, oldExec); revertErr != nil {
p.app.Logger().Debug(
"Failed to revert executable",
slog.String("old", renamedOldExec),
slog.String("new", oldExec),
slog.String("error", revertErr.Error()),
)
}
}
+7 -3
View File
@@ -5,8 +5,8 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log/slog"
"net/http"
"os"
"os/exec"
@@ -120,8 +120,12 @@ func cronBinds(app core.App, loader *goja.Runtime, executors *vmsPool) {
return err
})
if err != nil && app.IsDebug() {
fmt.Println("[cronAdd] failed to execute cron job " + jobId + ": " + err.Error())
if err != nil {
app.Logger().Debug(
"[cronAdd] failed to execute cron job",
slog.String("jobId", jobId),
slog.String("error", err.Error()),
)
}
})
if err != nil {
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -429,7 +429,7 @@ declare class DateTime implements types.DateTime {
interface ValidationError extends ozzo_validation.Error{} // merge
/**
* ValidationError defines a single formatted data validation error,
* usually used as part of a error response.
* usually used as part of an error response.
*
* ` + "```" + `js
* new ValidationError("invalid_title", "Title is not valid")
+6 -6
View File
@@ -15,7 +15,7 @@ import (
"github.com/pocketbase/pocketbase/tools/migrate"
)
const collectionsCacheKey = "migratecmd_collections"
const collectionsStoreKey = "migratecmd_collections"
// onCollectionChange handles the automigration snapshot generation on
// collection change event (create/update/delete).
@@ -94,7 +94,7 @@ func (p *plugin) afterCollectionChange() func(*core.ModelEvent) error {
}
func (p *plugin) updateSingleCachedCollection(new, old *models.Collection) {
cached, _ := p.app.Cache().Get(collectionsCacheKey).(map[string]*models.Collection)
cached, _ := p.app.Store().Get(collectionsStoreKey).(map[string]*models.Collection)
switch {
case new == nil:
@@ -103,7 +103,7 @@ func (p *plugin) updateSingleCachedCollection(new, old *models.Collection) {
cached[new.Id] = new
}
p.app.Cache().Set(collectionsCacheKey, cached)
p.app.Store().Set(collectionsStoreKey, cached)
}
func (p *plugin) refreshCachedCollections() error {
@@ -121,19 +121,19 @@ func (p *plugin) refreshCachedCollections() error {
cached[c.Id] = c
}
p.app.Cache().Set(collectionsCacheKey, cached)
p.app.Store().Set(collectionsStoreKey, cached)
return nil
}
func (p *plugin) getCachedCollections() (map[string]*models.Collection, error) {
if !p.app.Cache().Has(collectionsCacheKey) {
if !p.app.Store().Has(collectionsStoreKey) {
if err := p.refreshCachedCollections(); err != nil {
return nil, err
}
}
result, _ := p.app.Cache().Get(collectionsCacheKey).(map[string]*models.Collection)
result, _ := p.app.Store().Get(collectionsStoreKey).(map[string]*models.Collection)
return result, nil
}