I have requirement to read the last modified time of a log file in the Magento 2 like Apr 10, 2017, 6:47:17 AM

The log file will be present under var/log directory of Magento. How can implement it? Is there a method in core Magento for this?

2 Answers 2


I have created one module to search and get the modified files. you can get list from command line.

This Magento 2 Module is use to search string and find modified files in Magento Root Directory.

It is very easy to search content, search content in specific directory.

Also you can search the modified files within the folder.

Please refer the URL: https://github.com/ashish-wagento/module-searchmodified


You can use the DirectorIterator class to do so.

I'm not sure exactly how you want to achieve that but here's a small script that can be used to do what you want:

$modificationsTimes = array();
foreach (new DirectorIterator("/path/to/var/log/directory") as $file) {
    if (!$file->isDir() && file_exists($file->getPathname())) {
        $modificationTimes[$file->getFilename()] = date('Y-m-d H:i:s', $file->getMTime());

The $modificationTimes array will contain an association of entries where the key is the log file name and the value is the last modification time of the file.

NB: this code is pure PHP it does not use any core Magento methods / classes.

  • I have requirement to show this time in a Admin Grid column.
    – Mukesh
    Apr 14, 2017 at 9:17
  • I was using the function getMtime.. I am getting an error splfileInfo getMtime() stat failed
    – User 69
    May 1, 2020 at 7:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.