Skip to content

Commit e74a378

Browse files
authored
Merge pull request #556 from UniversityOfHelsinkiCS/trunk
better logging
2 parents c2d988b + 5ca6fa9 commit e74a378

File tree

10 files changed

+39
-40
lines changed

10 files changed

+39
-40
lines changed

backend/server/controllers/admin.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ module.exports = {
1313
const nonActive = await helper.getInactive(req, res)
1414
const areActive = await helper.getActive(req, res)
1515
res.render('index', {
16-
title: 'Import courses to Labtool from Kurki',
17-
message1: 'Current and upcoming courses',
16+
title: 'Import courses to Labtool from Kurki',
17+
message1: 'Current and upcoming courses',
1818
submessage1: 'Current and upcoming courses from Kurki which are not yet in Labtool database. Click Import to import course to Labtool.',
1919
elseMessage1: 'There are no courses in Kurki to import',
2020
values1: nonActive,
2121
message2: 'Already imported courses',
22-
elseMessage2: 'There are no courses in Labtool.',
22+
elseMessage2: 'There are no courses in Labtool.',
2323
values2: areActive
2424
})
2525
} catch (e) {
26-
logger.error(e)
26+
logger.error('admin page error', { error: e.message })
2727

2828
res.send('errored in controllers/admin/list')
2929
}

backend/server/controllers/assistants.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module.exports = {
7272
})
7373
res.status(200).send(studentInstance)
7474
} catch (e) {
75-
logger.error(e)
75+
logger.error('create assistant error', { error: e.message })
7676
}
7777
},
7878

@@ -83,7 +83,7 @@ module.exports = {
8383
status: undefined,
8484
data: undefined
8585
}
86-
let studentInstanceId = undefined
86+
let studentInstanceId
8787

8888
try {
8989
studentInstanceId = req.params.id
@@ -138,7 +138,7 @@ module.exports = {
138138
})
139139
res.status(200).send(studentsForThisTeacherInstance)
140140
} catch (e) {
141-
logger.error(e)
141+
logger.error('find students by teacher instance error', { error: e.message })
142142
res.status(400).send(e)
143143
}
144144
}

backend/server/controllers/checklists.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module.exports = {
9090
data: req.body
9191
})
9292
} catch (e) {
93-
logger.error(e)
93+
logger.error('checklist creation error', { error: e.message })
9494
res.status(500).send('Unexpected error')
9595
}
9696
},
@@ -122,7 +122,7 @@ module.exports = {
122122
})
123123
}
124124
} catch (e) {
125-
logger.error(e)
125+
logger.error('get checklist error', { error: e.message })
126126
res.status(500).send(e)
127127
}
128128
}

backend/server/controllers/codeReviews.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ module.exports = {
7777
data: req.body
7878
})
7979
} catch (e) {
80-
logger.error('CodeReview bulk insert failed.\n', e)
80+
logger.error('CodeReview bulk insert failed.', { error: e.message })
8181
res.status(500).send('Unexpected error.')
8282
}
8383
},

