Return-Path: X-Original-To: apmail-logging-commits-archive@minotaur.apache.org Delivered-To: apmail-logging-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3B8F99583 for ; Wed, 19 Oct 2011 05:14:16 +0000 (UTC) Received: (qmail 58298 invoked by uid 500); 19 Oct 2011 05:14:16 -0000 Delivered-To: apmail-logging-commits-archive@logging.apache.org Received: (qmail 58271 invoked by uid 500); 19 Oct 2011 05:14:13 -0000 Mailing-List: contact commits-help@logging.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@logging.apache.org Delivered-To: mailing list commits@logging.apache.org Received: (qmail 58243 invoked by uid 99); 19 Oct 2011 05:14:11 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Oct 2011 05:14:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Oct 2011 05:14:09 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0923A2388962; Wed, 19 Oct 2011 05:13:49 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1185971 - in /logging/log4php/branches/experimental/config-adapters/src/site: apt/docs/configuration-old.apt apt/docs/filters-old.apt apt/docs/introduction-old.apt apt/docs/loggers.apt xdoc/docs/appenders.xml xdoc/docs/loggers.xml Date: Wed, 19 Oct 2011 05:13:48 -0000 To: commits@logging.apache.org From: ihabunek@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111019051349.0923A2388962@eris.apache.org> Author: ihabunek Date: Wed Oct 19 05:13:48 2011 New Revision: 1185971 URL: http://svn.apache.org/viewvc?rev=1185971&view=rev Log: More work on docs. Added: logging/log4php/branches/experimental/config-adapters/src/site/xdoc/docs/loggers.xml Removed: logging/log4php/branches/experimental/config-adapters/src/site/apt/docs/configuration-old.apt logging/log4php/branches/experimental/config-adapters/src/site/apt/docs/filters-old.apt logging/log4php/branches/experimental/config-adapters/src/site/apt/docs/introduction-old.apt logging/log4php/branches/experimental/config-adapters/src/site/apt/docs/loggers.apt Modified: logging/log4php/branches/experimental/config-adapters/src/site/xdoc/docs/appenders.xml Modified: logging/log4php/branches/experimental/config-adapters/src/site/xdoc/docs/appenders.xml URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/site/xdoc/docs/appenders.xml?rev=1185971&r1=1185970&r2=1185971&view=diff ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/site/xdoc/docs/appenders.xml (original) +++ logging/log4php/branches/experimental/config-adapters/src/site/xdoc/docs/appenders.xml Wed Oct 19 05:13:48 2011 @@ -83,7 +83,7 @@ LoggerAppenderPhp - Creates a PHP user-level message using the PHP trigger_error function. + Creates a PHP user-level message using the PHP trigger_error() function. LoggerAppenderSocket @@ -163,6 +163,28 @@ primus and will therefore only log to the console.

+ + + + +

An appender can be assigned a threshold level. All logging requests with level lower than this threshold + will be ignored.

+ +

For example, if you set WARN as a threshold, then INFO, DEBUG + and TRACE level events recieved by the appender will not be logged, but WARN, + ERROR and FATAL will.

+ +

An example of setting an appender threshold:

+ +

+    
+    
+        
+    
+
+]]>
+
Added: logging/log4php/branches/experimental/config-adapters/src/site/xdoc/docs/loggers.xml URL: http://svn.apache.org/viewvc/logging/log4php/branches/experimental/config-adapters/src/site/xdoc/docs/loggers.xml?rev=1185971&view=auto ============================================================================== --- logging/log4php/branches/experimental/config-adapters/src/site/xdoc/docs/loggers.xml (added) +++ logging/log4php/branches/experimental/config-adapters/src/site/xdoc/docs/loggers.xml Wed Oct 19 05:13:48 2011 @@ -0,0 +1,289 @@ + + + + + + Loggers + + + +
+ +

A logger is a component which will take your logging request and log it. Each class in a project can + have an individual logger, or they can all use a common logger. Loggers are named entities; it is + common to name them after the class which will use it for logging.

+ +

Creating a logger is done by calling the static getLogger() method on the Logger object + and providing the name of the logger. For example, to create a logger named foo:

+ +
$logger = Logger::getLogger('foo');
+ +

Logging requests are made by invoking one of the printing methods of a Logger instance. These logging + methods are: trace, debug, info, warn, error and fatal. The printing method determines the level of a + logging request. For example, calling the method info() creates a logging request of level + INFO. For example:

+ +
$logger->info("This is the message to be logged.");
+ +

Loggers by themselves do not define where these messages will be logged. For that you need to assign + one or more appenders to the logger.

+ + +

A logger can be assigned a threshold level. All logging requests with level lower than this threshold + will be ignored.

+ +

For example, setting logger threshold to INFO means that logging requests with levels + TRACE and DEBUG will not be logged by this logger.

+ +

