Announcement

#1 2015-04-24 18:10:18

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3270

Logger

Hello team,

Today I added a real logger in Piwigo, based on https://github.com/katzgrau/KLogger (version 0.2 supporting PHP 5.2)

It currently only logs what was already logged by i.php and ws.php
What I would like is that if you have time you add log almost everywhere it would be interesting to have a trace of what is going on, mainly errors for production galleries but also debug infos for developpement.

I'll write a Wiki page about the logger but the main usage is

Code:

// 5 levels  (there are two more but I don't think we need this granularity)
$logger->info('message');
$logger->debug('message');
$logger->warning('message');
$logger->error('message');
$logger->critical('message');

// each method can take a array of info
$logger->info('message', array(
  'page' => $page,
  'user' => $user,
));

// each method can also take a "module" name (to separate core components, plugins, etc)
$logger->info('message', 'i.php');

$logger->info('message', 'i.php', array(
  'page' => $page,
  'user' => $user,
));

The logger generate one file by day in "_data/logs".
The filename contains an hash to prevent direct file access on unconfigured nginx servers (there is an .htaccess for Apache).
Up to 30 logs are kept (configurable).
The log level is also configurable (prod = ERROR, dev = DEBUG)

The last thing I plan is a logs viewer in "Maintenance" page for easy access by users when we ask them for the logs

https://i.imgflip.com/klrnn.jpg

Offline

 

#2 2015-04-24 18:40:00

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13150

Re: Logger

Hello,

Good idea to "unify" i.php and ws loggers and to have a clean way to do it anywhere in Piwigo code. I very often add debug trace with:

Code:

file_put_contents('/tmp/piwigo.log', "message\n", FILE_APPEND);

Now I will use:

Code:

$logger->info('message');

Much cleaner :-)

Can you add a few examples of $loggger calls where you think it's useful and I'll be happy to work on it too.


Latest blog post (May 3rd 2018) New subscription form

Offline

 

#3 2015-04-24 18:49:25

rvelices
Piwigo Team
2005-12-29
1960

Re: Logger

Hello.

Nice. Just 2 suggestions:

1. IMHO there should be absolutely no IO (such as file_exists, is_writable and especially fopen) in the logger constructor. On production sites, we don't expect a log line for every page hit, so we should lazily perform these operations when the first line is actually logged.

2. Note: If I remember well there were some calls to ilog in image.class ... I should check that ...

Offline

 

#4 2015-04-24 18:53:32

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3270

Re: Logger

1. oh right, I had this idea and forgot about it ^^  thank you
2. yep, missed that

edit: done both

Offline

 

#5 2015-04-24 19:09:14

mistic100
Former Piwigo Team
Lyon (FR)
2008-09-27
3270

Re: Logger

@plg : didn't think about it yet, recurent questions/problems on the forum should give use hints

Offline

 

Board footer

Powered by FluxBB

github twitter facebook google+ newsletter Donate Piwigo.org © 2002-2018 · Contact