Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OGUI-1452] Rename Log to Logger #2493

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Control/test/lib/common/mocha-role-enum.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

const assert = require('assert');
const {Role, isRoleSufficient} = require("../../../lib/common/role.enum");
const {Role, isRoleSufficient} = require('../../../lib/common/role.enum');

describe('`Role Enum` test suite, needed to ensure no change in Roles hierarchy', () => {
it('should successfully return the hierarchy of roles', () => {
Expand Down
8 changes: 4 additions & 4 deletions Framework/Backend/db/mysql.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* 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 mysql = require('mysql');
const assert = require('assert');
const Log =require('./../log/Log.js');
const {Logger} = require('./../log/Logger.js');

/**
* MySQL pool wrapper
Expand All @@ -39,7 +39,7 @@ class MySQL {
config.timeout = (!config.timeout) ? 30000 : config.timeout;

this.config = config;
this.log = new Log(`${process.env.npm_config_log_label ?? 'framework'}/mysql`);
this.log = new Logger(`${process.env.npm_config_log_label ?? 'framework'}/mysql`);
this.pool = mysql.createPool(config);
}

Expand Down Expand Up @@ -72,7 +72,7 @@ class MySQL {
this.pool.query({
sql: query,
timeout: this.config.timeout,
values: parameters
values: parameters,
}, (error, results) => {
if (error) {
reject(new Error(this.errorHandler(error)));
Expand Down
21 changes: 11 additions & 10 deletions Framework/Backend/http/openid.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@
* 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 {Issuer, generators, custom} = require('openid-client');
const assert = require('assert');
const Log =require('./../log/Log.js');
const {Logger} = require('./../log/Logger.js');

/**
* Authenticates and authorises users via OpenID Connect (new CERN SSO).
* @author Adam Wegrzynek <[email protected]>
*/
class OpenId {
/**
* Sets up OpenID Connect based on passed config
* @param {object} config - id, secret, well_known, redirect_uri
*/
* Sets up OpenID Connect based on passed config
* @param {object} config - id, secret, well_known, redirect_uri
*/
constructor(config) {
assert(config.id, 'Missing config value: id');
assert(config.secret, 'Missing config value: secret');
Expand All @@ -34,10 +34,10 @@ class OpenId {
this.config = config;
this.code_verifier = generators.codeVerifier();
custom.setHttpOptionsDefaults({
timeout: config.timeout
timeout: config.timeout,
});

this.log = new Log(`${process.env.npm_config_log_label ?? 'framework'}/openid`);
this.log = new Logger(`${process.env.npm_config_log_label ?? 'framework'}/openid`);
}

/**
Expand All @@ -54,7 +54,7 @@ class OpenId {
redirect_uris: [this.config.redirect_uri],
response_types: ['code'],
id_token_signed_response_alg: 'RS256',
token_endpoint_auth_method: 'client_secret_basic'
token_endpoint_auth_method: 'client_secret_basic',
});
this.log.info('Client initialised');
resolve();
Expand All @@ -76,7 +76,7 @@ class OpenId {
scope: 'openid',
code_challenge: codeChallenge,
code_challenge_method: 'S256',
state: state
state: state,
});
}

Expand All @@ -89,9 +89,10 @@ class OpenId {
const params = this.client.callbackParams(req);
delete params.state;
const checks = {
code_verifier: this.code_verifier
code_verifier: this.code_verifier,
};
return this.client.callback(this.config.redirect_uri, params, checks);
}
}

module.exports = OpenId;
4 changes: 2 additions & 2 deletions Framework/Backend/http/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const http = require('http');
const https = require('https');
const express = require('express');
const helmet = require('helmet');
const Log = require('./../log/Log.js');
const {Logger} = require('../log/Logger');
const O2TokenService = require('./../services/O2TokenService.js');
const OpenId = require('./openid.js');
const path = require('path');
Expand Down Expand Up @@ -76,7 +76,7 @@ class HttpServer {
this.listen();
}

this.log = new Log(`${process.env.npm_config_log_label ?? 'framework'}/server`);
this.log = new Logger(`${process.env.npm_config_log_label ?? 'framework'}/server`);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion Framework/Backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ const InfoLoggerReceiver = require('./log/InfoLoggerReceiver.js');
const InfoLoggerSender = require('./log/InfoLoggerSender.js');
const Jira = require('./services/jira.js');
const O2TokenService = require('./services/O2TokenService.js');
const Log = require('./log/Log.js');
const {Logger} = require('./log/Logger.js');
/**
* @deprecated use {Logger} instead
* @type {Logger}
*/
const Log = Logger;
const MySQL = require('./db/mysql.js');
const NotificationService = require('./services/notification.js');
const WebSocket = require('./websocket/server.js');
Expand All @@ -41,6 +46,7 @@ exports.InfoLoggerReceiver = InfoLoggerReceiver;
exports.InfoLoggerSender = InfoLoggerSender;
exports.Jira = Jira;
exports.O2TokenService = O2TokenService;
exports.Logger = Logger;
exports.Log = Log;
exports.MySQL = MySQL;
exports.NotificationService = NotificationService;
Expand Down
6 changes: 3 additions & 3 deletions Framework/Backend/log/InfoLoggerReceiver.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

const net = require('net');
const EventEmitter = require('events');
const Log = require('./Log.js');
const {Logger} = require('./Logger');

const protocols = require('./infologger-protocols.js');

/**
/**
* @class InfoLoggerReceiver
* Connects to server
* Stream data
Expand All @@ -38,7 +38,7 @@ class InfoLoggerReceiver extends EventEmitter {

this.isConnected = false;

this.log = new Log(`${process.env.npm_config_log_label ?? 'framework'}/ilreceiver`);
this.log = new Logger(`${process.env.npm_config_log_label ?? 'framework'}/ilreceiver`);
}

/**
Expand Down
21 changes: 11 additions & 10 deletions Framework/Backend/log/Log.js → Framework/Backend/log/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* 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 WinstonWrapper = require('./WinstonWrapper.js');
const InfoLoggerSender = require('./InfoLoggerSender.js');
Expand All @@ -29,7 +29,7 @@ let infologger = null;
* Handles logging, prints out in console, saves to file or sends to central InfoLogger instance
* @author Adam Wegrzynek <[email protected]>
*/
class Log {
class Logger {
/**
* Sets the label and constructs default winston instance
* @constructor
Expand All @@ -47,7 +47,7 @@ class Log {
/**
* Method to allow clients to configure Log instance to make use:
* * WinstonWrapper together with a file
* * InfoLoggerSender
* * InfoLoggerSender
* @param {JSON} config - object expected to contain winston and infoLoggerSender configurations
*/
static configure(config) {
Expand Down Expand Up @@ -76,11 +76,12 @@ class Log {
winston.instance.info({message, label: this.label});

const log = InfoLoggerMessage.fromJSON({
severity: 'Info',
message, level, system, facility, partition, run, errorSource
severity: 'Info',
message, level, system, facility, partition, run, errorSource,
});
infologger?.sendMessage(log);
}

/**
* @deprecated
* Information severity log
Expand All @@ -102,8 +103,8 @@ class Log {
winston.instance.warn({message, label: this.label});

const log = InfoLoggerMessage.fromJSON({
severity: 'Warning',
message, level, system, facility, partition, run, errorSource
severity: 'Warning',
message, level, system, facility, partition, run, errorSource,
});
infologger?.sendMessage(log);
}
Expand All @@ -129,8 +130,8 @@ class Log {
winston.instance.error({message, label: this.label});

const log = InfoLoggerMessage.fromJSON({
severity: 'Error',
message, level, system, facility, partition, run, errorSource
severity: 'Error',
message, level, system, facility, partition, run, errorSource,
});
infologger?.sendMessage(log);
}
Expand All @@ -156,4 +157,4 @@ class Log {
}
}

module.exports = Log;
module.exports.Logger = Logger;
4 changes: 2 additions & 2 deletions Framework/Backend/services/jira.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

const https = require('https');
const Log = require('./../log/Log.js');
const {Logger} = require('../log/Logger');

/**
* Handles creating JIRA issues
Expand Down Expand Up @@ -44,7 +44,7 @@ class Jira {
bug: 1
};

this.log = new Log(`${process.env.npm_config_log_label ?? 'framework'}/jira`);
this.log = new Logger(`${process.env.npm_config_log_label ?? 'framework'}/jira`);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Framework/Backend/services/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

const { Kafka, logLevel } = require('kafkajs')
const WebSocketMessage = require('../websocket/message.js');
const Log = require('./../log/Log.js');
const {Logger} = require('../log/Logger');

/**
* Gateway for all Kafka notification service
Expand All @@ -25,7 +25,7 @@ class NotificationService {
* @param {object} config Config with list of Kafka brokers
*/
constructor(config) {
this.log = new Log(`${process.env.npm_config_log_label ?? 'framework'}/kafka`);
this.log = new Logger(`${process.env.npm_config_log_label ?? 'framework'}/kafka`);
if (!config) {
this.log.warn('Missing configuration');
return;
Expand Down
8 changes: 4 additions & 4 deletions Framework/Backend/test/log/mocha-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ const fs = require('fs');

const config = require('../config.js');

const Log = require('../../log/Log.js');
const InfoLoggerReceiver = require('../../log/InfoLoggerReceiver.js');
const {Logger} = require('../../log/Logger');

describe('Logging via WinstonWrapper', () => {
it('should successfully instantiate Log class and generate error file (winston)', (done) => {
Log.configure(config.log);
const logger = new Log('test/winston');
Logger.configure(config.log);

const logger = new Logger('test/winston');
logger.error('Test error winston');
setTimeout(() => {
assert.ok(fs.existsSync('./Backend/test/log/error.log'));
Expand Down
12 changes: 7 additions & 5 deletions Framework/Backend/websocket/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
* 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 WebSocketServer = require('ws').Server;
const url = require('url');
const Log = require('./../log/Log.js');
const WebSocketMessage = require('./message.js');
const {Logger} = require('../log/Logger');

/**
* It represents WebSocket server (RFC 6455).
Expand All @@ -33,7 +33,7 @@ class WebSocket {
this.server = new WebSocketServer({server: httpsServer.getServer, clientTracking: true});
this.server.on('connection', (client, request) => this.onconnection(client, request));

this.log = new Log(`${process.env.npm_config_log_label ?? 'framework'}/ws`);
this.log = new Logger(`${process.env.npm_config_log_label ?? 'framework'}/ws`);
this.log.info('Server started');

this.callbackArray = [];
Expand Down Expand Up @@ -79,7 +79,7 @@ class WebSocket {
reject(error);
return;
}

// Transfer decoded JWT data to request
Object.assign(req, data);
this.log.debug(`ID ${data.id} Processing "${req.getCommand()}"`);
Expand Down Expand Up @@ -158,7 +158,8 @@ class WebSocket {
}, (failed) => {
// 7. If parsing message fails
client.send(JSON.stringify(failed.json));
}).catch((error) => {
})
.catch((error) => {
this.log.warn(`ID ${client.id} ${error.name} : ${error.message}`);
client.close(1008);
});
Expand Down Expand Up @@ -226,4 +227,5 @@ class WebSocket {
this.log.debug(`Unfiltered broadcast ${message.getCommand()}/${message.getCode()}`);
}
}

module.exports = WebSocket;
Loading