@go-mailer/jarvis 10.6.0 → 10.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/clients/go-flags.js +19 -1
- package/lib/middlewares/logger.js +17 -16
- package/package.json +1 -1
package/lib/clients/go-flags.js
CHANGED
|
@@ -3,6 +3,24 @@ const Env = require('../env')
|
|
|
3
3
|
const BASE_URI = Env.fetch('GO_FLAGS_URI', true)
|
|
4
4
|
const API_KEY = Env.fetch('GO_FLAGS_KEY', true)
|
|
5
5
|
|
|
6
|
+
const sendLog = async ({ environment, service, type, message, log_data }) => {
|
|
7
|
+
await axios.post(
|
|
8
|
+
`${BASE_URI}/api/v1/logs`,
|
|
9
|
+
{
|
|
10
|
+
environment,
|
|
11
|
+
type,
|
|
12
|
+
message,
|
|
13
|
+
service,
|
|
14
|
+
metadata: log_data
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
headers: {
|
|
18
|
+
authorization: `Bearer ${API_KEY}`
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
6
24
|
const verifyFeatureFlag = async (flag_name, criteria = {}, environment = '') => {
|
|
7
25
|
const { error, payload } = (
|
|
8
26
|
await axios.post(
|
|
@@ -24,4 +42,4 @@ const verifyFeatureFlag = async (flag_name, criteria = {}, environment = '') =>
|
|
|
24
42
|
return payload.is_permitted
|
|
25
43
|
}
|
|
26
44
|
|
|
27
|
-
module.exports = { verifyFeatureFlag }
|
|
45
|
+
module.exports = { sendLog, verifyFeatureFlag }
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
* @author Oguntuberu Nathan O. <nateoguns.work@gmail.com>
|
|
3
3
|
**/
|
|
4
4
|
|
|
5
|
+
const { sendLog } = require('../clients/go-flags')
|
|
5
6
|
const Env = require('../env')
|
|
6
7
|
const { randomUUID } = require('crypto')
|
|
8
|
+
const app_name = Env.fetch('APP_NAME', true)
|
|
9
|
+
const env = Env.fetch('NODE_ENV', true)
|
|
7
10
|
|
|
8
11
|
function hashLogData (log = {}) {
|
|
9
12
|
const hashed = JSON.stringify(log).replace(/\w+@/gi, '************')
|
|
@@ -11,7 +14,6 @@ function hashLogData (log = {}) {
|
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
function RequestLogger () {
|
|
14
|
-
const app_name = Env.fetch('APP_NAME', true)
|
|
15
17
|
return (request, response, next) => {
|
|
16
18
|
if (!request.request_id) request.request_id = randomUUID()
|
|
17
19
|
|
|
@@ -54,14 +56,14 @@ function RequestLogger () {
|
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
log.error = payload ? payload.error : statusMessage
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
let log_type = 'info'
|
|
60
|
+
let message = 'Success'
|
|
61
|
+
if (log.error) {
|
|
62
|
+
log_type = 'error'
|
|
63
|
+
message = log.error
|
|
64
|
+
sendLog({ type: log_type, service: app_name, environment: env, message: message, log_data: log })
|
|
65
|
+
}
|
|
63
66
|
|
|
64
|
-
// logtail.flush();
|
|
65
67
|
console.log(pathname, hashLogData({ status_code: log.status_code, request_id: log.request_id }))
|
|
66
68
|
})
|
|
67
69
|
|
|
@@ -75,14 +77,13 @@ class ProcessLogger {
|
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
error (error, method = 'unspecified_method', params = {}) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// logtail.flush();
|
|
80
|
+
sendLog({
|
|
81
|
+
type: 'error',
|
|
82
|
+
service: app_name,
|
|
83
|
+
environment: env,
|
|
84
|
+
message: error.message,
|
|
85
|
+
log_data: { ...params, stack: error.stack }
|
|
86
|
+
})
|
|
86
87
|
console.log(`${this.service}:${method}:${error.message}`, params, error.stack)
|
|
87
88
|
}
|
|
88
89
|
|