An example of setting the root logger threshold to DEBUG:

+ +

+    
+    
+        
+        
+    
+
+]]>
+ +

By default loggers do not have a threshold set, which means they will log all events, regardless of the + level.

+
+ + +

Loggers can be individually configured in the configuration file.

+ +

The simplest example is to configure the root logger, since all other loggers will inherit its + settings, as explained in the next section.

+ +

+    
+    
+        
+        
+    
+
+]]>
+

This configuration adds the default appender to the root logger, and sets it's + threshold level to DEBUG.

+ +

It is also possible to configure individual named loggers. For example, let's configure the + foo logger, used in the example above, and set it's threshold to WARN:

+ +

+    
+    
+        
+        
+    
+
+]]>
+
+ + +

Loggers follow a parent-child relationship pattern which is implemented by using a naming pattern. + A logger is said to be an ancestor of another logger if its name followed by a dot is a + prefix of the descendant logger name. A logger is said to be a parent of a + child logger if there are no ancestors between itself and the descendant logger.

+ +

For example, the logger named foo is a parent of the logger named foo.bar. + Similarly, org is a parent of org.apache and an ancestor of + org.apache.logging. This naming scheme should be familiar to most developers.

+ +

The root logger resides at the top of the logger hierarchy. It is exceptional in two ways:

+
    +
  • it always exists,
  • +
  • it cannot be retrieved by name.
  • +
+ +

Invoking the class static Logger::getRootLogger() method retrieves the root logger. + All other loggers are instantiated and retrieved with the Logger::getLogger($name) + method. This method takes the name of the desired logger as a parameter. If the logger does not exist + at the time of the call, it will be created.

+
+ + +

The threshold level and appenders are inherited from the parent to the child loggers.

+ +

For example examine the following configuration:

+ +

+    
+    
+        
+        
+    
+
+]]>
+ +

The threshold level of the root logger is set to debug. Also, the root logger is linked to a console + appender. Any named logger that is created will inherit these root settings.

+ +
trace('This will not be logged.');
+$main->info('This will be logged.');
+]]>
+

A logger named main is created. Since there is no logger-specific configuration, it + will inherit all of it's settings from the root logger: a console appender, and threshold set to DEBUG. + Therefore, this code will produce the following output:

+ +
INFO - This will be logged.
+
+ + +

Appender additivity is a property of loggers to inherit their parent's appenders. By default all + loggers have appender additivity enabled.

+ +

Let's take the following example:

+ +

+    
+    
+    
+        
+    
+     
+        
+    
+
+]]>
+

Since additivity is enabled by default, the logger foo will have two linked appenders: + A1 which it will inherit from the root logger, and A2 which is defined for it specifically.

+ +

Therefore, by executing the following code:

+ +
info('This will be logged twice.');
+]]>
+

The message will be logged twice - once by A1 and once by A2, producing:

+ +
+INFO - This will be logged twice.
+INFO - This will be logged twice.
+
+ +

Disabling appender additivity

+ +

Logger's appender additivity can also be disabled if needed.

+ +

If the foo logger in the previous example was configured like this:

+ +
 
+    
+
+]]>
+

Then the logger would not have inherited the A1 appender from the root logger, and the message + would have been logged only once.

+ +

A more complex example

+ +

In this example we will look at multiple loggers making a hierarchy.

+ +

Not to make the example too complex, all appenders will log to the console. Of course, this doesn't + always have to be the case.

+ +

Let's take the following configuration file:

+ +

+    
+    
+    
+    
+
+    
+        
+    
+    
+        
+        
+    
+    
+    
+        
+    
+
+]]>
+

The table below shows how the configuration is interpreted, and which appenders are inherited:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Logger nameLinked appendersAdditivity flagOutput targetsComment
rootA1N/AA1One appender, named A1, is added to root logger. Any logging requests to root logger + will be forwarded only to that one appender.
fooA2, A3trueA1, A2, A3A logger named foo is created and two appenders, named A2 and A3, are + added to it. Additionally, because of logger additivity, foo inherits the + appender A1 from the root logger which is it's parent in the logger hierarchy. Therefore + logging requests to this logger will be forwarded to appenders A1, A2 and A3.
foo.barnonetrueA1, A2, A3A logger named foo.bar is created. Because it's name starts with + foo, it will be created as a child of the foo logger. + No appenders are added to foo.bar but it will inherit it's ancestor's + appenders: appenders A2 and A3 from foo and A1 from root. + Logging requests to this logger will be forwarded to appenders A1, A2 and A3.
foo.bar.bazA4falseA4Finally, logger foo.bar.baz is created, and because of it's name it is + created as child to foo.bar. One appender, A4 is added to it. However, since + it's additivity flag is set to false, it will not inherit any appenders from it's + ancestors. Logging requests to this logger will be forwarded only to appender A4.
+
+
+ +