katzgrau / KLogger

A Simple Logging Class For PHP
http://codefury.net/projects/klogger/
980 stars 284 forks source link

throw exception when parameters object is null #58

Closed vanjor closed 9 years ago

vanjor commented 9 years ago

Argument 2 passed to Psr\Log\AbstractLogger::info() must be of the type array, null given

when calling $logger->info("raise the log", null);

onno-vos-dev commented 9 years ago

@vanjor What exactly is your point?

The call is quite clear, it must take an array... Whether or not that functionality should be expanded to include other types of context, is a valid discussion in my opinion but you don't raise such point.

Adding null as a context won't add anything to your logfile and no matter what type of context we would allow, it would always look kinda odd.

katzgrau commented 9 years ago

Agreed w/ @onno-vos-dev

If you've got a concrete idea of what/how you think it should work, submit a PR and we'll have a look over.

onno-vos-dev commented 9 years ago

(Sorry to comment on a closed Issue @katzgrau )

Just to add to this:

If we would like to include other forms of context, it would automatically mean we would deviate from the PSR-3 LoggerInterface as that only allows for $context to be of type array. Again, whether or not this is the best solution, I think is worth thinking about but breaking the LoggerInterface in favor of KLogger does not sound like a great idea to me. See: LoggerInterface Context

My final $0,02: If you need more context to be added to your log, you can always go as followed (which is what we use internally if we want really verbose logs).

$logger->log(LogLevel::DEBUG, 'Your request failed. The request you sent was: '.json_encode($request_data));
vanjor commented 9 years ago

Thanks to both.

Actually I does not expect logging function raise the exception, for PHP is a weak type as many function expected to return array, but return null at some case.

accept @onno-vos-dev suggest,though this substituted way is a little bit verbos:)