backend/server/controllers/login.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
try {
2323
const result = request(options, (err, resp, body) => {
2424
if (err) {
25-
logger.error('\nlogin: ', err, 'n')
25+
logger.error('login result error', { error: err.message })
2626
}
2727
if (result.response && result.response.body && result.response.body.username && result.response.body.error !== 'wrong credentials') {
2828
let first
@@ -70,7 +70,7 @@ module.exports = {
7070
}
7171
})
7272
} catch (error) {
73-
logger.error(error)
73+
logger.error('login error', { error: error.message })
7474
res.status(500).send({
7575
error: 'Unexpected error'
7676
})

backend/server/controllers/tags.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ module.exports = {
5252
return
5353
})
5454
.catch(error => {
55-
logger.error(error)
55+
logger.error('tag create/update error', { error: error.message })
5656
res.status(400).send('color did not update')
5757
return
5858
})
@@ -99,16 +99,15 @@ module.exports = {
9999

100100
try {
101101
return Tag.findAll()
102-
.then(tag => {
102+
.then((tag) => {
103103
return res.status(200).send(tag)
104104
})
105-
.catch(error => {
105+
.catch((error) => {
106106
res.status(400).send('et ny saa niitä tageja')
107-
logger.error(error)
107+
logger.error('tag getall error', { error: error.message })
108108
})
109109
} catch (e) {
110110
res.status(400).send('nymmeni jokin pieleen')
111-
return
112111
}
113112
},
114113

@@ -120,7 +119,7 @@ module.exports = {
120119
where: {
121120
userId: req.decoded.id
122121
}
123-
}).then(found => {
122+
}).then((found) => {
124123
if (!found) {
125124
res.status(400).send('you have to be a teacher to do this')
126125
return
@@ -129,7 +128,7 @@ module.exports = {
129128
where: {
130129
id: req.body.studentId
131130
}
132-
}).then(student => {
131+
}).then((student) => {
133132
if (!student) {
134133
res.status(404).send('did not found student with that id')
135134
return
@@ -138,16 +137,16 @@ module.exports = {
138137
where: {
139138
id: req.body.tagId
140139
}
141-
}).then(found => {
142-
if (!found) {
140+
}).then((foundTag) => {
141+
if (!foundTag) {
143142
res.status(404).send('did not find a tag with that id')
144143
}
145144
StudentTag.findOrCreate({
146145
where: {
147146
tagId: req.body.tagId,
148147
studentInstanceId: req.body.studentId
149148
}
150-
}).then(studentTag => {
149+
}).then((studentTag) => {
151150
if (!studentTag) {
152151
return res.status(400).send('tagging did not succeed')
153152
}
@@ -194,7 +193,7 @@ module.exports = {
194193
attributes: ['id', 'name', 'color']
195194
}
196195
]
197-
}).then(student => {
196+
}).then((student) => {
198197
return res.status(200).send(student)
199198
})
200199
})

backend/server/controllers/users.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = {
3030
} else {
3131
User.update({ email: req.body.email }, { where: { id: req.decoded.id } }).then(
3232
User.findById(req.decoded.id)
33-
.then(user => {
33+
.then((user) => {
3434
const returnedUser = {
3535
email: req.body.email,
3636
firsts: user.firsts,
@@ -40,9 +40,9 @@ module.exports = {
4040
}
4141
res.status(201).send(returnedUser)
4242
})
43-
.catch(error => {
43+
.catch((error) => {
4444
res.status(400).send(error)
45-
logger.error(error)
45+
logger.error('user update error', { error: error.message })
4646
})
4747
)
4848
}
@@ -77,7 +77,7 @@ module.exports = {
7777
})
7878
res.status(200).send(users)
7979
} catch (exception) {
80-
logger.error(exception)
80+
logger.error('user list error', { error: exception.message })
8181
res.status(400).send('Unable to send user list')
8282
}
8383
}

backend/server/controllers/weeks.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module.exports = {
6868
res.status(400).send('token verific ation failed')
6969
}
7070
} catch (error) {
71-
logger.error('\nweeks, ', error, '\n')
71+
logger.error('create weeks error', { error: error.message })
7272
}
7373
},
7474
/**
@@ -82,8 +82,8 @@ module.exports = {
8282

8383
return Week.all()
8484
.then(ui => res.status(200).send(ui))
85-
.catch(error => {
86-
logger.error(error)
85+
.catch((error) => {
86+
logger.error('list weeks error', { error: error.message })
8787
res.status(400).send(error)
8888
})
8989
},
@@ -97,16 +97,16 @@ module.exports = {
9797
helper.controller_before_auth_check_action(req, res)
9898

9999
return Week.findById(req.params.id, {})
100-
.then(week => {
100+
.then((week) => {
101101
if (!week) {
102102
return res.status(404).send({
103103
message: 'Teacher Instance not Found'
104104
})
105105
}
106106
return res.status(200).send(week)
107107
})
108-
.catch(error => {
109-
logger.error(error)
108+
.catch((error) => {
109+
logger.error('retrieve weeks error', {error: error.message})
110110
res.status(400).send(error)
111111
})
112112
}

backend/server/helpers/application_helper.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ async function createCourse(body) {
240240
}
241241
return result
242242
} catch (error) {
243-
logger.error(error)
243+
logger.error('createCourse error', { error: error.message })
244244
}
245245
}
246246

@@ -263,7 +263,7 @@ async function getCurrent(req, res) {
263263
})
264264
return result
265265
} catch (error) {
266-
logger.error(error)
266+
logger.error('getCurrent error', { error: error.message })
267267
}
268268
}
269269

@@ -286,6 +286,6 @@ async function getNewer(req, res) {
286286
})
287287
return result
288288
} catch (error) {
289-
logger.error(error)
289+
logger.error('getNewer error', { error: error.message })
290290
}
291291
}

backend/server/helpers/course_instance_helper.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ function checkWebOodi(req, res, user, resolve) {
3939
try {
4040
json = JSON.parse(body)
4141
} catch (e) {
42-
logger.error(e)
42+
logger.error('checkweboodi error', { error: e.message })
4343
resolve('notfound')
4444
return
4545
}
4646
if (json.students.find(student => student === user.studentNumber)) {
4747
resolve('found')
4848
return
4949
} else {
50-
logger.info(json)
51-
logger.info('course registration not found for studentNumber', user.studentNumber)
50+
// logger.info(json)
51+
// logger.info('course registration not found for studentNumber', user.studentNumber)
5252
resolve('notfound')
5353
return
5454
}
@@ -76,7 +76,7 @@ function findByUserStudentInstance(req, res) {
7676
.query(`SELECT * FROM "CourseInstances" JOIN "StudentInstances" ON "CourseInstances"."id" = "StudentInstances"."courseInstanceId" WHERE "StudentInstances"."userId" = ${req.decoded.id}`)
7777
.then(instance => res.status(200).send(instance[0]))
7878
.catch((error) => {
79-
logger.error(error)
79+
logger.error('findByUserStudentInstance error', { error: error.message })
8080
res.status(400).send(error)
8181
})
8282
} else {

0 commit comments

Comments
 (0)