Skip to content

Commit

Permalink
Added context filter for admin logs, missing application context
Browse files Browse the repository at this point in the history
  • Loading branch information
r3-gabriel committed Oct 4, 2021
1 parent 23f2af8 commit 4be14a7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func SetConfigFilePath(path string) {
filePath = path
}
func SetLogLevels() {
log.SetLogLevel("application", int(GetUint64("logApplication")))
log.SetLogLevel("backup", int(GetUint64("logBackup")))
log.SetLogLevel("cache", int(GetUint64("logCache")))
log.SetLogLevel("csv", int(GetUint64("logCsv")))
Expand Down
30 changes: 18 additions & 12 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ var (

// log levels
contextLevel = map[string]int{
"backup": 1,
"cache": 1,
"csv": 1,
"mail": 1,
"ldap": 1,
"scheduler": 1,
"server": 1,
"transfer": 1,
"application": 1,
"backup": 1,
"cache": 1,
"csv": 1,
"mail": 1,
"ldap": 1,
"scheduler": 1,
"server": 1,
"transfer": 1,
}
)

func Get(dateFrom pgtype.Int8, dateTo pgtype.Int8, limit int, offset int, byString string) ([]types.Log, int, error) {
func Get(dateFrom pgtype.Int8, dateTo pgtype.Int8, limit int, offset int,
context string, byString string) ([]types.Log, int, error) {

logs := make([]types.Log, 0)
total := 0
Expand All @@ -40,11 +42,15 @@ func Get(dateFrom pgtype.Int8, dateTo pgtype.Int8, limit int, offset int, byStri
qb.Set("FROM", "instance.log AS l")
qb.Add("JOIN", "LEFT JOIN app.module AS m ON m.id = l.module_id")

if context != "" {
qb.Add("WHERE", `l.context::TEXT = {CONTEXT}`)
qb.AddPara("{CONTEXT}", context)
}

if byString != "" {
qb.Add("WHERE", `(
l.context::TEXT ILIKE {NAME} OR
l.message ILIKE {NAME} OR
m.name ILIKE {NAME}
l.message ILIKE {NAME} OR
m.name ILIKE {NAME}
)`)
qb.AddPara("{NAME}", fmt.Sprintf("%%%s%%", byString))
}
Expand Down
5 changes: 3 additions & 2 deletions request/request_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func LogGet(reqJson json.RawMessage) (interface{}, error) {
err error
req struct {
ByString string `json:"byString"`
Context string `json:"context"`
DateFrom pgtype.Int8 `json:"dateFrom"`
DateTo pgtype.Int8 `json:"dateTo"`
Limit int `json:"limit"`
Expand All @@ -28,8 +29,8 @@ func LogGet(reqJson json.RawMessage) (interface{}, error) {
if err := json.Unmarshal(reqJson, &req); err != nil {
return nil, err
}
res.Logs, res.Total, err = log.Get(req.DateFrom,
req.DateTo, req.Limit, req.Offset, req.ByString)
res.Logs, res.Total, err = log.Get(req.DateFrom, req.DateTo,
req.Limit, req.Offset, req.Context, req.ByString)

if err != nil {
return nil, err
Expand Down
18 changes: 16 additions & 2 deletions www/comps/admin/adminLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ let MyAdminLogs = {
:offset="offset"
:total="total"
/>
<select class="entry" v-model="context" @change="offset = 0;get()">
<option value="">[{{ capApp.context }}]</option>
<option value="application">Applications</option>
<option value="backup">Backup</option>
<option value="cache">Cache</option>
<option value="csv">CSV</option>
<option value="ldap">LDAP</option>
<option value="mail">Mail</option>
<option value="scheduler">Scheduler</option>
<option value="server">Server</option>
<option value="transfer">Transfer</option>
</select>
<input class="entry"
v-model="byString"
@keyup.enter="offset = 0;get()"
Expand Down Expand Up @@ -101,11 +113,12 @@ let MyAdminLogs = {

// inputs
byString:'',
unixFrom:null,
unixTo:null,
context:'',
limit:100,
offset:0,
total:0,
unixFrom:null,
unixTo:null,

// data
logs:[]
Expand Down Expand Up @@ -182,6 +195,7 @@ let MyAdminLogs = {
let trans = new wsHub.transactionBlocking();
trans.add('log','get',{
byString:this.byString,
context:this.context,
dateFrom:this.unixFrom,
dateTo:this.unixTo,
limit:this.limit,
Expand Down

0 comments on commit 4be14a7

Please sign in to comment.