How we can print array variable in log file of Magento 2?How to print array in magento 2?How to print array contents in log file?Data.php file function log()Magento 2: Create custom log fileHow to print array in magento 2?I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?main.CRITICAL: Plugin class doesn't existWhy Getting categories and names on product view page Magento 2 fails?Magento 2.1 Create a filter in the product grid by new attributeMagento 2.2.5: Add, Update and Delete existing products Custom Optionsmagento 2 how to print log

Why are only specific transaction types accepted into the mempool?

Why is the design of haulage companies so “special”?

Do airline pilots ever risk not hearing communication directed to them specifically, from traffic controllers?

N.B. ligature in Latex

How can bays and straits be determined in a procedurally generated map?

Is the month field really deprecated?

Example of a relative pronoun

Download, install and reboot computer at night if needed

What do you call something that goes against the spirit of the law, but is legal when interpreting the law to the letter?

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

How can the DM most effectively choose 1 out of an odd number of players to be targeted by an attack or effect?

Why is "Reports" in sentence down without "The"

Why Is Death Allowed In the Matrix?

Email Account under attack (really) - anything I can do?

Prevent a directory in /tmp from being deleted

Do Phineas and Ferb ever actually get busted in real time?

Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?

What are these boxed doors outside store fronts in New York?

"You are your self first supporter", a more proper way to say it

What is the command to reset a PC without deleting any files

declaring a variable twice in IIFE

If Manufacturer spice model and Datasheet give different values which should I use?

Is it possible to do 50 km distance without any previous training?

Question about Goedel's incompleteness Proof



How we can print array variable in log file of Magento 2?


How to print array in magento 2?How to print array contents in log file?Data.php file function log()Magento 2: Create custom log fileHow to print array in magento 2?I created a custom module ,but getting error, not able to figure out what the error is about. How to get out of this error?main.CRITICAL: Plugin class doesn't existWhy Getting categories and names on product view page Magento 2 fails?Magento 2.1 Create a filter in the product grid by new attributeMagento 2.2.5: Add, Update and Delete existing products Custom Optionsmagento 2 how to print log






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








12















I am trying to print array variable contents into a log file.



In Magento 1, it was possible using Mage::log(print_r($arr, 1), null, 'logfile.log');



For Magento 2, in class file I have written following code:



protected $_logger;

public function __construct(PsrLogLoggerInterface $logger)
$this->_logger = $logger;



private function getValuesAsHtmlList(MagentoFrameworkObject $object)
$options = $this->getOptions($object);
//$this->_logger->addDebug($options );
$this->_logger->log(100,null,$options);



When I execute the code after clearing the cache, Debug.log & system.log files are not showing the array contents.



Please share if anyone has any idea about it.










