Skip to content

Commit 4e22d71

Browse files
author
NarrowsProjects
committed
feat: create filterLogger
1 parent 571ca62 commit 4e22d71

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

lib/server/Loggers/FilterLogger.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
const { LogManager, LogLevel } = require('@aliceo2/web-ui');
15+
16+
/**
17+
* Logger dedicated to filter-related endpoint access events.
18+
*/
19+
class FilterLogger {
20+
/**
21+
* Creates an instance of FilterLogger.
22+
*/
23+
constructor() {
24+
LogManager.configure({ infologger: true });
25+
this._logger = LogManager.getLogger('FILTERING');
26+
this._logLevel = LogLevel.OPERATIONS;
27+
}
28+
29+
/**
30+
* Logs an informational message about endpoint access and applied filters.
31+
*
32+
* @param {string} endpoint the endpoint that was accessed.
33+
* @param {string|number} userId identifier of the user accessing the endpoint.
34+
* @param {Object} [filters={}] filters applied to the request.
35+
* @returns {void}
36+
*/
37+
infoMessage(endpoint, userId, filters = {}) {
38+
let message = `Endpoint ${endpoint} was accessed by user ${userId} `;
39+
40+
if (!Object.keys(filters).length) {
41+
message += 'without filters';
42+
} else {
43+
message += 'with the following filters:\n';
44+
message += JSON.stringify(filters);
45+
}
46+
47+
this._logger.infoMessage(message, { level: this._logLevel });
48+
}
49+
}
50+
51+
module.exports = new FilterLogger;

lib/server/Loggers/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright CERN and copyright holders of ALICE O2. This software is
4+
* distributed under the terms of the GNU General Public License v3 (GPL
5+
* Version 3), copied verbatim in the file "COPYING".
6+
*
7+
* See http://alice-o2.web.cern.ch/license for full licensing information.
8+
*
9+
* In applying this license CERN does not waive the privileges and immunities
10+
* granted to it by virtue of its status as an Intergovernmental Organization
11+
* or submit itself to any jurisdiction.
12+
*/
13+
14+
const FilterLogger = require('./FilterLogger');
15+
16+
module.exports = {
17+
FilterLogger,
18+
};

0 commit comments

Comments
 (0)