Skip to content

Commit

Permalink
feat: convert table server logging messages to localizable strings
Browse files Browse the repository at this point in the history
  • Loading branch information
tucats committed Jan 25, 2025
1 parent 09ceb59 commit 9d2a581
Show file tree
Hide file tree
Showing 26 changed files with 383 additions and 283 deletions.
4 changes: 0 additions & 4 deletions bytecode/goroutine.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/tucats/ego/app-cli/ui"
"github.com/tucats/ego/data"
"github.com/tucats/ego/errors"
"github.com/tucats/ego/i18n"
"github.com/tucats/ego/symbols"
)

Expand Down Expand Up @@ -132,9 +131,6 @@ func GoRoutine(fx interface{}, parentCtx *Context, args data.List) {

// If we had an error in the go routine, stop the invoking context execution.
if err != nil && !err.Is(errors.ErrStop) {
msg := i18n.E("go.error", map[string]interface{}{"id": ctx.threadID, "name": fName, "err": err})
ui.Log(ui.InfoLogger, "%s", msg)

ui.Log(ui.GoRoutineLogger, "go.exit.error",
"thread", ctx.threadID,
"name", fName,
Expand Down
37 changes: 35 additions & 2 deletions i18n/languages/messages_en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,13 @@ db.tx.exec=(TX) Executing, sql: {{sql}}
db.rows={{count}} rows affected
db.rows.close=rows.Close() called
db.rows.next=rows.Next() called, more rows={{flag}}
db.dsn=Accessing using DSN {{name}}
db.dsn.error=Error reading dsn {{name}}{{user|label ", user="}}: {{error}}
db.dsn.found=DSN {{name}} found
db.dsn.noauth=User {{user}} not authorized for action {{action}} in dsn {{dsn}}
db.dsn.auth=User {{user}} is authorized for action {{action}} in dsn {{dsn}}
db.error=Database error, {{error}}
db.dsn.constr=Connection string is {{constr}}


go.launch=Launching go routine {{function}} from thread id {{thread}}
Expand All @@ -865,7 +872,6 @@ go.args=Thread {{thread}} argument list: {{args}}
go.exit.error=Go routine invocation of {{name}} (thread {{thread}}) exits with {{error}}
go.exit=Go routine invocation of {{name}} (thread {{thread}}) exits without error


logging.filename=New log file opened: {{name}}
logging.purging=Purging all but {{count}} logs from {{path}}
logging.archiving=Archving all but {{count}} logs from {{path}}
Expand Down Expand Up @@ -1097,6 +1103,12 @@ services.run.error=Service execution error, {{error}}
sql.read.unique=Read unique query: {{sql}}
sql.read.nullabe=Read nullable query: {{sql}}
sql.query=Query: {{sql}}
sql.columns.metadata=Columns metadata query: {{sql}}
sql.query.error=Query error: {{error}}
sql.row.count.query=Row count query: {{sql}}
sql.exec=Execute: {{sql}}
sql.rows={{count}} rows affected
sql.read.rows=Read {{rows}} rows of {{columns}} columns


stats.time=Compile and execution time: {{duration|%15s}}
Expand All @@ -1110,11 +1122,32 @@ stats.system.heap=Total system memory allocated: {{size|%12d}}
stats.gc.count=Garbage collection cycles: {{count|%12d}}
stats.gc.cpu=Garbage collection pct of cpu: {{cpu|%8.7f}}


table.unique.columns=Unique columns: {{list}}
table.nullable.columns=Nullable columns: {{list}}
table.schema.tables=Attempting to read tables from schema {{schema}}
table.schema.count=Read {{count}} table names

table.deleted.rows=Deleted {{count}} rows; {{status}}
table.inserted.rows=Inserted {{count}}; {{status}}
table.update.column=Updated column {{name}} value from {{from}} to {{to}}
table.read.error=read error, {{error}}
table.read=Read {{rows}} rows of {{coulumns}}; {{status}}
table.update.table=Request to update rows in table {{name}}
table.parms=Request parameteres: {{parms}}
table.updated.rows=Updated {{count}} rows; {{status}}
table.values=values list = {{data|list}}
table.query.error=failed query: {{sql}}, {{error}}
table.exclude=Exclude list = {{data||list}}
table.permissions=Permissions list for user {{name}}, table {{table}}: {{perms}}
table.perms.deleted={{count}} permissions for {{table}} deleted
table.write.error=Error writing/updating: {{error}}
table.tx=Exxecuting SQL statements in a transaction
table.tx.count=Transaction request has {{count}} operations
table.tx.rollback=Transaction rolled back at task {{count}}
table.tx.done=Completed {{operations}} in transaction, modified and/or read {{afffected}} rows, returning {{rows}} rows
table.tx.affected=Completed {{operations}} in tractions, uupdated {{affected}} rows
table.created=Table created
table.affected=Affected {{count}} rows

symbols.push.table=({{thread}}) push symbol table; "{{name}}" <= "{{parent}}"
symbols.push.table.boundary=({{thread}}) push symbol table; "{{name}}" <= "{{parent}}" (boundary={{flag}})
Expand Down
4 changes: 2 additions & 2 deletions server/auth/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ func ageCredentials() {
}

if len(list) > 0 {
ui.Log(ui.AuthLogger, "auth.proxy.expire",
"count", len(list))
ui.Log(ui.AuthLogger, "auth.proxy.expire", ui.A{
"count": len(list)})
}

for _, user := range list {
Expand Down
23 changes: 12 additions & 11 deletions server/auth/users_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func NewFileService(userDatabaseFile, defaultUser, defaultPassword string) (user
}
}

ui.Log(ui.AuthLogger, "auth.file.size",
"size", len(svc.data))
ui.Log(ui.AuthLogger, "auth.file.size", ui.A{
"size": len(svc.data)})
}
}

Expand All @@ -83,9 +83,10 @@ func NewFileService(userDatabaseFile, defaultUser, defaultPassword string) (user
}
svc.dirty = true

ui.Log(ui.AuthLogger, "auth.default.cred",
"user", defaultUser,
"pass", strings.Repeat("*", len(defaultPassword)))
ui.Log(ui.AuthLogger, "auth.default.cred", ui.A{
"user": defaultUser,
"pass": strings.Repeat("*", len(defaultPassword)),
})
}