share|improve this question






























    12















    I am trying to print array variable contents into a log file.



    In Magento 1, it was possible using Mage::log(print_r($arr, 1), null, 'logfile.log');



    For Magento 2, in class file I have written following code:



    protected $_logger;

    public function __construct(PsrLogLoggerInterface $logger)
    $this->_logger = $logger;



    private function getValuesAsHtmlList(MagentoFrameworkObject $object)
    $options = $this->getOptions($object);
    //$this->_logger->addDebug($options );
    $this->_logger->log(100,null,$options);



    When I execute the code after clearing the cache, Debug.log & system.log files are not showing the array contents.



    Please share if anyone has any idea about it.










    share|improve this question


























      12












      12








      12


      2






      I am trying to print array variable contents into a log file.



      In Magento 1, it was possible using Mage::log(print_r($arr, 1), null, 'logfile.log');



      For Magento 2, in class file I have written following code:



      protected $_logger;

      public function __construct(PsrLogLoggerInterface $logger)
      $this->_logger = $logger;



      private function getValuesAsHtmlList(MagentoFrameworkObject $object)
      $options = $this->getOptions($object);
      //$this->_logger->addDebug($options );
      $this->_logger->log(100,null,$options);



      When I execute the code after clearing the cache, Debug.log & system.log files are not showing the array contents.



      Please share if anyone has any idea about it.










      share|improve this question
















      I am trying to print array variable contents into a log file.



      In Magento 1, it was possible using Mage::log(print_r($arr, 1), null, 'logfile.log');



      For Magento 2, in class file I have written following code:



      protected $_logger;

      public function __construct(PsrLogLoggerInterface $logger)
      $this->_logger = $logger;



      private function getValuesAsHtmlList(MagentoFrameworkObject $object)
      $options = $this->getOptions($object);
      //$this->_logger->addDebug($options );
      $this->_logger->log(100,null,$options);



      When I execute the code after clearing the cache, Debug.log & system.log files are not showing the array contents.



      Please share if anyone has any idea about it.







      magento2 log






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jun 24 '16 at 9:13









      Tine

      5117




      5117










      asked Nov 7 '15 at 13:27









      Praful RajputPraful Rajput

      2,84472246




      2,84472246




















          3 Answers
          3






          active

          oldest

          votes


















          15














          Suppose your array is



          $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));



          then you have to write below code to write proper array format in your log file



          $this->_logger->log(100,print_r($a,true));


          It will print in you log file



          [2015-11-09 06:58:27] main.DEBUG: Array
          (
          [a] => apple
          [b] => banana
          [c] => Array
          (
          [0] => x
          [1] => y
          [2] => z
          )

          )
          "is_exception":false []





          share|improve this answer






























            9














            See declaration of log method



            public function PsrLogLoggerInterface::log($level, $message, array $context = array());


            So, you need code like



            $this->_logger->log(100, json_encode($options));





            share|improve this answer























            • I'd print_r($options, true) myself instead of json encoding. But preferences o/

              – Barry Carlyon
              Nov 8 '15 at 16:05






            • 4





              better yet: $this->_logger->debug(json_encode($options));

              – nevvermind
              Nov 9 '15 at 22:50


















            0














            protected $_logger;

            public function __construct(PsrLogLoggerInterface $logger)
            $this->_logger = $logger;


            public function logs()

            $this->_logger->log($level,'errorlog1234', array( array('test1'=>'123', 'test2' => '456'), array('a'=>'b') ));




            Try This it will print array.
            Tested !






            share|improve this answer























              Your Answer








              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "479"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: false,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f89267%2fhow-we-can-print-array-variable-in-log-file-of-magento-2%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              15














              Suppose your array is



              $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));



              then you have to write below code to write proper array format in your log file



              $this->_logger->log(100,print_r($a,true));


              It will print in you log file



              [2015-11-09 06:58:27] main.DEBUG: Array
              (
              [a] => apple
              [b] => banana
              [c] => Array
              (
              [0] => x
              [1] => y
              [2] => z
              )

              )
              "is_exception":false []





              share|improve this answer



























                15














                Suppose your array is



                $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));



                then you have to write below code to write proper array format in your log file



                $this->_logger->log(100,print_r($a,true));


                It will print in you log file



                [2015-11-09 06:58:27] main.DEBUG: Array
                (
                [a] => apple
                [b] => banana
                [c] => Array
                (
                [0] => x
                [1] => y
                [2] => z
                )

                )
                "is_exception":false []





                share|improve this answer

























                  15












                  15








                  15







                  Suppose your array is



                  $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));



                  then you have to write below code to write proper array format in your log file



                  $this->_logger->log(100,print_r($a,true));


                  It will print in you log file



                  [2015-11-09 06:58:27] main.DEBUG: Array
                  (
                  [a] => apple
                  [b] => banana
                  [c] => Array
                  (
                  [0] => x
                  [1] => y
                  [2] => z
                  )

                  )
                  "is_exception":false []





                  share|improve this answer













                  Suppose your array is



                  $a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));



                  then you have to write below code to write proper array format in your log file



                  $this->_logger->log(100,print_r($a,true));


                  It will print in you log file



                  [2015-11-09 06:58:27] main.DEBUG: Array
                  (
                  [a] => apple
                  [b] => banana
                  [c] => Array
                  (
                  [0] => x
                  [1] => y
                  [2] => z
                  )

                  )
                  "is_exception":false []






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 9 '15 at 6:15









                  Keyur ShahKeyur Shah

                  13.3k24165




                  13.3k24165























                      9














                      See declaration of log method



                      public function PsrLogLoggerInterface::log($level, $message, array $context = array());


                      So, you need code like



                      $this->_logger->log(100, json_encode($options));





                      share|improve this answer























                      • I'd print_r($options, true) myself instead of json encoding. But preferences o/

                        – Barry Carlyon
                        Nov 8 '15 at 16:05






                      • 4





                        better yet: $this->_logger->debug(json_encode($options));

                        – nevvermind
                        Nov 9 '15 at 22:50















                      9














                      See declaration of log method



                      public function PsrLogLoggerInterface::log($level, $message, array $context = array());


                      So, you need code like



                      $this->_logger->log(100, json_encode($options));





                      share|improve this answer























                      • I'd print_r($options, true) myself instead of json encoding. But preferences o/

                        – Barry Carlyon
                        Nov 8 '15 at 16:05






                      • 4





                        better yet: $this->_logger->debug(json_encode($options));

                        – nevvermind
                        Nov 9 '15 at 22:50













                      9












                      9








                      9







                      See declaration of log method



                      public function PsrLogLoggerInterface::log($level, $message, array $context = array());


                      So, you need code like



                      $this->_logger->log(100, json_encode($options));





                      share|improve this answer













                      See declaration of log method



                      public function PsrLogLoggerInterface::log($level, $message, array $context = array());


                      So, you need code like



                      $this->_logger->log(100, json_encode($options));






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Nov 7 '15 at 13:52









                      KAndyKAndy

                      16.1k23245




                      16.1k23245












                      • I'd print_r($options, true) myself instead of json encoding. But preferences o/

                        – Barry Carlyon
                        Nov 8 '15 at 16:05






                      • 4





                        better yet: $this->_logger->debug(json_encode($options));

                        – nevvermind
                        Nov 9 '15 at 22:50

















                      • I'd print_r($options, true) myself instead of json encoding. But preferences o/

                        – Barry Carlyon
                        Nov 8 '15 at 16:05






                      • 4





                        better yet: $this->_logger->debug(json_encode($options));

                        – nevvermind
                        Nov 9 '15 at 22:50
















                      I'd print_r($options, true) myself instead of json encoding. But preferences o/

                      – Barry Carlyon
                      Nov 8 '15 at 16:05





                      I'd print_r($options, true) myself instead of json encoding. But preferences o/

                      – Barry Carlyon
                      Nov 8 '15 at 16:05




                      4




                      4





                      better yet: $this->_logger->debug(json_encode($options));

                      – nevvermind
                      Nov 9 '15 at 22:50





                      better yet: $this->_logger->debug(json_encode($options));

                      – nevvermind
                      Nov 9 '15 at 22:50











                      0














                      protected $_logger;

                      public function __construct(PsrLogLoggerInterface $logger)
                      $this->_logger = $logger;


                      public function logs()

                      $this->_logger->log($level,'errorlog1234', array( array('test1'=>'123', 'test2' => '456'), array('a'=>'b') ));




                      Try This it will print array.
                      Tested !






                      share|improve this answer



























                        0














                        protected $_logger;

                        public function __construct(PsrLogLoggerInterface $logger)
                        $this->_logger = $logger;


                        public function logs()

                        $this->_logger->log($level,'errorlog1234', array( array('test1'=>'123', 'test2' => '456'), array('a'=>'b') ));




                        Try This it will print array.
                        Tested !






                        share|improve this answer

























                          0












                          0








                          0







                          protected $_logger;

                          public function __construct(PsrLogLoggerInterface $logger)
                          $this->_logger = $logger;


                          public function logs()

                          $this->_logger->log($level,'errorlog1234', array( array('test1'=>'123', 'test2' => '456'), array('a'=>'b') ));




                          Try This it will print array.
                          Tested !






                          share|improve this answer













                          protected $_logger;

                          public function __construct(PsrLogLoggerInterface $logger)
                          $this->_logger = $logger;


                          public function logs()

                          $this->_logger->log($level,'errorlog1234', array( array('test1'=>'123', 'test2' => '456'), array('a'=>'b') ));




                          Try This it will print array.
                          Tested !







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Apr 4 at 12:28









                          HaFiz UmerHaFiz Umer

                          4149




                          4149



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Magento Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f89267%2fhow-we-can-print-array-variable-in-log-file-of-magento-2%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Bulk add to cart function issuecart vs. mini cart issue … rwd themeRedirect Add to cart button to cart pageAdd to cart issue - Magento 2.1The requested Payment Method is not available When creating an orderM2: reason add-to-cart might not function in production modeAdd to cart issue in some android devicesMagento 2 - custom price can not add to subtotal and grand total after add to cartAdd to cart codeIssue with my cart module on pdp and cart pages, just keeps spinningBulk price and quantity update using rest api

                              БиармияSxpst500bh2ntaf! 3h2r