-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathFilterLogger.js
More file actions
59 lines (52 loc) · 1.94 KB
/
Copy pathFilterLogger.js
File metadata and controls
59 lines (52 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
const { LogManager, LogLevel } = require('@aliceo2/web-ui');
const { isInTestMode } = require('../../utilities/env-utils');
/**
* Logger dedicated to filter-related endpoint access events.
*/
class FilterLogger {
/**
* Creates an instance of FilterLogger.
*/
constructor(silent = isInTestMode()) {
LogManager.configure({ infologger: true });
this._logger = LogManager.getLogger('FILTERING');
this._logLevel = LogLevel.OPERATIONS;
this._silent = silent;
}
/**
* Logs an informational message about endpoint access and applied filters.
*
* @param {object} request the request received at any given endpoint.
* @param {string} endpoint the endpoint that was accessed.
* @param {string|number} id identifier of the user accessing the endpoint.
* @param {Object} [filters={}] filters applied to the request.
* @returns {void}
*/
infoMessage({ path, session: { id }, query = {} }) {
if (this._silent) {
return;
}
const filters = query.filters ?? {};
let message = `Endpoint ${path} was accessed by user ${id} `;
if (!Object.keys(filters).length) {
message += 'without filters';
} else {
message += 'with the following filters:\n';
message += JSON.stringify(filters);
}
this._logger.infoMessage(message, { level: this._logLevel });
}
}
module.exports = new FilterLogger();