return svc, nil
Expand Down Expand Up @@ -127,11 +128,11 @@ func (f *fileService) WriteUser(user defs.User) error {
f.dirty = true

if found {
ui.Log(ui.AuthLogger, "auth.user.update",
"user", user.Name)
ui.Log(ui.AuthLogger, "auth.user.update", ui.A{
"user": user.Name})
} else {
ui.Log(ui.AuthLogger, "auth.user.create",
"user", user.Name)
ui.Log(ui.AuthLogger, "auth.user.create", ui.A{
"user": user.Name})
}

return nil
Expand All @@ -148,8 +149,8 @@ func (f *fileService) DeleteUser(name string) error {
delete(f.data, u.Name)
f.dirty = true

ui.Log(ui.AuthLogger, "auth.user.delete",
"user", u.Name)
ui.Log(ui.AuthLogger, "auth.user.delete", ui.A{
"user": u.Name})
}

return nil
Expand Down
40 changes: 20 additions & 20 deletions server/auth/users_sqldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func NewDatabaseService(connStr, defaultUser, defaultPassword string) (userIOSer

// Create the underlying database table definition if it does not yet exist.
if err = svc.userHandle.CreateIf(); err != nil {
ui.Log(ui.ServerLogger, "server.db.error",
"error", err)
ui.Log(ui.ServerLogger, "server.db.error", ui.A{
"error": err})

return nil, errors.New(err)
}
Expand All @@ -54,8 +54,8 @@ func NewDatabaseService(connStr, defaultUser, defaultPassword string) (userIOSer
err = svc.userHandle.Insert(user)

if err == nil {
ui.Log(ui.AuthLogger, "auth.user.create",
"user", user.Name)
ui.Log(ui.AuthLogger, "auth.user.create", ui.A{
"user": user.Name})
}
}

Expand All @@ -77,8 +77,8 @@ func (pg *databaseService) ListUsers() map[string]defs.User {

rowSet, err := pg.userHandle.Begin().Read()
if err != nil {
ui.Log(ui.ServerLogger, "server.db.error",
"error", err)
ui.Log(ui.ServerLogger, "server.db.error", ui.A{
"error": err})

return r
}
Expand Down Expand Up @@ -114,8 +114,8 @@ func (pg *databaseService) ReadUser(name string, doNotLog bool) (defs.User, erro

rowSet, err := pg.userHandle.Begin().Read(pg.userHandle.Equals("name", name))
if err != nil {
ui.Log(ui.ServerLogger, "server.db.error",
"error", err)
ui.Log(ui.ServerLogger, "server.db.error", ui.A{
"error": err})

return defs.User{}, errors.New(err)
}
Expand All @@ -127,8 +127,8 @@ func (pg *databaseService) ReadUser(name string, doNotLog bool) (defs.User, erro

if !found {
if !doNotLog {
ui.Log(ui.AuthLogger, "auth.user.not.found",
"user", name)
ui.Log(ui.AuthLogger, "auth.user.not.found", ui.A{
"user": name})
}

return defs.User{}, errors.ErrNoSuchUser.Context(name)
Expand Down Expand Up @@ -157,13 +157,13 @@ func (pg *databaseService) WriteUser(user defs.User) error {
}

if err != nil {
ui.Log(ui.ServerLogger, "server.db.error",
"error", err)
ui.Log(ui.ServerLogger, "server.db.error", ui.A{
"error": err})

err = errors.New(err)
} else {
ui.Log(ui.AuthLogger, update,
"user", user.Name)
ui.Log(ui.AuthLogger, update, ui.A{
"user": user.Name})
}

return err
Expand All @@ -178,17 +178,17 @@ func (pg *databaseService) DeleteUser(name string) error {

count, err := pg.userHandle.Begin().Delete(pg.userHandle.Equals("name", name))
if err != nil {
ui.Log(ui.ServerLogger, "server.db.error",
"error", err)
ui.Log(ui.ServerLogger, "server.db.error", ui.A{
"error": err})

err = errors.New(err)
} else {
if count > 0 {
ui.Log(ui.AuthLogger, "auth.user.delete",
"user", name)
ui.Log(ui.AuthLogger, "auth.user.delete", ui.A{
"user": name})
} else {
ui.Log(ui.AuthLogger, "auth.user.not.found",
"user", name)
ui.Log(ui.AuthLogger, "auth.user.not.found", ui.A{
"user": name})
}
}

Expand Down
4 changes: 2 additions & 2 deletions server/auth/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func ValidateToken(t string) bool {

v, err := builtins.CallBuiltin(s, "cipher.Validate", t, true)
if err != nil {
ui.Log(ui.AuthLogger, "auth.token.error",
"error", err)
ui.Log(ui.AuthLogger, "auth.token.error", ui.A{
"error": err})

return false
}
Expand Down
16 changes: 8 additions & 8 deletions server/dsns/dsn_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func NewFileService(userDatabaseFile string) (dsnService, error) {
svc.Data = svcObject.Data
svc.Auth = svcObject.Auth

ui.Log(ui.AuthLogger, "auth.file.size",
"size", len(svc.Data))
ui.Log(ui.AuthLogger, "auth.file.size", ui.A{
"size": len(svc.Data)})
}
}

Expand Down Expand Up @@ -90,11 +90,11 @@ func (f *fileService) WriteDSN(user string, dsn defs.DSN) error {
f.dirty = true

if found {
ui.Log(ui.AuthLogger, "auth.dsn.udpate",
"nane", dsn.Name)
ui.Log(ui.AuthLogger, "auth.dsn.udpate", ui.A{
"name": dsn.Name})
} else {
ui.Log(ui.AuthLogger, "auth.dsn.create",
"name", dsn.Name)
ui.Log(ui.AuthLogger, "auth.dsn.create", ui.A{
"name": dsn.Name})
}

return nil
Expand All @@ -109,8 +109,8 @@ func (f *fileService) DeleteDSN(user, name string) error {
delete(f.Data, u.Name)
delete(f.Auth, key)

ui.Log(ui.AuthLogger, "auth.dsn.delete",
"name", u.Name)
ui.Log(ui.AuthLogger, "auth.dsn.delete", ui.A{
"name": u.Name})
}

return nil
Expand Down
40 changes: 20 additions & 20 deletions server/dsns/dsn_sqldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ func NewDatabaseService(connStr string) (dsnService, error) {
}

if dberr := svc.initializeDatabase(); dberr != nil {
ui.Log(ui.ServerLogger, "server.db.error",
"error", dberr)
ui.Log(ui.ServerLogger, "server.db.error", ui.A{
"error": dberr})

return nil, errors.New(dberr)
}

ui.Log(ui.AuthLogger, "auth.dsn.db",
"constr", svc.constr)
ui.Log(ui.AuthLogger, "auth.dsn.db", ui.A{
"constr": svc.constr})

return svc, nil
}
Expand Down Expand Up @@ -106,8 +106,8 @@ func (pg *databaseService) ReadDSN(user, name string, doNotLog bool) (defs.DSN,
item, err = pg.dsnHandle.Begin().ReadOne(name)
if err != nil {
if !doNotLog {
ui.Log(ui.AuthLogger, "auth.dsn.not.found",
"name", name)
ui.Log(ui.AuthLogger, "auth.dsn.not.found", ui.A{
"name": name})
}

if errors.Equal(err, errors.ErrNotFound) {
Expand Down Expand Up @@ -150,14 +150,14 @@ func (pg *databaseService) WriteDSN(user string, dsname defs.DSN) error {
}

if err != nil {
ui.Log(ui.ServerLogger, "server.db.error",
"error", err)
ui.Log(ui.ServerLogger, "server.db.error", ui.A{
"error": err})

err = errors.New(err)
} else {
caches.Add(caches.DSNCache, dsname.Name, &dsname)
ui.Log(ui.AuthLogger, "auth.dsn.update",
"name", dsname.Name)
ui.Log(ui.AuthLogger, "auth.dsn.update", ui.A{
"name": dsname.Name})
}

return err
Expand All @@ -173,8 +173,8 @@ func (pg *databaseService) DeleteDSN(user, name string) error {
// Delete any authentication objects for this DSN as well...
_, _ = pg.authHandle.Begin().Delete(pg.authHandle.Equals("dsn", name))

ui.Log(ui.AuthLogger, "auth.dsn.delete",
"name", name)
ui.Log(ui.AuthLogger, "auth.dsn.delete", ui.A{
"name": name})
}

if errors.Equal(err, errors.ErrNotFound) {
Expand Down Expand Up @@ -271,11 +271,11 @@ func (pg *databaseService) GrantDSN(user, name string, action DSNAction, grant b
existingAction = auth.Action
exists = true

ui.Log(ui.AuthLogger, "auth.dsn.found",
"name", name)
ui.Log(ui.AuthLogger, "auth.dsn.found", ui.A{
"name": name})
} else {
ui.Log(ui.AuthLogger, "auth.dsn.not.found",
"name", name)
ui.Log(ui.AuthLogger, "auth.dsn.not.found", ui.A{
"name": name})

auth.DSN = name
auth.User = user
Expand All @@ -290,17 +290,17 @@ func (pg *databaseService) GrantDSN(user, name string, action DSNAction, grant b
existingAction = existingAction &^ action
}

ui.Log(ui.AuthLogger, "auth.dsn.mask",
"mask", existingAction)
ui.Log(ui.AuthLogger, "auth.dsn.mask", ui.A{
"mask": existingAction})

// If the DSN was not previously marked as restricted,
// then update it now to be restricted so future access
// will use the auth table for authorization checks.
if !dsn.Restricted {
dsn.Restricted = true

ui.Log(ui.AuthLogger, "auth.dsn.restrict",
"name", dsn.Name)
ui.Log(ui.AuthLogger, "auth.dsn.restrict", ui.A{
"name": name})

if err = pg.WriteDSN(user, dsn); err != nil {
return err
Expand Down
Loading

0 comments on commit 9d2a581

Please sign in to comment.