bernhard Posted September 9, 2015 Share Posted September 9, 2015 hi guys, i'm in a hurry so i try it short i wanted to make it visible what happens behind the scenes when you do different things in processwire backend, especially WHEN all the hookable methods are called (render > saveReady > save or the like) i tried a simple wire('log')->save('hookrecorder', __METHOD__); inside the pages::saveReady() method and that worked! next step: i tried to add this line to all hookable functions here: <?php $rustart = getrusage(); include('index.php'); wireCopy('wire_original', 'wire_tmp'); $dir_iterator = new RecursiveDirectoryIterator("wire_tmp"); $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $file) { if ($file->isFile() AND $file->getExtension() === "php") { $content = file_get_contents($file); $pattern = "/(\w+) function ___(\w+(?<!log))\((.*)\) *{/"; $replace = "$1 function ___$2($3) {\n wire('log')->save('hookrecorder', __METHOD__);"; /* // for debugging preg_match_all($pattern, $content, $matches); echo $file . "<br>"; if(is_array($matches[0]) AND count($matches[0]) > 0) { foreach($matches[0] as $match) { echo $match . '<br>'; } } echo "<br><br>";*/ $content = preg_replace($pattern, $replace, $content); file_put_contents($file, $content); } } //wireRmdir('wire_tmp', true); // Script end function rutime($ru, $rus, $index) { return ($ru["ru_$index.tv_sec"]*1000 + intval($ru["ru_$index.tv_usec"]/1000)) - ($rus["ru_$index.tv_sec"]*1000 + intval($rus["ru_$index.tv_usec"]/1000)); } $ru = getrusage(); echo "This process used " . rutime($ru, $rustart, "utime") . " ms for its computations\n"; echo "It spent " . rutime($ru, $rustart, "stime") . " ms in system calls\n"; ?> it creates a directory wire_tmp with all the inserted log-statements. i replaced wire folder with wire_tmp folder (renamed it) and this does not work unfortunately (white screen, don't know if it would be different with debuggin true). i also tried to replace the wire/core/Wire.php file with the original one and to not log calls of "wire('log')" as i thought this may leed to errors (it's excluded in the regex) the idea is to save a page and then look all the hookable method calls up under setup > logs > hookrecorder and have a list like just now | pagexy | pages::save() just now | pagexy | pages::saveReady() just now | pagexy | pages::render() looking forward to hearing your opinions. should i exclude private methods or the like? or should i exclude whole files? or can i achieve what i want much simpler (eg server logging tools)? 3 Link to comment Share on other sites More sharing options...
bernhard Posted September 11, 2015 Author Share Posted September 11, 2015 nobody? some news: changed logging from the internal wire('log')->save() to hardcoded file log and that works! fwrite(fopen('/var/www/html/hooklogger.txt', 'a'), __METHOD__ . "\n"); added linebreaks after ___finished() method for better reading protected function ___finished() { fwrite(fopen('/var/www/html/hooklogger.txt', 'a'), __METHOD__ . "\n\n\n\n"); added some info to all methods of class page fwrite(fopen('/var/www/html/hooklogger.txt', 'a'), __METHOD__ . " (pageid " . $this->id . ", pagetitle: " . $this->title . "\n"); we could show any useful informations here... wouldn't it be great to have a module to install that enables logging (only on dev ofcourse) and makes it visible on an admin page. maybe filterable to only show relevant entries like macrura did on this site from the showcase section: http://ohmspeaker.com/speaker-filter/ ? couldn't that be a great addition to captain hook? as it alters all the hookable methods from the current installation it would not need any updating like captain hook does need. i think i read captain hook is quite outdated some time. wouldn't that solve this problem? this is the log of one save action on page "about" (changing title from "about" to "hookloggerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr") WireSaveableItems::___load Fieldgroups::___load WireSaveableItemsLookup::___load WireSaveableItems::___load Fieldtype::___wakeupValue Fieldtype::___wakeupValue Page::___loaded (pageid 1, pagetitle: Home) Fieldtype::___wakeupValue Page::___loaded (pageid 2, pagetitle: Admin) Fieldtype::___wakeupValue Page::___loaded (pageid 28, pagetitle: Access) Fieldtype::___wakeupValue Page::___loaded (pageid 29, pagetitle: Users) Fieldtype::___wakeupValue Page::___loaded (pageid 30, pagetitle: Roles) Page::___loaded (pageid 37, pagetitle: ) Page::___loaded (pageid 38, pagetitle: ) Page::___loaded (pageid 40, pagetitle: ) Session::___init Session::___isValidSession Fieldtype::___wakeupValue Page::___loaded (pageid 41, pagetitle: ) Fieldtype::___loadPageField Page::___path (pageid 2, pagetitle: Admin) ProcessWire::___init Pages::___find PageFinder::___find PageFinder::___getQuery PageFinder::___getQueryJoinPath Pages::___find Fieldtype::___wakeupValue Page::___loaded (pageid 3, pagetitle: Pages) Fieldtype::___wakeupValue Page::___loaded (pageid 10, pagetitle: Edit Page) ProcessWire::___ready TemplateFile::___render Page::___path (pageid 2, pagetitle: Admin) Page::___path (pageid 3, pagetitle: Pages) Fieldtype::___formatValue Fieldtype::___formatValue Fieldtype::___formatValue ProcessController::___execute Pages::___find Pages::___find Fieldtype::___wakeupValue Page::___loaded (pageid 7, pagetitle: Trash) Fieldtype::___wakeupValue Fieldtype::___wakeupValue Page::___loaded (pageid 1001, pagetitle: About) Page::___setEditor (pageid 1001, pagetitle: About) Field::___getInputfield (id: 1, title: ) Field::___getInputfield (id: 78, title: ) Fieldtype::___loadPageField Fieldtype::___wakeupValue Field::___getInputfield (id: 79, title: ) Field::___getInputfield (id: 76, title: ) Fieldtype::___loadPageField Fieldtype::___wakeupValue Field::___getInputfield (id: 82, title: ) Fieldtype::___loadPageField Field::___getInputfield (id: 44, title: ) Fieldtype::___loadPageField PagefilesManager::___path Page::___isPublic (pageid 1001, pagetitle: About) User::___hasPagePermission User::___hasPagePermission User::___hasPagePermission User::___hasPagePermission User::___hasPagePermission User::___hasPagePermission User::___hasPagePermission InputfieldWrapper::___processInput InputfieldWrapper::___processInput Inputfield::___processInput Wire::___changed Inputfield::___processInput Inputfield::___processInput PagefilesManager::___path InputfieldWrapper::___processInput Inputfield::___processInput Inputfield::___processInput Inputfield::___processInput InputfieldWrapper::___processInput Inputfield::___processInput Wire::___changed User::___hasPagePermission User::___hasPagePermission User::___hasPagePermission User::___hasPagePermission User::___hasPagePermission User::___hasPagePermission Page::___path (pageid 1001, pagetitle: hookloggerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr) Pages::___save Pages::___saveReady Page::___isPublic (pageid 1001, pagetitle: hookloggerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr) PagefilesManager::___save Fieldtype::___savePageField Fieldtype::___sleepValue Fieldtype::___savePageField Fieldtype::___savePageField Fieldtype::___savePageField Fieldtype::___savePageField FieldtypeMulti::___savePageField Pages::___saved Session::___redirect Wire::___changed Wire::___changed ProcessWire::___finished WireSaveableItems::___load Fieldgroups::___load WireSaveableItemsLookup::___load WireSaveableItems::___load Fieldtype::___wakeupValue Fieldtype::___wakeupValue Page::___loaded (pageid 1, pagetitle: Home) Fieldtype::___wakeupValue Page::___loaded (pageid 2, pagetitle: Admin) Fieldtype::___wakeupValue Page::___loaded (pageid 28, pagetitle: Access) Fieldtype::___wakeupValue Page::___loaded (pageid 29, pagetitle: Users) Fieldtype::___wakeupValue Page::___loaded (pageid 30, pagetitle: Roles) Page::___loaded (pageid 37, pagetitle: ) Page::___loaded (pageid 38, pagetitle: ) Page::___loaded (pageid 40, pagetitle: ) Session::___init Session::___isValidSession Fieldtype::___wakeupValue Page::___loaded (pageid 41, pagetitle: ) Fieldtype::___loadPageField Page::___path (pageid 2, pagetitle: Admin) ProcessWire::___init Pages::___find PageFinder::___find PageFinder::___getQuery PageFinder::___getQueryJoinPath Pages::___find Fieldtype::___wakeupValue Page::___loaded (pageid 3, pagetitle: Pages) Fieldtype::___wakeupValue Page::___loaded (pageid 10, pagetitle: Edit Page) ProcessWire::___ready TemplateFile::___render Page::___path (pageid 2, pagetitle: Admin) Page::___path (pageid 3, pagetitle: Pages) Fieldtype::___formatValue Fieldtype::___formatValue Fieldtype::___formatValue ProcessController::___execute Pages::___find Pages::___find Fieldtype::___wakeupValue Page::___loaded (pageid 7, pagetitle: Trash) Fieldtype::___wakeupValue Fieldtype::___wakeupValue Page::___loaded (pageid 1001, pagetitle: hookloggerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr) Process::___headline Fieldtype::___formatValue Process::___breadcrumb Process::___breadcrumb ModuleJS::___use Page::___setEditor (pageid 1001, pagetitle: hookloggerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr) Field::___getInputfield (id: 1, title: ) Field::___getInputfield (id: 78, title: ) Fieldtype::___loadPageField Fieldtype::___wakeupValue Field::___getInputfield (id: 79, title: ) Field::___getInputfield (id: 76, title: ) Fieldtype::___loadPageField Fieldtype::___wakeupValue Field::___getInputfield (id: 82, title: ) Fieldtype::___loadPageField Field::___getInputfield (id: 44, title: ) Fieldtype::___loadPageField PagefilesManager::___path Page::___isPublic (pageid 1001, pagetitle: hookloggerrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr) Pages::___find PageFinder::___find PageFinder::___getQuery Fieldtype::___formatValue User::___hasPagePermission User::___hasPagePermission User::___hasPagePermission User::___hasPagePermission User::___hasPagePermission User::___hasPagePermission User::___hasPagePermission Page::___path (pageid 7, pagetitle: Trash) Wire::___changed InputfieldWrapper::___render InputfieldWrapper::___renderInputfield InputfieldWrapper::___render InputfieldWrapper::___renderInputfield InputfieldWrapper::___renderInputfield InputfieldWrapper::___renderInputfield InputfieldWrapper::___renderInputfield ModuleJS::___use InputfieldWrapper::___renderInputfield InputfieldWrapper::___renderInputfield InputfieldWrapper::___renderInputfield Page::___path (pageid 10, pagetitle: Edit Page) InputfieldWrapper::___renderInputfield InputfieldWrapper::___render InputfieldWrapper::___renderInputfield Page::___path (pageid 7, pagetitle: Trash) InputfieldWrapper::___renderInputfield InputfieldWrapper::___renderInputfield Page::___path (pageid 10, pagetitle: Edit Page) InputfieldWrapper::___renderInputfield InputfieldWrapper::___renderInputfield Page::___path (pageid 10, pagetitle: Edit Page) InputfieldWrapper::___renderInputfield InputfieldWrapper::___render InputfieldWrapper::___renderInputfield InputfieldWrapper::___render InputfieldWrapper::___renderInputfield InputfieldWrapper::___renderInputfield InputfieldWrapper::___renderInputfield InputfieldWrapper::___renderInputfield User::___hasPagePermission AdminTheme::___getExtraMarkup Pages::___find PageFinder::___find PageFinder::___getQuery Fieldtype::___wakeupValue Page::___loaded (pageid 21, pagetitle: Modules) Fieldtype::___wakeupValue Page::___loaded (pageid 22, pagetitle: Setup) Pages::___find PageFinder::___find PageFinder::___getQuery Fieldtype::___wakeupValue Page::___loaded (pageid 6, pagetitle: Add Page) Fieldtype::___wakeupValue Page::___loaded (pageid 8, pagetitle: Tree) Fieldtype::___wakeupValue Page::___loaded (pageid 1007, pagetitle: Find) Fieldtype::___wakeupValue Page::___loaded (pageid 1009, pagetitle: Recent) Page::___path (pageid 10, pagetitle: Edit Page) Page::___path (pageid 3, pagetitle: Pages) Page::___path (pageid 3, pagetitle: Pages) Page::___path (pageid 10, pagetitle: Edit Page) Page::___path (pageid 8, pagetitle: Tree) Page::___path (pageid 8, pagetitle: Tree) Page::___path (pageid 10, pagetitle: Edit Page) Page::___path (pageid 1007, pagetitle: Find) Page::___path (pageid 1007, pagetitle: Find) Page::___path (pageid 1009, pagetitle: Recent) Page::___path (pageid 1009, pagetitle: Recent) Page::___path (pageid 1009, pagetitle: Recent) Page::___path (pageid 1009, pagetitle: Recent) Page::___path (pageid 1009, pagetitle: Recent) Page::___path (pageid 1009, pagetitle: Recent) Page::___path (pageid 1009, pagetitle: Recent) Page::___path (pageid 1009, pagetitle: Recent) Page::___path (pageid 1009, pagetitle: Recent) Page::___path (pageid 1009, pagetitle: Recent) Page::___path (pageid 1009, pagetitle: Recent) Page::___path (pageid 3, pagetitle: Pages) Pages::___find PageFinder::___find PageFinder::___getQuery Fieldtype::___wakeupValue Page::___loaded (pageid 11, pagetitle: Templates) Fieldtype::___wakeupValue Page::___loaded (pageid 16, pagetitle: Fields) Fieldtype::___wakeupValue Page::___loaded (pageid 1011, pagetitle: Logs) Page::___path (pageid 10, pagetitle: Edit Page) Page::___path (pageid 22, pagetitle: Setup) Page::___path (pageid 22, pagetitle: Setup) Page::___path (pageid 11, pagetitle: Templates) Page::___path (pageid 11, pagetitle: Templates) Page::___path (pageid 16, pagetitle: Fields) Page::___path (pageid 16, pagetitle: Fields) Page::___path (pageid 1011, pagetitle: Logs) Page::___path (pageid 1011, pagetitle: Logs) Page::___path (pageid 22, pagetitle: Setup) Page::___path (pageid 10, pagetitle: Edit Page) Page::___path (pageid 21, pagetitle: Modules) Page::___path (pageid 21, pagetitle: Modules) Page::___path (pageid 21, pagetitle: Modules) Page::___path (pageid 21, pagetitle: Modules) Page::___path (pageid 21, pagetitle: Modules) Page::___path (pageid 21, pagetitle: Modules) Page::___path (pageid 21, pagetitle: Modules) Page::___path (pageid 21, pagetitle: Modules) Page::___path (pageid 21, pagetitle: Modules) Page::___path (pageid 21, pagetitle: Modules) Page::___path (pageid 21, pagetitle: Modules) Page::___path (pageid 21, pagetitle: Modules) Pages::___find PageFinder::___find PageFinder::___getQuery Fieldtype::___wakeupValue Page::___loaded (pageid 31, pagetitle: Permissions) Page::___path (pageid 10, pagetitle: Edit Page) Page::___path (pageid 28, pagetitle: Access) Page::___path (pageid 28, pagetitle: Access) Page::___path (pageid 29, pagetitle: Users) Page::___path (pageid 29, pagetitle: Users) Page::___path (pageid 30, pagetitle: Roles) Page::___path (pageid 30, pagetitle: Roles) Page::___path (pageid 31, pagetitle: Permissions) Page::___path (pageid 31, pagetitle: Permissions) Page::___path (pageid 28, pagetitle: Access) User::___hasPagePermission Page::___path (pageid 2, pagetitle: Admin) Fieldtype::___formatValue User::___hasPagePermission ProcessWire::___finished 1 Link to comment Share on other sites More sharing options...
bernhard Posted September 11, 2015 Author Share Posted September 11, 2015 9 Link to comment Share on other sites More sharing options...
Adam Kiss Posted September 12, 2015 Share Posted September 12, 2015 Looks super awesome, but to be honest, I have no idea whether some other method of logging would be better (or would have better performance). But it looks nice Link to comment Share on other sites More sharing options...
bernhard Posted September 14, 2015 Author Share Posted September 14, 2015 hi adam, thank you. i don't think performance is an issue as it is only intended to be used during development from just one superuser... it's a pity i've no time to take this further at the moment Link to comment Share on other sites More sharing options...
Adam Kiss Posted September 14, 2015 Share Posted September 14, 2015 thank you. i don't think performance is an issue as it is only intended to be used during development from just one superuser... Of course, I thought you've been looking for the most performant option, and I just said I don't know Looking at your posts now, I don't see it, so I got confused, probably. Link to comment Share on other sites More sharing options...
bernhard Posted September 14, 2015 Author Share Posted September 14, 2015 anyway - thanks for your opinion. i'm happy that it is not a monologue any more i would have been interested in more experienced pirates' opinions if that would be helpful or it was better to look through the code manually... it's also not showing hooks in the /site/modules folder right now... Link to comment Share on other sites More sharing options...
elabx Posted September 15, 2015 Share Posted September 15, 2015 It took my a while to realize that this could be VERY educational, thank you BernhardB! 1 Link to comment Share on other sites More sharing options...
bernhard Posted September 15, 2015 Author Share Posted September 15, 2015 thank you elabx, that was my intention as i'm quite new to hooking and already find my way through the basics but i think it could be very handy to click a button in backend and have all the called hookable methods showing up somewhere. maybe with some helpful information inside a toggleable div (like pageid/title from the triggering page or descriptions from above the medhod (maybe links to github like this one for pages::saveReady(): https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/Pages.php#L2086) edit: github won't be a good idea because it should show the info of the currently installed version of processwire so it would be better to fetch the information directly from the file system. 2 Link to comment Share on other sites More sharing options...
Recommended Posts