From 679bc9b9029ae232cfe953f1f5160cf598bde83c Mon Sep 17 00:00:00 2001 From: alex Date: Tue, 17 Oct 2023 22:23:17 +0200 Subject: [PATCH] implemented updated logger --- go.mod | 5 +- go.sum | 24 +++++++++- .../robots/__pycache__/rex.cpython-39.pyc | Bin 3286 -> 3286 bytes groupTasks/libs/robots/rex.py | 5 +- main.go | 2 +- modules/equipment/equipment.go | 7 +-- modules/grouptasks/grouptasks.go | 45 +++++++++--------- modules/logger/logger.go | 10 ++-- modules/requestclient/requestclient.go | 5 +- routers/router/router.go | 5 +- socketclients/socketclients.go | 31 ++++++------ socketserver/hub.go | 13 ++--- 12 files changed, 91 insertions(+), 61 deletions(-) diff --git a/go.mod b/go.mod index 13be141..4f8a18e 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,8 @@ module jannex/admin-dashboard-backend go 1.21.0 require ( - git.ex.umbach.dev/Alex/roese-utils v1.0.11 + git.ex.umbach.dev/Alex/roese-utils v1.0.16 + github.com/gofiber/fiber v1.14.6 github.com/gofiber/fiber/v2 v2.49.2 github.com/gofiber/websocket/v2 v2.1.6 github.com/google/uuid v1.3.1 @@ -23,6 +24,8 @@ require ( github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.15.5 // indirect github.com/go-sql-driver/mysql v1.7.0 // indirect + github.com/gofiber/utils v0.0.10 // indirect + github.com/gorilla/schema v1.1.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/klauspost/compress v1.16.7 // indirect diff --git a/go.sum b/go.sum index 51d2ed5..a7d8eb4 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,6 @@ -git.ex.umbach.dev/Alex/roese-utils v1.0.11 h1:iPrVktpUG0WYLTexoI3iJqi/KojaB5Cs0hCF/GFs92c= -git.ex.umbach.dev/Alex/roese-utils v1.0.11/go.mod h1:mov3ZaoSu+GBQU1uXN/AfSK6MF3/3WxUk38Tb6IKxbI= +git.ex.umbach.dev/Alex/roese-utils v1.0.16 h1:B9yVx5nL7FfUPJmqHDs58mq8MB2wSox1fK34EP3dqhc= +git.ex.umbach.dev/Alex/roese-utils v1.0.16/go.mod h1:mov3ZaoSu+GBQU1uXN/AfSK6MF3/3WxUk38Tb6IKxbI= +github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= @@ -21,24 +22,33 @@ github.com/go-playground/validator/v10 v10.15.5/go.mod h1:9iXMNT7sEkjXb0I+enO7QX github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc= github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/gofiber/fiber v1.14.6 h1:QRUPvPmr8ijQuGo1MgupHBn8E+wW0IKqiOvIZPtV70o= +github.com/gofiber/fiber v1.14.6/go.mod h1:Yw2ekF1YDPreO9V6TMYjynu94xRxZBdaa8X5HhHsjCM= github.com/gofiber/fiber/v2 v2.49.2 h1:ONEN3/Vc+dUCxxDgZZwpqvhISgHqb+bu+isBiEyKEQs= github.com/gofiber/fiber/v2 v2.49.2/go.mod h1:gNsKnyrmfEWFpJxQAV0qvW6l70K1dZGno12oLtukcts= +github.com/gofiber/utils v0.0.10 h1:3Mr7X7JdCUo7CWf/i5sajSaDmArEDtti8bM1JUVso2U= +github.com/gofiber/utils v0.0.10/go.mod h1:9J5aHFUIjq0XfknT4+hdSMG6/jzfaAgCu4HEbWDeBlo= github.com/gofiber/websocket/v2 v2.1.6 h1:k4z+YqzGUwbCQJCIW+mDJF2iCcBfRY7BJGUa2k+VHXo= github.com/gofiber/websocket/v2 v2.1.6/go.mod h1:o+oXFwHjavIiM2KWo/MNpcIOruS0am16h3efqnjXLis= github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/gorilla/schema v1.1.0 h1:CamqUDOFUBqzrvxuz2vEwo8+SUdwsluFh7IlzJh30LY= +github.com/gorilla/schema v1.1.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= @@ -63,18 +73,28 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA= github.com/valyala/fasthttp v1.49.0 h1:9FdvCpmxB74LH4dPb7IJ1cOSsluR07XG3I1txXWwJpE= github.com/valyala/fasthttp v1.49.0/go.mod h1:k2zXd82h/7UZc3VOdJ2WaUqt1uZ/XpXAfE9i+HBC3lA= +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ= golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/groupTasks/libs/robots/__pycache__/rex.cpython-39.pyc b/groupTasks/libs/robots/__pycache__/rex.cpython-39.pyc index 155119ca1865bc10fa43eca34f70f10fa5781cc6..73142ca6dc9ac2ca0a6bd609572cab10ef9095a4 100644 GIT binary patch delta 95 zcmV-l0HFWY8P*vNVGRum00000E$S|1PYbaQSOWnZlV<~z0VcEj1Ly$(DU;;|=mA8N z&IYUjOp|*DssU27CJ0gi0a%lH3H||OlXwcq18HPzlS2!T0cw-f3xWX{lUEFW0SRS0 B9m@a! delta 95 zcmV-l0HFWY8P*vNVGRum00000a>6cUw+gWiSOWnYlV<~z0VT8i1Ly$(D3j#{=mA5M z&IYUjOOtyCssT~6CJ0gi0aufG3H||NlXwcq17>n%lS2!T0cn%e3xWX`lUEFW0SJu8 B9!LNH diff --git a/groupTasks/libs/robots/rex.py b/groupTasks/libs/robots/rex.py index 4fb8312..f417b52 100644 --- a/groupTasks/libs/robots/rex.py +++ b/groupTasks/libs/robots/rex.py @@ -19,6 +19,7 @@ max_job_name_length = 30 ### # TODO: add oriention left or right +# TODO: bei jeder Positionsangabe (einmal bei XY und einmal bei Z) geben wir eine Zahl an als Kraft, die normalerweise nicht überschritten werden soll class Rex: """ @@ -105,11 +106,11 @@ class Rex: def finish(self): """ Finish the robot. - This will update the robot status to free. + This will update the robot status to idle. """ print('Robot finished') - # TODO: request to the server to finish the robot and update the robot status to free + # TODO: request to the server to finish the robot and update the robot status to idle res = requests.post(self.address + '/v1/control/1/finish', json={'robotName': self.robotName, 'jobId': self.jobId}) diff --git a/main.go b/main.go index 67045f2..3204222 100644 --- a/main.go +++ b/main.go @@ -164,7 +164,7 @@ func main() { go grouptasks.StartUnlockLockedGroupTaskStepsTicker() - adlogger.AddSystemLog("Server started") + adlogger.AddSystemLog(rslogger.LogTypeInfo, "Server started") app.Listen(config.Cfg.Host + ":" + config.Cfg.Port) } diff --git a/modules/equipment/equipment.go b/modules/equipment/equipment.go index 55fcf6e..781cd73 100644 --- a/modules/equipment/equipment.go +++ b/modules/equipment/equipment.go @@ -13,6 +13,7 @@ import ( "strconv" "strings" + "git.ex.umbach.dev/Alex/roese-utils/rslogger" "git.ex.umbach.dev/Alex/roese-utils/rspagination" "github.com/gofiber/fiber/v2" "github.com/google/uuid" @@ -106,7 +107,7 @@ func CreateEquipmentDocumentation(c *fiber.Ctx, body structs.CreateEquipmentDocu database.DB.Create(&newEquipmentDocumentation) - logger.AddSystemLog("User %s has created the equipment document %s for the stock item %s with the title %s type %v description %s", + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has created the equipment document %s for the stock item %s with the title %s type %v description %s", userId, newEquipmentDocumentation.Id, newEquipmentDocumentation.StockItemId, body.Title, body.Type, string(marshaledNotes)) return c.JSON(fiber.Map{"message": "ok"}) @@ -142,7 +143,7 @@ func GetEquipmentDocumentations(stockItemId string, query rspagination.PageQuery stockItemId) } - logger.AddSystemLog("User %s has viewed equipment documentation of the stock item %s. StatusCode: %s", + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has viewed equipment documentation of the stock item %s. StatusCode: %s", c.Locals("userId").(string), stockItemId, strconv.Itoa(statusCode)) return c.JSON(structs.EquipmentDocumentationResponse{ @@ -246,7 +247,7 @@ func EditEquipmentDocumentation(c *fiber.Ctx, body structs.EditEquipmentDocument Notes: string(marshaledNotes), }) - logger.AddSystemLog("User %s has updated the equipment document %s to title %s type %s and description %s", + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has updated the equipment document %s to title %s type %s and description %s", c.Locals("userId").(string), body.DocumentationId, body.Title, strconv.Itoa(int(body.Type)), string(marshaledNotes)) return c.JSON(fiber.Map{"message": "ok"}) diff --git a/modules/grouptasks/grouptasks.go b/modules/grouptasks/grouptasks.go index 4319d7e..a787c03 100644 --- a/modules/grouptasks/grouptasks.go +++ b/modules/grouptasks/grouptasks.go @@ -18,6 +18,7 @@ import ( "strings" "time" + "git.ex.umbach.dev/Alex/roese-utils/rslogger" "git.ex.umbach.dev/Alex/roese-utils/rspagination" "git.ex.umbach.dev/Alex/roese-utils/rsutils" "github.com/google/uuid" @@ -362,7 +363,7 @@ func HandleUserActionTaskStep(userId string, body map[string]interface{}) { nextStep = step + 1 - logger.AddGroupTasksLog("User %s has executed action %s on step %s of groupTaskId %s", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "User %s has executed action %s on step %s of groupTaskId %s", userId, "resume", taskStepId, groupTaskId) } else { groupTaskStep.Status = utils.GroupTasksStatusRunning @@ -395,13 +396,13 @@ func HandleUserActionTaskStep(userId string, body map[string]interface{}) { if action == UserActionTaskStepRepeat { runGroupTaskArgs.StartType = RunGroupTaskStartTypeTryAgain - logger.AddGroupTasksLog("User %s has executed action %s on step %s of groupTaskId %s", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "User %s has executed action %s on step %s of groupTaskId %s", userId, "repeat", taskStepId, groupTaskId) } else if action == UserActionTaskStepUndo { runGroupTaskArgs.StartType = RunGroupTaskStartTypeUndo runGroupTaskArgs.TaskInputs = dbGroupTaskStep.Inputs - logger.AddGroupTasksLog("User %s has executed action %s on step %s of groupTaskId %s", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "User %s has executed action %s on step %s of groupTaskId %s", userId, "undo", taskStepId, groupTaskId) } @@ -470,7 +471,7 @@ func RunGroupTask(args RunGroupTaskArgs) { updateGroupTaskSteps(groupTaskStep, args.Category) - logger.AddGroupTasksLog("Step %s of groupTaskId %s status set to %s", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "Step %s of groupTaskId %s status set to %s", groupTaskStep.Id, groupTaskStep.GroupTasksId, "input required") return } else if len(args.TaskInputs) > 0 { @@ -536,12 +537,12 @@ func RunGroupTask(args RunGroupTaskArgs) { log.Error().Msgf("error exec command %s", err.Error()) groupTaskStep.Status = utils.GroupTasksStatusFailed - logger.AddGroupTasksLog("Step %s of groupTaskId %s status set to %s", + logger.AddGroupTasksLog(rslogger.LogTypeWarning, "Step %s of groupTaskId %s status set to %s", groupTaskStep.Id, groupTaskStep.GroupTasksId, "failed") } else { groupTaskStep.Status = utils.GroupTasksStatusFinished - logger.AddGroupTasksLog("Step %s of groupTaskId %s status set to %s", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "Step %s of groupTaskId %s status set to %s", groupTaskStep.Id, groupTaskStep.GroupTasksId, "finished") } @@ -638,7 +639,7 @@ func RunGroupTask(args RunGroupTaskArgs) { Status: utils.GroupTasksStatusFailed, }, args.Category) - logger.AddGroupTasksLog("GroupTaskId %s status set to %s", + logger.AddGroupTasksLog(rslogger.LogTypeWarning, "GroupTaskId %s status set to %s", groupTaskStep.GroupTasksId, "failed") } else { prevStartType := args.StartType @@ -652,16 +653,16 @@ func RunGroupTask(args RunGroupTaskArgs) { groupTaskStep.Inputs = " " groupTaskStep.Files = " " - logger.AddGroupTasksLog("GroupTaskId %s status set to %s", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "GroupTaskId %s status set to %s", groupTaskStep.GroupTasksId, "Undo ended") - logger.AddGroupTasksLog("Step %s of groupTaskId %s status set to %s", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "Step %s of groupTaskId %s status set to %s", groupTaskStep.Id, groupTaskStep.GroupTasksId, "Undo ended") } else { - logger.AddGroupTasksLog("GroupTaskId %s status set to %s", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "GroupTaskId %s status set to %s", groupTaskStep.GroupTasksId, "paused") - logger.AddGroupTasksLog("Step %s of groupTaskId %s status set to %s", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "Step %s of groupTaskId %s status set to %s", groupTaskStep.Id, groupTaskStep.GroupTasksId, "paused") } @@ -682,7 +683,7 @@ func RunGroupTask(args RunGroupTaskArgs) { CurrentTasksStep: args.Step, }, args.Category) - logger.AddGroupTasksLog("System has started step %s of groupTaskId %s", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "System has started step %s of groupTaskId %s", rsutils.MarshalJson(args.Step), groupTaskStep.GroupTasksId) RunGroupTask(args) @@ -704,7 +705,7 @@ func groupTaskFinished(groupTasksId string, category string) { log.Error().Msgf("Failed to delete running task folder %s", err.Error()) } - logger.AddGroupTasksLog("GroupTaskId %s status set to %s", groupTasksId, "finished") + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "GroupTaskId %s status set to %s", groupTasksId, "finished") } // Updates group task and send it to websocket users @@ -880,12 +881,12 @@ func StartGroupTask(userId string, groupTask structs.GroupTasks) { GlobalInputs: groupTask.GlobalInputs, }) - logger.AddGroupTasksLog("User %s has started group task groupTaskId %s groupTaskName %s", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "User %s has started group task groupTaskId %s groupTaskName %s", userId, groupTask.Id, groupTask.GroupName) } func InstallGlobalPythonPackages(userId string) { - logger.AddGroupTasksLog("User %s has requested installing the global python packages", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "User %s has requested installing the global python packages", userId) socketclients.BroadcastMessageToUsersWithPermissionAndTopic( @@ -897,7 +898,7 @@ func InstallGlobalPythonPackages(userId string) { // check if requirements.txt exists if _, err := os.Stat(config.Cfg.FolderPaths.GroupTasksGroups + "requirements.txt"); errors.Is(err, os.ErrNotExist) { - logger.AddGroupTasksLog("Installing the global python packages failed. Error %s", "requirements.txt not found") + logger.AddGroupTasksLog(rslogger.LogTypeWarning, "Installing the global python packages failed. Error %s", "requirements.txt not found") socketclients.BroadcastMessageToUsersWithPermissionAndTopic( utils.PermissionGroupTasksInstallGlobalPythonPackages, @@ -913,7 +914,7 @@ func InstallGlobalPythonPackages(userId string) { out, err := cmd.CombinedOutput() if err != nil { - logger.AddGroupTasksLog("Installing the global python packages failed. Error %s", err.Error()) + logger.AddGroupTasksLog(rslogger.LogTypeWarning, "Installing the global python packages failed. Error %s", err.Error()) socketclients.BroadcastMessageToUsersWithPermissionAndTopic( utils.PermissionGroupTasksInstallGlobalPythonPackages, @@ -924,7 +925,7 @@ func InstallGlobalPythonPackages(userId string) { return } - logger.AddGroupTasksLog("Installation of the global python packages finished. Log %s", string(out)) + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "Installation of the global python packages finished. Log %s", string(out)) socketclients.BroadcastMessageToUsersWithPermissionAndTopic( utils.PermissionGroupTasksInstallGlobalPythonPackages, @@ -935,7 +936,7 @@ func InstallGlobalPythonPackages(userId string) { } func InstallPythonPackages(userId string, category string, groupId string) { - logger.AddGroupTasksLog("User %s has requested installing python packages for groupId %s of category %s", userId, groupId, category) + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "User %s has requested installing python packages for groupId %s of category %s", userId, groupId, category) messageBody := struct { Category string @@ -957,7 +958,7 @@ func InstallPythonPackages(userId string, category string, groupId string) { // check if requirements.txt exists if _, err := os.Stat(config.Cfg.FolderPaths.GroupTasksGroups + groupId + "/requirements.txt"); errors.Is(err, os.ErrNotExist) { - logger.AddGroupTasksLog("Installing python packages for groupId %s of category %s failed. Error: %s", + logger.AddGroupTasksLog(rslogger.LogTypeWarning, "Installing python packages for groupId %s of category %s failed. Error: %s", category, groupId, "requirements.txt not found") socketclients.BroadcastMessageToUsersWithPermissionAndTopic( @@ -977,7 +978,7 @@ func InstallPythonPackages(userId string, category string, groupId string) { log.Info().Msgf("pa %s", config.Cfg.FolderPaths.GroupTasksGroups+groupId+"/requirements.txt") if err != nil { - logger.AddGroupTasksLog("Installing python packages for groupId %s of category %s failed. Error: %s", + logger.AddGroupTasksLog(rslogger.LogTypeWarning, "Installing python packages for groupId %s of category %s failed. Error: %s", category, groupId, err.Error()) socketclients.BroadcastMessageToUsersWithPermissionAndTopic( @@ -990,7 +991,7 @@ func InstallPythonPackages(userId string, category string, groupId string) { return } - logger.AddGroupTasksLog("Installing python packages for groupId %s of category %s finished. Log: %s", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "Installing python packages for groupId %s of category %s finished. Log: %s", category, groupId, string(out)) socketclients.BroadcastMessageToUsersWithPermissionAndTopic( diff --git a/modules/logger/logger.go b/modules/logger/logger.go index 05fde8e..24ee475 100644 --- a/modules/logger/logger.go +++ b/modules/logger/logger.go @@ -4,17 +4,17 @@ import ( "fmt" "git.ex.umbach.dev/Alex/roese-utils/rslogger" - "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber" ) -func AddSystemLog(format string, v ...any) { +func AddSystemLog(logType string, format string, v ...any) { go rslogger.LogManagerRequestClient(fiber.MethodPost, rslogger.LogManagerRequestBody{ Type: "system", - Logs: []string{"I " + rslogger.GetTime() + fmt.Sprintf(format, v...)}}) + Logs: []string{logType + rslogger.GetTime() + fmt.Sprintf(format, v...)}}) } -func AddGroupTasksLog(format string, v ...any) { +func AddGroupTasksLog(logType string, format string, v ...any) { go rslogger.LogManagerRequestClient(fiber.MethodPost, rslogger.LogManagerRequestBody{ Type: "grouptasks", - Logs: []string{"I " + rslogger.GetTime() + fmt.Sprintf(format, v...)}}) + Logs: []string{logType + rslogger.GetTime() + fmt.Sprintf(format, v...)}}) } diff --git a/modules/requestclient/requestclient.go b/modules/requestclient/requestclient.go index d864495..0032a22 100644 --- a/modules/requestclient/requestclient.go +++ b/modules/requestclient/requestclient.go @@ -5,6 +5,7 @@ import ( "jannex/admin-dashboard-backend/modules/logger" "strconv" + "git.ex.umbach.dev/Alex/roese-utils/rslogger" "github.com/gofiber/fiber/v2" "github.com/rs/zerolog/log" ) @@ -28,7 +29,7 @@ func InvexApiRequestClient(requestMethod string, url string) (statusCode int, bo if code == 401 { log.Error().Msgf("invex not authorized, code: %d", code) - logger.AddSystemLog("InvexApiRequestClient err: %s statusCode: %s", + logger.AddSystemLog(rslogger.LogTypeInfo, "InvexApiRequestClient err: %s statusCode: %s", "invex not authorized", strconv.Itoa(code)) return code, nil, err @@ -37,7 +38,7 @@ func InvexApiRequestClient(requestMethod string, url string) (statusCode int, bo if code == 404 { log.Error().Msgf("Invex stock item not found, code: %d", code) - logger.AddSystemLog("InvexApiRequestClient err: %s statusCode: %s", + logger.AddSystemLog(rslogger.LogTypeInfo, "InvexApiRequestClient err: %s statusCode: %s", "invex stock item not found", strconv.Itoa(code)) return code, nil, err diff --git a/routers/router/router.go b/routers/router/router.go index be2d432..ad33b42 100644 --- a/routers/router/router.go +++ b/routers/router/router.go @@ -17,6 +17,7 @@ import ( "jannex/admin-dashboard-backend/socketclients" "time" + "git.ex.umbach.dev/Alex/roese-utils/rslogger" "github.com/gofiber/fiber/v2" "gorm.io/gorm" ) @@ -109,7 +110,7 @@ func userApikeyTokenValidation(c *fiber.Ctx) error { // delete api key from database database.DB.Delete(&apiKey) - logger.AddSystemLog("User %s has tried to use one of its api keys, but has no longer permission to do so", + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has tried to use one of its api keys, but has no longer permission to do so", apiKey.UserId) return fiber.ErrUnauthorized @@ -140,7 +141,7 @@ func userApikeyTokenValidation(c *fiber.Ctx) error { }, }) - logger.AddSystemLog("User %s has used one of its api keys", apiKey.UserId) + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has used one of its api keys", apiKey.UserId) return c.Next() } diff --git a/socketclients/socketclients.go b/socketclients/socketclients.go index 6e0e260..de74ae4 100644 --- a/socketclients/socketclients.go +++ b/socketclients/socketclients.go @@ -14,6 +14,7 @@ import ( "strings" "time" + "git.ex.umbach.dev/Alex/roese-utils/rslogger" "git.ex.umbach.dev/Alex/roese-utils/rsutils" "github.com/gofiber/websocket/v2" "github.com/google/uuid" @@ -428,7 +429,7 @@ func UpdateUserProfile(conn *websocket.Conn, changes map[string]interface{}) { // user has changed password - logout all his sessions CloseAndDeleteAllUserConnections(userId) - logger.AddSystemLog("%s has changed his password", userId) + logger.AddSystemLog(rslogger.LogTypeInfo, "%s has changed his password", userId) return } @@ -454,7 +455,7 @@ func UpdateUserProfile(conn *websocket.Conn, changes map[string]interface{}) { }, }) - logger.AddSystemLog("User %s has updated his account with the following changes: %v", userId, rsutils.MarshalJson(updates)) + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has updated his account with the following changes: %v", userId, rsutils.MarshalJson(updates)) } } } @@ -634,7 +635,7 @@ func AdminAreaUpdateRole(conn *websocket.Conn, body map[string]interface{}) { }, }) - logger.AddSystemLog("User %s has updated the role %s with the following changes: %v", + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has updated the role %s with the following changes: %v", conn.Locals("userId").(string), roleId, rsutils.MarshalJson(updates)) } @@ -695,7 +696,7 @@ func AdminAreaMoveRoleToSortingOrder(conn *websocket.Conn, body map[string]inter Body: body, }) - logger.AddSystemLog("User %s has changed the sorting order of role %s to %s", + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has changed the sorting order of role %s to %s", conn.Locals("userId").(string), roleId, strconv.Itoa(newSortingOrder)) } @@ -720,7 +721,7 @@ func AdminAreaDeleteRole(conn *websocket.Conn, body map[string]interface{}) { Body: body, }) - logger.AddSystemLog("User %s has deleted the role %s", conn.Locals("userId").(string), role.Id) + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has deleted the role %s", conn.Locals("userId").(string), role.Id) } func UpdateUserRole(conn *websocket.Conn, userId string, roleId string) { @@ -754,7 +755,7 @@ func UpdateUserRole(conn *websocket.Conn, userId string, roleId string) { }, }) - logger.AddSystemLog("User %s has assigned the role %s to %s", + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has assigned the role %s to %s", conn.Locals("userId").(string), roleId, userId) } @@ -894,7 +895,7 @@ func AllUsersCreateNewUser(conn *websocket.Conn, body map[string]interface{}) { }, }) - logger.AddSystemLog("User %s has created the user %s with the assigned role %s", + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has created the user %s with the assigned role %s", conn.Locals("userId").(string), newUser.Id, roleId) } @@ -935,7 +936,7 @@ func AllUsersDeleteUser(conn *websocket.Conn, userId string) { }, }) - logger.AddSystemLog("User %s has deleted the user %s", + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has deleted the user %s", conn.Locals("userId").(string), userId) } @@ -959,7 +960,7 @@ func AllUsersUserDeactivation(conn *websocket.Conn, userId string, deactivate bo }, }) - logger.AddSystemLog("User %s has changed the deactivation status of user %s to %v", + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has changed the deactivation status of user %s to %v", conn.Locals("userId").(string), userId, strconv.FormatBool(deactivate)) } @@ -978,9 +979,9 @@ func ScannersUpdateScannerUsedByUserId(userId string, scannerId string) { }) if userId != "" { - logger.AddSystemLog("Scanner %s is now used by user %s", scannerId, userId) + logger.AddSystemLog(rslogger.LogTypeInfo, "Scanner %s is now used by user %s", scannerId, userId) } else { - logger.AddSystemLog("Scanner %s is not longer used", scannerId) + logger.AddSystemLog(rslogger.LogTypeInfo, "Scanner %s is not longer used", scannerId) } } @@ -1019,7 +1020,7 @@ func CreateNewUserApiKey(userId string, apiName string) { Body: newApiKey, }) - logger.AddSystemLog("User %s has created an API key", userId) + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has created an API key", userId) } func DeleteUserApiKey(userId string, apiKey string) { @@ -1035,7 +1036,7 @@ func DeleteUserApiKey(userId string, apiKey string) { Body: apiKey, }) - logger.AddSystemLog("User %s has deleted one of its api keys", userId) + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has deleted one of its api keys", userId) } func GetAvailableCategories(userId string) []string { @@ -1124,7 +1125,7 @@ func AddLogManagerServerConnection(userId string, displayName string, address st Body: newConnection, }) - logger.AddSystemLog("User %s has added log manager server connection with id %s, display name %s and address %s", userId, newConnection.Id, displayName, address) + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has added log manager server connection with id %s, display name %s and address %s", userId, newConnection.Id, displayName, address) } func DeleteLogManagerServerConnection(userId string, id string) { @@ -1137,5 +1138,5 @@ func DeleteLogManagerServerConnection(userId string, id string) { Body: id, }) - logger.AddSystemLog("User %s has removed log manager server connection with id %s", userId, id) + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has removed log manager server connection with id %s", userId, id) } diff --git a/socketserver/hub.go b/socketserver/hub.go index 53dec08..d19e3c9 100644 --- a/socketserver/hub.go +++ b/socketserver/hub.go @@ -14,6 +14,7 @@ import ( "jannex/admin-dashboard-backend/socketclients" "time" + "git.ex.umbach.dev/Alex/roese-utils/rslogger" "git.ex.umbach.dev/Alex/roese-utils/rsutils" "github.com/gofiber/websocket/v2" "github.com/google/uuid" @@ -64,7 +65,7 @@ func RunHub() { socketclients.UpdateConnectedUsers(userId) socketclients.UpdateUserSessionsForUser(userId, sessionId) - logger.AddSystemLog("User %v has come online", userId) + logger.AddSystemLog(rslogger.LogTypeInfo, "User %v has come online", userId) case data := <-broadcast: var receivedMessage structs.ReceivedMessage @@ -115,7 +116,7 @@ func RunHub() { go grouptasks.RunGroupTask(groupTaskArgs) - logger.AddGroupTasksLog("Step %s of groupTaskId %s has failed and was started by user %s to try again", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "Step %s of groupTaskId %s has failed and was started by user %s to try again", groupTaskArgs.TaskStepId, groupTaskArgs.GroupTaskId, groupTaskArgs.CreatorUserId) break case utils.ReceivedCmdTaskContinueTaskStep: @@ -132,7 +133,7 @@ func RunHub() { go grouptasks.RunGroupTask(groupTaskArgs) - logger.AddGroupTasksLog("Step %s of groupTaskId %s was continued by user %s", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "Step %s of groupTaskId %s was continued by user %s", groupTaskArgs.TaskStepId, groupTaskArgs.GroupTaskId, groupTaskArgs.CreatorUserId) break case utils.ReceivedCmdReloadGroupTasks: @@ -153,7 +154,7 @@ func RunHub() { grouptasks.ReloadCategoryGroups(category) - logger.AddGroupTasksLog("User %s has reloaded group tasks config of category %s", + logger.AddGroupTasksLog(rslogger.LogTypeInfo, "User %s has reloaded group tasks config of category %s", data.Conn.Locals("userId").(string), category) break case utils.ReceivedCmdTaskLocking: @@ -208,7 +209,7 @@ func RunHub() { Body: role, }) - logger.AddSystemLog("User %s has created the role %s", + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has created the role %s", data.Conn.Locals("userId").(string), role.Id) break @@ -371,7 +372,7 @@ func RunHub() { socketclients.UpdateUserSessionsForUser(userId, sessionId) socketclients.UpdateConnectedUsers(userId) - logger.AddSystemLog("User %s has gone offline", userId) + logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has gone offline", userId) } } }