Method setLevel() in LoggerManager should be declared static #4279

Open
opened 2026-02-20 16:15:44 -05:00 by deekerman · 0 comments
Owner

Originally created by @Abuelodelanada on GitHub (Apr 30, 2020).

Issue

In include/SugarLogger/LoggerManager.php the methods setLogger() and setLevelMapping() are defined as public static, but the method setLevel() is defined only as public

This leads to an annoying NOTICE in PHP log If you create your own Logger class extending LoggerTemplate.

When creating a custom logger class to, for example, log in a different file the requests to web services, you can have something like this.

class SuiteWSLogger implements LoggerTemplate
{

    public function __construct()
    {
        $config = SugarConfig::getInstance();
        $this->ext = $config->get('logger_ws.file.ext', $this->ext);
        $this->logfile = $config->get('logger_ws.file.name', $this->logfile);
        $this->dateFormat = $config->get('logger_ws.file.dateFormat', $this->dateFormat);
        $this->filesuffix = $config->get('logger_ws.file.suffix', $this->filesuffix);
        $level = $config->get('logger.level');
        $log_dir = $config->get('log_dir', $this->log_dir);
        $this->log_dir = $log_dir . (empty($log_dir)?'':'/');
        unset($config);
        $this->doInitialization();
        LoggerManager::setLogger('webservices', 'SuiteWSLogger');
        LoggerManager::setLevelMapping('webservices', self::$levelMapping[$level]);
        LoggerManager::setLevel('webservices');
    }

So, if for example you run a robo task an annoying message appears:

root@cdb72216b5c8:/tmp/gca# ./vendor/bin/robo help build:theme
Usage:
  build:theme [options]

Options:
      --theme[=THEME]                   [default: ""]
      --color-scheme[=COLOR-SCHEME]     [default: ""]
  -h, --help                           Display this help message
  -q, --quiet                          Do not output any message
  -V, --version                        Display this application version
      --ansi                           Force ANSI output
      --no-ansi                        Disable ANSI output
  -n, --no-interaction                 Do not ask any interactive question
      --simulate                       Run in simulated mode (show what would have happened).
      --progress-delay=PROGRESS-DELAY  Number of seconds before progress bar is displayed in long-running task collections. Default: 2s. [default: 2]
  -D, --define=DEFINE                  Define a configuration item value. (multiple values allowed)
  -v|vv|vvv, --verbose                 Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
  Compile a theme (SASS) based in SuiteP
ERROR: Non-static method LoggerManager::setLevel() should not be called statically
in /tmp/gca/custom/include/SugarLogger/SuiteWSLogger.php:94

Expected Behavior

No annoying messages in php log or in robo tasks

Possible Fix

Define setLevel() as public static

Steps to Reproduce

  1. Create your own Logger class as showed
  2. Run robo

Context

Your Environment

  • SuiteCRM Version used: 7.10.x
  • Browser name and version (e.g. Chrome Version 51.0.2704.63 (64-bit)): Firefox 75
  • Environment name and version (e.g. MySQL, PHP 7): PHP 7.3 / MySQL 8
  • Operating System and version (e.g Ubuntu 16.04): Ubuntu 19.10
Originally created by @Abuelodelanada on GitHub (Apr 30, 2020). <!--- Provide a general summary of the issue in the **Title** above --> <!--- Before you open an issue, please check if a similar issue already exists or has been closed before. ---> <!--- If you have discovered a security risk please report it by emailing security@suitecrm.com. This will be delivered to the product team who handle security issues. Please don't disclose security bugs publicly until they have been handled by the security team. ---> #### Issue <!--- Provide a more detailed introduction to the issue itself, and why you consider it to be a bug --> <!--- Ensure that all code ``` is surrounded ``` by triple back quotes. This can also be done over multiple lines --> In `include/SugarLogger/LoggerManager.php` the methods `setLogger()` and `setLevelMapping()` are defined as `public static`, but the method `setLevel()` is defined only as `public` This leads to an annoying `NOTICE` in PHP log If you create your own Logger class extending `LoggerTemplate`. When creating a custom logger class to, for example, log in a different file the requests to web services, you can have something like this. ```php class SuiteWSLogger implements LoggerTemplate { public function __construct() { $config = SugarConfig::getInstance(); $this->ext = $config->get('logger_ws.file.ext', $this->ext); $this->logfile = $config->get('logger_ws.file.name', $this->logfile); $this->dateFormat = $config->get('logger_ws.file.dateFormat', $this->dateFormat); $this->filesuffix = $config->get('logger_ws.file.suffix', $this->filesuffix); $level = $config->get('logger.level'); $log_dir = $config->get('log_dir', $this->log_dir); $this->log_dir = $log_dir . (empty($log_dir)?'':'/'); unset($config); $this->doInitialization(); LoggerManager::setLogger('webservices', 'SuiteWSLogger'); LoggerManager::setLevelMapping('webservices', self::$levelMapping[$level]); LoggerManager::setLevel('webservices'); } ``` So, if for example you run a `robo` task an annoying message appears: ```bash root@cdb72216b5c8:/tmp/gca# ./vendor/bin/robo help build:theme Usage: build:theme [options] Options: --theme[=THEME] [default: ""] --color-scheme[=COLOR-SCHEME] [default: ""] -h, --help Display this help message -q, --quiet Do not output any message -V, --version Display this application version --ansi Force ANSI output --no-ansi Disable ANSI output -n, --no-interaction Do not ask any interactive question --simulate Run in simulated mode (show what would have happened). --progress-delay=PROGRESS-DELAY Number of seconds before progress bar is displayed in long-running task collections. Default: 2s. [default: 2] -D, --define=DEFINE Define a configuration item value. (multiple values allowed) -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug Help: Compile a theme (SASS) based in SuiteP ERROR: Non-static method LoggerManager::setLevel() should not be called statically in /tmp/gca/custom/include/SugarLogger/SuiteWSLogger.php:94 ``` #### Expected Behavior <!--- Tell us what should happen --> No annoying messages in php log or in robo tasks #### Possible Fix <!--- Not obligatory, but suggest a fix or reason for the bug --> Define `setLevel()` as `public static` #### Steps to Reproduce <!--- Provide a link to a live example, or an unambiguous set of steps to --> <!--- reproduce this bug include code to reproduce, if relevant --> 1. Create your own Logger class as showed 2. Run `robo` #### Context <!--- How has this bug affected you? What were you trying to accomplish? --> <!--- If you feel this should be a low/medium/high priority then please state so --> #### Your Environment <!--- Include as many relevant details about the environment you experienced the bug in --> * SuiteCRM Version used: 7.10.x * Browser name and version (e.g. Chrome Version 51.0.2704.63 (64-bit)): Firefox 75 * Environment name and version (e.g. MySQL, PHP 7): PHP 7.3 / MySQL 8 * Operating System and version (e.g Ubuntu 16.04): Ubuntu 19.10
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SuiteCRM-SuiteCRM#4279
No description provided.