PhpGt / WebEngine

Minimalistic, ergonomic PHP toolkit.
https://www.php.gt/webengine
MIT License
26 stars 6 forks source link

Implement Logging Framework #94

Closed 8w closed 10 years ago

8w commented 11 years ago

Would you be prepared to add a logging framework (such as Log4Php ) to PhpGt? debugging my own php code is very difficult without it (var dump and die is very blunt), and there's not much sense in trying to reinvent the wheel when php4j is a fully fledged Apache project.

g105b commented 11 years ago

I use xdebug for debugging PHP, and you can pop the breakpoints into Sublime or other IDE for variable lookup, callstack, etc.

I don't have a problem with Log4Php though, just can't work out the benefits over a simple file_put_contents in combination with xdebug's functionality (or just using the IDE).

8w commented 11 years ago

There are lots of possible reasons, but these are most relevant to me:

I think it's an important requirement for a framework that will be used for enterprise/ production apps.

I'm happy to add it to my local apps as a pagetool or whatever, but it seems like something that the php.gt framework would be enhanced by if it includes it.

g105b commented 11 years ago

I'll have a look at the popular ones that are out there, might put it into your project to test with before making it a feature

8w commented 11 years ago

I just opened issue #95 - a great example of why custom logging with config hard-coded into the php is a bad idea!

8w commented 11 years ago

I started to implement this last night, but got tied-up because I don't remember how class-loading is handled by PHP.Gt. What I did was:

{
    "require": {
        "apache/log4php": "2.3.0"
    },
    "prefer-stable": true,
}
g105b commented 11 years ago

A simple solution that I've seen some PHP apps do is to output logs directly to StdErr / StdOut, which can be read by the OS or PHP at any time.

Does this sound good, or do you think outputting to a file is more desirable?

8w commented 11 years ago

Neither - I think we need a proper logging framework so it can be increased and decreased at runtime for debugging etc rather than needing code changes. On 31 Jul 2013 09:48, "Greg Bowler" notifications@github.com wrote:

A simple solution that I've seen some PHP apps do is to output logs directly to StdErr / StdOut, which can be read by the OS or PHP at any time.

Does this sound good, or do you think outputting to a file is more desirable?

— Reply to this email directly or view it on GitHubhttps://github.com/g105b/PHP.Gt/issues/94#issuecomment-21848316 .

g105b commented 10 years ago

Just implemented a logger, with similar (but simpler) capabilities to Log4Php.

Use it like this:

// Always obtain a Logger instance. You can name the log file by passing in the name as a parameter to get.
$logger = Log::get();
$logger->info("Here's a log message");
$logger->debug("Here's a debug message", $throwable);

Optionally, a log config file can be used within environments. Put it in APPROOT/Config/Log_Config.cfg.php, and the following variables can be configured:

g105b commented 10 years ago

I'm leaving this issue open until you've read it, as you made the feature request... does it do what you expect?

8w commented 10 years ago

Need to update the docs to show the config file format/ example Does the implementation allow logging to be configured for particular classes/ namespaces/ PageCode/ PageTool directory hierarchies? So if I was trying to debug an issue in authentication or a particular pagetool I would want to be able to turn up logging on that part of the codebase but not the whole application. If it applies to the whole application level it would be really difficult to see what you wanted.