Nico Knoll

Release: ProcessLogs

Recommended Posts

Hi,

today I'm proud to release my first Module: the "ProcessErrorLog"-Reader.

It gives you the ability to read the error log in the backend. You can sort it and clear it.

Maybe you just want to try it out. You can download it here:

[uPDATE]

I renamed this project to ProcessLogs. Now you can download it here:

https://github.com/NicoKnoll/ProcessLogs

Share this post


Link to post
Share on other sites

Nico congratulations! This sounds great and very useful. Will try this soon!

Share this post


Link to post
Share on other sites

Installed it in my test environment and it looks very nice and usefull. Good job!

Share this post


Link to post
Share on other sites

Tested here too. Seems to work great – nice work Nico!

I have a couple of suggestions. For loading/writing to the log file, I recommend replacing this:

'../assets/logs/errors.txt'

With this:

$config->paths->logs . 'errors.txt';

I was also wondering about this:

$url = explode('/', substr($_SERVER["REQUEST_URI"],0,-1));
unset($url[count($url)-1]);
$url = implode($url, '/').'/';
header('Location: '.$url);

Couldn't you just do this instead?

$session->redirect("../"); 

In your getInstalledPage() function, I recommend adding this before the $page->save():

$page->sort = $parent->numChildren; 

That will ensure it gets placed as the last item on the Setup page, rather than potentially in between Template and Fields.

Lastly, take a look at PW's FileLog class: /wire/core/FileLog.php. This is what PW uses to create the log files. It includes two functions that may be handy in a future version of your module – particularly if you ever have to deal with really large log files (which may not be very likely with PW's error log). It includes a get($bytes) function that returns lines from the end of the file, without having to load the whole file. It also includes a prune($bytes) function that prunes a log file down to a specific size, leaving all lines in tact from the end of the file. This is preferable to clearing sometimes as it still leaves the most recent entries in tact. PW doesn't currently utilize either of these functions anywhere but just wanted to let you know they were there in case you ever find them useful. I originally coded them thinking of a log viewing/management utility module.

Share this post


Link to post
Share on other sites

Version 1.08 is out (you can download it on Github - link is in the first post). I changed the functions like Ryan recommended. But I still want it to read all of the errors and so I left this part of the code untouched.

Share this post


Link to post
Share on other sites

Ther error log works.

THe error messages overlap the table, they're too long to fit in the cells. I suggest to trim them to 50chars and when on hover show the message in a layer? Or use collapsible InputfieldWrapper fieltype to make each error an element, with the date time and cut message as label, and if open show the whole message. Just ideas.

Also when I clear the log... I get this notice:

Notice Undefined index:  file in /site/modules/ProcessLogs/ProcessLogs.module on line 52
Notice Undefined variable: errors in <b>/Applications/XAMPP/xamppfiles/htdocs/pw2.ch/site/modules/ProcessLogs/ProcessLogs.module on line 76

If I select the LoginNotifier Log it shows me these:

Warning: array_combine() [function.array-combine]: Both parameters should have an equal number of elements in /Applications/XAMPP/xamppfiles/htdocs/pw2.ch/site/modules/ProcessLogs/ProcessLogs.module on line 69

Warning: array_combine() [function.array-combine]: Both parameters should have an equal number of elements in /Applications/XAMPP/xamppfiles/htdocs/pw2.ch/site/modules/ProcessLogs/ProcessLogs.module on line 69

Warning: array_combine() [function.array-combine]: Both parameters should have an equal number of elements in /Applications/XAMPP/xamppfiles/htdocs/pw2.ch/site/modules/ProcessLogs/ProcessLogs.module on line 69

Warning: array_combine() [function.array-combine]: Both parameters should have an equal number of elements in /Applications/XAMPP/xamppfiles/htdocs/pw2.ch/site/modules/ProcessLogs/ProcessLogs.module on line 69

Warning: array_combine() [function.array-combine]: Both parameters should have an equal number of elements in /Applications/XAMPP/xamppfiles/htdocs/pw2.ch/site/modules/ProcessLogs/ProcessLogs.module on line 69

Notice: Undefined index: page in /Applications/XAMPP/xamppfiles/htdocs/pw2.ch/site/modules/ProcessLogs/ProcessLogs.module on line 82
Notice: Undefined index: type in /Applications/XAMPP/xamppfiles/htdocs/pw2.ch/site/modules/ProcessLogs/ProcessLogs.module on line 83
Notice: Undefined index: description in /Applications/XAMPP/xamppfiles/htdocs/pw2.ch/site/modules/ProcessLogs/ProcessLogs.module on line 84
Notice: Undefined index: user in /Applications/XAMPP/xamppfiles/htdocs/pw2.ch/site/modules/ProcessLogs/ProcessLogs.module on line 81

