Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9138333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:14:34+00:00 2026-06-17T09:14:34+00:00

We are using zend framework 2 for a new application, i would like to

  • 0

We are using zend framework 2 for a new application, i would like to have the same logging system of Rails or similar, i would like have a log for each request, is possible to do this in Zend?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:14:34+00:00Added an answer on June 17, 2026 at 9:14 am

    It depends what you want to log. If it is just an access log, you should try to use the webserver’s log. The logs from Apache/nginx/IIS etc perform better than you will achieve in your ZF2 app.

    If you need to log inside the ZF2 application, you have two choices. First option is at bootstrap. It’s one of the earliest options you can use, so probably therefore the best. However, you can also look at route or dispatch. Those two events are called during the “run” phase of the application. With these events, you have for example a route match available and therefore you know (or not) if your request did match any controller (or in case you don’t have the match, it’s a 404).

    Some examples. Let’s assume you have a logger configured in the ServiceManager under the logger key. Then to log at bootstrap:

    namespace Application;
    
    class Module
    {
      public function onBootstrap($e)
      {
        $app = $e->getApplication();
        $sm  = $app->getServiceManager();
    
        $logger = $sm->get('logger');
        $logger->debug('Log here!');
      }
    }
    

    Or for example if you wait for route, you attach a listener for the route event:

    namespace Application;
    
    use Zend\Mvc\MvcEvent;
    use Zend\Mvc\Router\RouteMatch;
    
    class Module
    {
      public function onBootstrap($e)
      {
        $app = $e->getApplication();
        $em  = $app->getEventManager();
        $sm  = $app->getServiceManager();
    
        $logger = $sm->get('logger');
        $em->attach(MvcEvent::EVENT_ROUTE, function($e) use ($logger) {
          $match = $e->getRouteMatch();
    
          // No route, this is a 404
          if (!$match instanceof RouteMatch) {
            return;
          }
    
          $logger->debug(sprintf(
            'Route event with route %s',
            $match->getMatchedRouteName()
          ));
        });
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP MVC application using Zend Framework. As presented in the quickstart,
I have been working on a new installation of a Zend Framework application for
I'm creating new application using zend framework with several modules. Can you please advice
I have based my application upon the Zend Framework. I am using Zend_Auth for
I have been building a dynamic form in my Zend Framework application using Jquery
I set up a Zend Framework application using Zend_Tool, but I wanted multiple modules
I'm trying to develop a site using Zend Framework, but i have a problem:
I have search and search but no answer I am using Zend Framework to
I am using Zend Framework and 3rd party application written in php for file
I´m developing an application using Zend Framework 2 and I´m using two select multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.