src/Application.php
private function setupLogging()
    {
        $test = defined('WEDETO_TEST') && WEDETO_TEST === 1 ? 'test' : '';

        $root_logger = Logger::getLogger();
        $root_logger->setLevel(LogLevel::INFO);

        if ($this->path_config->log)
        {
            $logfile = $this->path_config->log . '/wedeto' . $test . '.log';
            $root_logger->addLogWriter(new FileWriter($logfile, LogLevel::DEBUG));
        }

        // Set up logger based on ini file
        if ($this->config->has('log', Type::ARRAY))
        {
            foreach ($this->config['log'] as $logname => $level)
            {
                if ($logname === "writer")
                {
                    foreach ($level as $logname => $parameters)
                    {
                        $logger = Logger::getLogger($logname);
                        $parameters = str_replace('{LOGDIR}', $this->path_config->log, $parameters);
                        $parameters = explode(';', $parameters);

                        $class = array_shift($parameters);
                        if (!class_exists($class))
                            throw new \DomainException("Invalid logger class: $class");

                        $refl = new \ReflectionClass($class);
                        $writer = $refl->newInstanceArgs($parameters);

                        if (!($writer instanceof AbstractWriter))
                            throw new \DomainException("Class $class is not a log writer");

                        $logger->addLogWriter($writer);
                    }
                    continue;
                }
                
                $logger = Logger::getLogger($logname);
                $level = strtolower($level);

                try
                {
                    $logger->setLevel($level);
                }
                catch (\DomainException $e)
                {
                    self::$logger->error("Failed to set log level for {0} to {1}: {2}", [$logname, $level, $e->getMessage()]);
                }
            }
        }

        // Load the configuration file
        // Attach the dev logger when dev-mode is enabled
        if ($this->dev)
        {
            $devlogger = new MemLogWriter(LogLevel::DEBUG);
            $root_logger->addLogWriter($devlogger);
        }

        // Log beginning of request handling
        if (isset($_SERVER['REQUEST_URI']))
        {
            self::$logger->debug(
                "*** Starting processing for {0} request to {1}", 
                [$_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']]
            );
        }

        // Change settings for CLI
        if (Request::cli())
        {
            $limit = (int)$this->config->dget('cli', 'memory_limit', 1024);
            ini_set('memory_limit', $limit . 'M');
            ini_set('max_execution_time', 0);

            ini_set('display_errors', 1);
        }
        else
            ini_set('display_errors', 0);
    }
private function setupLogging()
    {
        $test = defined('WEDETO_TEST') && WEDETO_TEST === 1 ? 'test' : '';

        $root_logger = Logger::getLogger();
        $root_logger->setLevel(LogLevel::INFO);

        if ($this->path_config->log)
        {
            $logfile = $this->path_config->log . '/wedeto' . $test . '.log';
            $root_logger->addLogWriter(new FileWriter($logfile, LogLevel::DEBUG));
        }

        // Set up logger based on ini file
        if ($this->config->has('log', Type::ARRAY))
        {
            foreach ($this->config['log'] as $logname => $level)
            {
                if ($logname === "writer")
                {
                    foreach ($level as $logname => $parameters)
                    {
                        $logger = Logger::getLogger($logname);
                        $parameters = str_replace('{LOGDIR}', $this->path_config->log, $parameters);
                        $parameters = explode(';', $parameters);

                        $class = array_shift($parameters);
                        if (!class_exists($class))
                            throw new \DomainException("Invalid logger class: $class");

                        $refl = new \ReflectionClass($class);
                        $writer = $refl->newInstanceArgs($parameters);

                        if (!($writer instanceof AbstractWriter))
                            throw new \DomainException("Class $class is not a log writer");

                        $logger->addLogWriter($writer);
                    }
                    continue;
                }
                
                $logger = Logger::getLogger($logname);
                $level = strtolower($level);

                try
                {
                    $logger->setLevel($level);
                }
                catch (\DomainException $e)
                {
                    self::$logger->error("Failed to set log level for {0} to {1}: {2}", [$logname, $level, $e->getMessage()]);
                }
            }
        }

        // Load the configuration file
        // Attach the dev logger when dev-mode is enabled
        if ($this->dev)
        {
            $devlogger = new MemLogWriter(LogLevel::DEBUG);
            $root_logger->addLogWriter($devlogger);
        }

        // Log beginning of request handling
        if (isset($_SERVER['REQUEST_URI']))
        {
            self::$logger->debug(
                "*** Starting processing for {0} request to {1}", 
                [$_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']]
            );
        }

        // Change settings for CLI
        if (Request::cli())
        {
            $limit = (int)$this->config->dget('cli', 'memory_limit', 1024);
            ini_set('memory_limit', $limit . 'M');
            ini_set('max_execution_time', 0);

            ini_set('display_errors', 1);
        }
        else
            ini_set('display_errors', 0);
    }
private function setupLogging ( ) { $ test = defined ( 'WEDETO_TEST' ) && WEDETO_TEST === 1 ? 'test' : '' ; $ root_logger = Logger :: getLogger ( ) ; $ root_logger -> setLevel ( LogLevel :: INFO ) ; if ( $ this -> path_config -> log ) { $ logfile = $ this -> path_config -> log . '/wedeto' . $ test . '.log' ; $ root_logger -> addLogWriter ( new FileWriter ( $ logfile , LogLevel :: DEBUG ) ) ; } // Set up logger based on ini file if ( $ this -> config -> has ( 'log' , Type :: ARRAY ) ) { foreach ( $ this -> config [ 'log' ] as $ logname => $ level ) { if ( $ logname === "writer" ) { foreach ( $ level as $ logname => $ parameters ) { $ logger = Logger :: getLogger ( $ logname ) ; $ parameters = str_replace ( '{LOGDIR}' , $ this -> path_config -> log , $ parameters ) ; $ parameters = explode ( ';' , $ parameters ) ; $ class = array_shift ( $ parameters ) ; if ( ! class_exists ( $ class ) ) throw new \ DomainException ( "Invalid logger class: $class" ) ; $ refl = new \ ReflectionClass ( $ class ) ; $ writer = $ refl -> newInstanceArgs ( $ parameters ) ; if ( ! ( $ writer instanceof AbstractWriter ) ) throw new \ DomainException ( "Class $class is not a log writer" ) ; $ logger -> addLogWriter ( $ writer ) ; } continue ; } $ logger = Logger :: getLogger ( $ logname ) ; $ level = strtolower ( $ level ) ; try { $ logger -> setLevel ( $ level ) ; } catch ( \ DomainException $ e ) { self :: $ logger -> error ( "Failed to set log level for {0} to {1}: {2}" , [ $ logname , $ level , $ e -> getMessage ( ) ] ) ; } } } // Load the configuration file // Attach the dev logger when dev-mode is enabled if ( $ this -> dev ) { $ devlogger = new MemLogWriter ( LogLevel :: DEBUG ) ; $ root_logger -> addLogWriter ( $ devlogger ) ; } // Log beginning of request handling if ( isset ( $ _SERVER [ 'REQUEST_URI' ] ) ) { self :: $ logger -> debug ( "*** Starting processing for {0} request to {1}" , [ $ _SERVER [ 'REQUEST_METHOD' ] , $ _SERVER [ 'REQUEST_URI' ] ] ) ; } // Change settings for CLI if ( Request :: cli ( ) ) { $ limit = ( int ) $ this -> config -> dget ( 'cli' , 'memory_limit' , 1024 ) ; ini_set ( 'memory_limit' , $ limit . 'M' ) ; ini_set ( 'max_execution_time' , 0 ) ; ini_set ( 'display_errors' , 1 ) ; } else ini_set ( 'display_errors' , 0 ) ; }
Helper method to set up logging based on the application configuration file.
Helper method to set up logging based on the application configuration file .