and it doesn't show the log messages, just a table with 20 times the same date time...

Do you know the login notifier is configurable and its possible to define own fields that get logged? How are you handling this?

Share this post


Link to post
Share on other sites

Well I thought every log is the same. But it isn't. So I will have a look at the login module and figure out a solution.

And which kind of error reporting you have activated?

Share this post


Link to post
Share on other sites

is it possible to change the location of the save file of the logs

Example: i have a existing folder in logs folder i would like to create a log file inside the created folder it this possible..

/site/assets/logs/tfdencoding/

Thanks in advance?

Follow Up Question:

Getting the value of logs via api script...

Share this post


Link to post
Share on other sites

Hi there, i using logs as my page hits logs,

now, i want to get all the values of the created log file

but it display only 100 values

$items = $this->wire('log');
$items = $items->getEntries('animalabc_logs', $options);

How to add " limit (integer) "

Base on this https://processwire.com/api/variables/log/

Firstly, to clarify - what you are talking about is core functionality now, but you have posted in the support thread for Nico's "old" module.

Just use the $options array like this:

$options = array('limit' => 100);
$items = $this->wire('log');
$items = $items->getEntries('animalabc_logs', $options);
  • Like 1

Share this post


Link to post
Share on other sites

Follow up Question:

How to change the save location of logs....

The default save location is inside /site/assets/logs/

I added another folder inside /site/assets/logs/tfdencoding/

Share this post


Link to post
Share on other sites

It's going to affect all log files, but you could do this in your config.php file:

$config->paths->logs = $config->paths->assets.'/logs/tfdencoding/';

Share this post


Link to post
Share on other sites

It's going to affect all log files, but you could do this in your config.php file:

$config->paths->logs = $config->paths->assets.'/logs/tfdencoding/';

Is it possible to change only the specific logs like the one i created and will not affect the other logs like error...?

Share this post


Link to post
Share on other sites

There might be a better way - this is a bit of a rush, but put the following in site/ready.php

wire('config')->initialLogPath = wire('config')->paths->logs;
$this->addHookBefore('WireLog::save', function($event) {
    if($event->arguments[0] == 'test') { // where "test" is the name of the log to go into the tfdencoding subfolder
       wire('config')->paths->logs = wire('config')->paths->assets.'/logs/tfdencoding/';
    }
    else {
       wire('config')->paths->logs = wire('config')->initialLogPath;
    }
});

Share this post


Link to post
Share on other sites

There might be a better way - this is a bit of a rush, but put the following in site/ready.php

wire('config')->initialLogPath = wire('config')->paths->logs;
$this->addHookBefore('WireLog::save', function($event) {
    if($event->arguments[0] == 'test') { // where "test" is the name of the log to go into the tfdencoding subfolder
       wire('config')->paths->logs = wire('config')->paths->assets.'/logs/tfdencoding/';
    }
    else {
       wire('config')->paths->logs = wire('config')->initialLogPath;
    }
});
I changed it
$config->initialLogPath = $config->paths->logs;
$this->addHookBefore('WireLog::save', function($event) { // <-- there's an error here...
    if($event->arguments[0] == 'tfdupdates') { // where "test" is the name of the log to be put into the tfdencoding subfolder
    	$config->paths->logs = $config->paths->assets.'/logs/tfdencoding/';
    }
    else {
    	$config->paths->logs = $config->initialLogPath;
    }
});

Share this post


Link to post
Share on other sites

Sorry, I don't understand - the code I posted works here without errors. What error are you getting? Make sure you have debug mode on.

Share this post


Link to post
Share on other sites

Nothing happens is still saving in default location

the file I saved it in site folder the name of file is ready.php

i'm using Adobe dreamweaver cs5..

$this->addHookBefore('WireLog::save', function($event) { // this part turn on red....

but the changes i've made it is ok..?

like

wire('config')->initialLogPath = wire('config')->paths->logs;

to

$config->initialLogPath = $config->paths->logs;

Share this post


Link to post
Share on other sites

No you can't make those changes - $config is not available in ready.php

Please just try the code exactly as I had it, except for the name of the log file. Is "tfdupdates" definitely the name of the log file that you are saving, eg:

$log->save('tfdupdates', 'log file content');
  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.