Skip to content

Commit

Permalink
Merge pull request #11820 from iskipu/fix_logging_module
Browse files Browse the repository at this point in the history
Fix issues with Logging module ('kolibri.lib.logging')
  • Loading branch information
rtibbles authored Feb 23, 2024
2 parents 017af53 + f1807ac commit 3a28d76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions kolibri/core/assets/src/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,31 @@

import loglevel from 'loglevel';

const console = global.console;

class Logger {
constructor(loggerName) {
this.loggerName = loggerName;
this.logger = loglevel.getLogger(loggerName);
this.setMessagePrefix();
Object.keys(loglevel.levels).forEach(methodName => {
const name = methodName.toLowerCase();
const logFunction = this.logger[name];
if (logFunction) {
this[name] = logFunction.bind(console, this.messagePrefix(name));
this[name] = param => {
return this.logger[name](param);
};
}
});
}

messagePrefix(type) {
return `[${type.toUpperCase()}: ${this.loggerName}]`;
setMessagePrefix() {
var originalFactory = this.logger.methodFactory;
this.logger.methodFactory = function(methodName, logLevel, loggerName) {
var rawMethod = originalFactory(methodName, logLevel, loggerName);
return function(message) {
rawMethod(`[${methodName.toUpperCase()}: ${loggerName}] ` + message);
};
};
this.logger.setLevel(this.logger.getLevel());
}

setLevel(level, persist) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
// if we only include one of the keys for the extra_settings object
client({ method: 'GET', url: this.settingsUrl })
.then(({ data }) => {
logging.log('mounted', isMetered);
logging.log(data);
logging.info('mounted', isMetered);
logging.info(data);
this.extra_settings = data.extra_settings;
this.selected = this.extra_settings.allow_download_on_metered_connection
? Options.USE_METERED
Expand Down

0 comments on commit 3a28d76

Please sign in to comment.