lib/amd/src/local/reactive/logger.js

  1. // This file is part of Moodle - http://moodle.org/
  2. //
  3. // Moodle is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // Moodle is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  15. /**
  16. * Default reactive mutations logger class.
  17. *
  18. * This logger is used by default by the StateManager to log mutation feedbacks
  19. * and actions. By default, feedbacks will be displayed as a toast. However, the
  20. * reactive instance can provide alternative loggers to provide advanced logging
  21. * capabilities.
  22. *
  23. * @module core/local/reactive/logger
  24. * @class Logger
  25. * @copyright 2023 Ferran Recio <ferran@moodle.com>
  26. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27. */
  28. /**
  29. * Logger entry structure.
  30. *
  31. * @typedef {object} LoggerEntry
  32. * @property {string} feedbackMessage Feedback message.
  33. */
  34. import {add as addToast} from 'core/toast';
  35. /**
  36. * Default reactive mutations logger class.
  37. * @class Logger
  38. */
  39. export default class Logger {
  40. /**
  41. * Constructor.
  42. */
  43. constructor() {
  44. this._debug = false;
  45. }
  46. /**
  47. * Add a log entry.
  48. * @param {LoggerEntry} entry Log entry.
  49. */
  50. add(entry) {
  51. if (entry.feedbackMessage) {
  52. addToast(entry.feedbackMessage);
  53. }
  54. }
  55. }