2017-04-28 21:47:07 +08:00
|
|
|
import Logger from '/imports/startup/server/logger';
|
2018-06-15 20:45:58 +08:00
|
|
|
import Users from '/imports/api/users';
|
|
|
|
|
2018-08-02 00:06:49 +08:00
|
|
|
const logClient = function (type, log, fullInfo = {}) {
|
2018-06-15 20:45:58 +08:00
|
|
|
const SERVER_CONN_ID = this.connection.id;
|
|
|
|
const User = Users.findOne({ connectionId: SERVER_CONN_ID });
|
2018-07-26 03:59:14 +08:00
|
|
|
const logContents = { fullInfo };
|
2018-06-15 20:45:58 +08:00
|
|
|
|
|
|
|
if (User) {
|
2019-02-13 04:13:35 +08:00
|
|
|
if ((fullInfo.credentials && User.meetingId === fullInfo.credentials.meetingId)
|
|
|
|
|| ((fullInfo.meetingId && User.meetingId === fullInfo.meetingId))) {
|
2018-07-26 03:59:14 +08:00
|
|
|
logContents.validUser = 'valid';
|
2018-06-20 00:46:59 +08:00
|
|
|
} else {
|
2018-07-26 03:59:14 +08:00
|
|
|
logContents.validUser = 'invalid';
|
2018-06-20 00:46:59 +08:00
|
|
|
}
|
|
|
|
} else {
|
2018-07-26 03:59:14 +08:00
|
|
|
logContents.validUser = 'notFound';
|
2018-06-15 20:45:58 +08:00
|
|
|
}
|
2017-04-28 21:47:07 +08:00
|
|
|
|
2018-09-05 00:56:10 +08:00
|
|
|
const topic = typeof logContents === 'Object' ? logContents.topic : null;
|
2018-06-20 01:36:12 +08:00
|
|
|
|
2018-03-22 03:39:11 +08:00
|
|
|
if (typeof log === 'string' || log instanceof String) {
|
2019-02-13 04:13:35 +08:00
|
|
|
Logger.log({
|
|
|
|
level: type,
|
2019-03-09 04:52:35 +08:00
|
|
|
message: `${topic || 'CLIENT'} LOG: ${log} `,
|
2019-02-13 04:13:35 +08:00
|
|
|
meta: logContents,
|
|
|
|
});
|
2018-03-22 03:39:11 +08:00
|
|
|
} else {
|
2019-02-13 04:13:35 +08:00
|
|
|
Logger.log({
|
|
|
|
level: type,
|
2019-03-09 04:52:35 +08:00
|
|
|
message: `${topic || 'CLIENT'} LOG: ${JSON.stringify(log)} `,
|
2019-02-13 04:13:35 +08:00
|
|
|
meta: logContents,
|
|
|
|
});
|
2018-03-22 03:39:11 +08:00
|
|
|
}
|
2017-06-06 03:12:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
export default logClient;
|