home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / Log.pm < prev    next >
Encoding:
Perl POD Document  |  2004-09-23  |  14.5 KB  |  691 lines

  1. # /*
  2. #  * *********** WARNING **************
  3. #  * This file generated by ModPerl::WrapXS/0.01
  4. #  * Any changes made here will be lost
  5. #  * ***********************************
  6. #  * 01: lib/ModPerl/Code.pm:701
  7. #  * 02: O:\147xampp\sources\mod_perl-1.99_16\blib\lib/ModPerl/WrapXS.pm:584
  8. #  * 03: O:\147xampp\sources\mod_perl-1.99_16\blib\lib/ModPerl/WrapXS.pm:1100
  9. #  * 04: Makefile.PL:335
  10. #  * 05: Makefile.PL:283
  11. #  * 06: Makefile.PL:51
  12. #  */
  13.  
  14.  
  15. package Apache::Log;
  16.  
  17. use strict;
  18. use warnings FATAL => 'all';
  19.  
  20.  
  21.  
  22. use Apache::XSLoader ();
  23. our $VERSION = '0.01';
  24. Apache::XSLoader::load __PACKAGE__;
  25.  
  26.  
  27.  
  28. 1;
  29. __END__
  30.  
  31. =head1 NAME
  32.  
  33. Apache::Log - Perl API for Apache Logging Methods
  34.  
  35.  
  36.  
  37.  
  38. =head1 Synopsis
  39.  
  40.   #in startup.pl
  41.   #-------------
  42.   use Apache::Log;
  43.   
  44.   use Apache::Const -compile => qw(OK :log);
  45.   use APR::Const    -compile => qw(:error SUCCESS);
  46.   
  47.   my $s = Apache->server;
  48.   
  49.   $s->log_error("server: log_error");
  50.   $s->log_serror(__FILE__, __LINE__, Apache::LOG_ERR,
  51.                  APR::SUCCESS, "log_serror logging at err level");
  52.   $s->log_serror(Apache::Log::LOG_MARK, Apache::LOG_DEBUG,
  53.                  APR::ENOTIME, "debug print");
  54.   Apache::Server->log_error("routine warning");
  55.   
  56.   Apache->warn("routine warning");
  57.   Apache::warn("routine warning");
  58.   Apache::Server->warn("routine warning");
  59.  
  60.   #in a handler
  61.   #------------
  62.   package Foo;
  63.   
  64.   use strict;
  65.   use warnings FATAL => 'all';
  66.   
  67.   use Apache::Log;
  68.   
  69.   use Apache::Const -compile => qw(OK :log);
  70.   use APR::Const    -compile => qw(:error SUCCESS);
  71.   
  72.   sub handler {
  73.       my $r = shift;
  74.       $r->log_error("request: log_error");
  75.   
  76.       my $rlog = $r->log;
  77.       for my $level qw(emerg alert crit error warn notice info debug) {
  78.           no strict 'refs';
  79.           $rlog->$level($package, "request: $level log level");
  80.       }
  81.   
  82.       # can use server methods as well
  83.       my $s = $r->server;
  84.       $s->log_error("server: log_error");
  85.   
  86.       $r->log_rerror(Apache::Log::LOG_MARK, Apache::LOG_DEBUG,
  87.                      APR::ENOTIME, "in debug");
  88.   
  89.       $s->log_serror(Apache::Log::LOG_MARK, Apache::LOG_INFO,
  90.                      APR::SUCESS, "server info");
  91.   
  92.       $s->log_serror(Apache::Log::LOG_MARK, Apache::LOG_ERR,
  93.                      APR::ENOTIME, "fatal error");
  94.  
  95.       $s->warn('routine server warning');
  96.  
  97.       return Apache::OK;
  98.   }
  99.   1;
  100.  
  101.  
  102.  
  103. =head1 Description
  104.  
  105. C<Apache::Log> provides the Perl API for Apache logging methods.
  106.  
  107. Depending on the the current C<LogLevel> setting, only logging with
  108. the same log level or higher will be loaded. For example if the
  109. current C<LogLevel> is set to I<warning>, only messages with log level
  110. of the level I<warning> or higher (I<err>, I<crit>, I<elert> and
  111. I<emerg>) will be logged. Therefore this:
  112.  
  113.   $r->log_rerror(Apache::Log::LOG_MARK, Apache::LOG_WARNING,
  114.                  APR::ENOTIME, "warning!");
  115.  
  116. will log the message, but this one won't:
  117.  
  118.   $r->log_rerror(Apache::Log::LOG_MARK, Apache::LOG_INFO,
  119.                  APR::ENOTIME, "just an info");
  120.  
  121. It will be logged only if the server log level is set to I<info> or
  122. I<debug>. C<LogLevel> is set in the configuration file, but can be
  123. changed using the
  124. C<L<$s-E<gt>loglevel()|docs::2.0::api::Apache::Server/C_loglevel_>>
  125. method.
  126.  
  127. The filename and the line number of the caller are logged only if
  128. C<Apache::LOG_DEBUG> is used (because that's how Apache 2.0 logging
  129. mechanism works).
  130.  
  131. Note: On Win32 Apache attempts to lock all writes to a file whenever
  132. it's opened for append (which is the case with logging functions), as
  133. Unix has this behavior built-in, while Win32 does not. Therefore
  134. C<Apache::Log> functions could be slower than Perl's print()/warn().
  135.  
  136.  
  137.  
  138.  
  139.  
  140. =head1 Constants
  141.  
  142. Log level constants can be compiled all at once:
  143.  
  144.   use Apache::Const -compile => qw(:log);
  145.  
  146. or individually:
  147.  
  148.   use Apache::Const -compile => qw(LOG_DEBUG LOG_INFO);
  149.  
  150.  
  151.  
  152.  
  153. =head2 LogLevel Constants
  154.  
  155. The following constants (sorted from the most severe level to the
  156. least severe) are used in logging methods to specify the log level at
  157. which the message should be logged:
  158.  
  159. =head3 C<Apache::LOG_EMERG>
  160.  
  161. =head3 C<Apache::LOG_ALERT>
  162.  
  163. =head3 C<Apache::LOG_CRIT>
  164.  
  165. =head3 C<Apache::LOG_ERR>
  166.  
  167. =head3 C<Apache::LOG_WARNING>
  168.  
  169. =head3 C<Apache::LOG_NOTICE>
  170.  
  171. =head3 C<Apache::LOG_INFO>
  172.  
  173. =head3 C<Apache::LOG_DEBUG>
  174.  
  175.  
  176.  
  177. =head2 Other Constants
  178.  
  179.  
  180. Make sure to compile the APR status constants before using them. For
  181. example to compile C<APR::SUCESS> and all the APR error status
  182. constants do:
  183.  
  184.   use APR::Const    -compile => qw(:error SUCCESS);
  185.  
  186. Here is the rest of the logging related constants:
  187.  
  188.  
  189. =head3 C<Apache::LOG_LEVELMASK>
  190.  
  191. used to mask off the level value, to make sure that the log level's
  192. value is within the proper bits range. e.g.:
  193.  
  194.   $loglevel &= LOG_LEVELMASK;
  195.  
  196.  
  197.  
  198.  
  199.  
  200. =head3 C<Apache::LOG_TOCLIENT>
  201.  
  202. used to give content handlers the option of including the error text
  203. in the C<ErrorDocument> sent back to the client. When
  204. C<Apache::LOG_TOCLIENT> is passed to C<log_rerror()> the error message
  205. will be saved in the C<$r>'s notes table, keyed to the string
  206. I<"error-notes">, if and only if the severity level of the message is
  207. C<Apache::LOG_WARNING> or greater and there are no other
  208. I<"error-notes"> entry already set in the request record's notes
  209. table. Once the I<"error-notes"> entry is set, it is up to the error
  210. handler to determine whether this text should be sent back to the
  211. client.  For example:
  212.  
  213.   use Apache::Const -compile => qw(:log);
  214.   use APR::Const    -compile => qw(ENOTIME);
  215.   $r->log_rerror(Apache::Log::LOG_MARK,
  216.                  Apache::LOG_ERR|Apache::LOG_TOCLIENT,
  217.                  APR::ENOTIME,
  218.                  "request log_rerror");
  219.  
  220. now the log message can be retrieved via:
  221.  
  222.   $r->notes->get("error-notes");
  223.  
  224. Remember that client-generated text streams sent back to the client
  225. B<MUST> be escaped to prevent CSS attacks.
  226.  
  227.  
  228.  
  229.  
  230.  
  231. =head3 C<Apache::LOG_STARTUP>
  232.  
  233. is useful for startup message where no timestamps, logging level is
  234. wanted. For example:
  235.  
  236.   use Apache::Const -compile => qw(:log);
  237.   use APR::Const    -compile => qw(SUCCESS);
  238.   $s->log_serror(Apache::Log::LOG_MARK,
  239.                  Apache::LOG_INFO,
  240.                  APR::SUCCESS,
  241.                  "This log message comes with a header");
  242.  
  243. will print:
  244.  
  245.   [Wed May 14 16:47:09 2003] [info] This log message comes with a header
  246.  
  247. whereas, when C<Apache::LOG_STARTUP> is binary ORed as in:
  248.  
  249.   use Apache::Const -compile => qw(:log);
  250.   use APR::Const    -compile => qw(SUCCESS);
  251.   $s->log_serror(Apache::Log::LOG_MARK,
  252.                  Apache::LOG_INFO|Apache::LOG_STARTUP,
  253.                  APR::SUCCESS,
  254.                  "This log message comes with no header");
  255.  
  256. then the logging will be:
  257.  
  258.   This log message comes with no header
  259.  
  260.  
  261.  
  262.  
  263. =head1 Server Logging Methods
  264.  
  265.  
  266.  
  267. =head2 C<$s-E<gt>log_error>
  268.  
  269. just logs the supplied message to I<error_log>
  270.  
  271.   $s->log_error(@message);
  272.  
  273. =over 4
  274.  
  275. =item obj: C<$s>
  276. ( C<L<Apache::ServerRec object|docs::2.0::api::Apache::ServerRec>> )
  277.  
  278. =item arg1: C<@message> ( strings ARRAY )
  279.  
  280. what to log
  281.  
  282. =item ret: no return value
  283.  
  284. =item since: 1.99_12
  285.  
  286. =back
  287.  
  288. For example:
  289.  
  290.   $s->log_error("running low on memory");
  291.  
  292.  
  293.  
  294.  
  295.  
  296. =head2 C<$s-E<gt>log_serror>
  297.  
  298. This function provides a fine control of when the message is logged,
  299. gives an access to built-in status codes.
  300.  
  301.   $s->log_serror($file, $line, $level, $status, @message);
  302.  
  303. =over 4
  304.  
  305. =item obj: C<$s>
  306. ( C<L<Apache::ServerRec object|docs::2.0::api::Apache::ServerRec>> )
  307.  
  308. =item arg1: C<$file> ( string )
  309.  
  310. The file in which this function is called
  311.  
  312. =item arg2: C<$line> ( number )
  313.  
  314. The line number on which this function is called
  315.  
  316. =item arg3: C<$level>
  317. ( C<L<Apache::LOG_* constant|/LogLevel_Constants>> )
  318.  
  319. The level of this error message
  320.  
  321. =item arg4: C<$status>
  322. ( C<L<APR::Const status constant|docs::2.0::api::APR::Const>> )
  323.  
  324. The status code from the last command (similar to $! in perl), usually
  325. C<L<APR::Const constant|docs::2.0::api::APR::Const>> or coming from an
  326. L<exception object|docs::2.0::api::APR::Error>.
  327.  
  328. =item arg5: C<@message> ( strings ARRAY )
  329.  
  330. The log message(s)
  331.  
  332. =item ret: no return value
  333.  
  334. =item since: 1.99_12
  335.  
  336. =back
  337.  
  338. For example:
  339.  
  340.   use Apache::Const -compile => qw(:log);
  341.   use APR::Const    -compile => qw(ENOTIME SUCCESS);
  342.   $s->log_serror(Apache::Log::LOG_MARK, Apache::LOG_ERR,
  343.                  APR::SUCCESS, "log_serror logging at err level");
  344.   
  345.   $s->log_serror(Apache::Log::LOG_MARK, Apache::LOG_DEBUG,
  346.                  APR::ENOTIME, "debug print");
  347.  
  348.  
  349.  
  350.  
  351.  
  352. =head2 C<$s-E<gt>log>
  353.  
  354. get a log handle which can be used to L<log messages of different
  355. levels|/LogLevel_Methods>.
  356.  
  357.   my $slog = $s->log;
  358.  
  359. =over 4
  360.  
  361. =item obj: C<$s>
  362. ( C<L<Apache::ServerRec object|docs::2.0::api::Apache::ServerRec>> )
  363.  
  364. =item ret: C<$slog> ( C<Apache::Log::Server> object )
  365.  
  366. C<Apache::Log::Server> object to be used with L<LogLevel
  367. methods|/LogLevel_Methods>.
  368.  
  369. =item since: 1.99_12
  370.  
  371.  
  372. =back
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380. =head1 Request Logging Methods
  381.  
  382.  
  383.  
  384.  
  385. =head2 C<$r-E<gt>log_error>
  386.  
  387. just logs the supplied message (similar to
  388. C<L<$s-E<gt>log_error|/C__s_E_gt_log_error_>> ).
  389.  
  390.   $r->log_error(@message);
  391.  
  392. =over 4
  393.  
  394. =item obj: C<$r>
  395. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  396.  
  397. =item arg1: C<@message> ( strings ARRAY )
  398.  
  399. what to log
  400.  
  401. =item ret: no return value
  402.  
  403. =item since: 1.99_12
  404.  
  405.  
  406. =back
  407.  
  408. For example:
  409.  
  410.   $r->log_error("the request is about to end");
  411.  
  412.  
  413.  
  414.  
  415.  
  416.  
  417. =head2 C<$r-E<gt>log_rerror>
  418.  
  419. This function provides a fine control of when the message is logged,
  420. gives an access to built-in status codes.
  421.  
  422.   $r->log_rerror($file, $line, $level, $status, @message);
  423.  
  424. arguments are identical to
  425. C<L<$s-E<gt>log_serror|/C__s_E_gt_log_serror_>>.
  426.  
  427. =over 4
  428.  
  429. =item since: 1.99_12
  430.  
  431. =back
  432.  
  433. For example:
  434.  
  435.   use Apache::Const -compile => qw(:log);
  436.   use APR::Const    -compile => qw(ENOTIME SUCCESS);
  437.   $r->log_rerror(Apache::Log::LOG_MARK, Apache::LOG_ERR,
  438.                  APR::SUCCESS, "log_rerror logging at err level");
  439.   
  440.   $r->log_rerror(Apache::Log::LOG_MARK, Apache::LOG_DEBUG,
  441.                  APR::ENOTIME, "debug print");
  442.  
  443.  
  444.  
  445.  
  446.  
  447. =head2 C<$r-E<gt>log>
  448.  
  449. get a log handle which can be used to L<log messages of different
  450. levels|/LogLevel_Methods>.
  451.  
  452.   $rlog = $r->log;
  453.  
  454. =over 4
  455.  
  456. =item obj: C<$r> 
  457. ( C<L<Apache::RequestRec object|docs::2.0::api::Apache::RequestRec>> )
  458.  
  459. =item ret: C<$rlog> ( C<Apache::Log::Request> object )
  460.  
  461. C<Apache::Log::Request> object to be used with L<LogLevel
  462. methods|/LogLevel_Methods>.
  463.  
  464. =item since: 1.99_12
  465.  
  466.  
  467. =back
  468.  
  469.  
  470.  
  471.  
  472.  
  473.  
  474. =head1 Other Logging Methods
  475.  
  476. =head2 LogLevel Methods
  477.  
  478. after getting the log handle with C<L<$s-E<gt>log|/C__s_E_gt_log_>> or
  479. C<L<$r-E<gt>log|/C__s_E_gt_log_>>, use one of the following methods
  480. (corresponding to the C<LogLevel> levels):
  481.  
  482.   emerg(), alert(), crit(), error(), warn(), notice(), info(), debug()
  483.  
  484. to control when messages should be logged:
  485.  
  486.   $s->log->emerg(@message);
  487.   $r->log->emerg(@message);
  488.  
  489. =over 4
  490.  
  491. =item obj: C<$slog> ( L<server|/C__s_E_gt_log_> or
  492. L<request|/C__s_E_gt_log_> log handle )
  493.  
  494. =item arg1: C<@message> ( strings ARRAY )
  495.  
  496. =item ret: no return value
  497.  
  498. =item since: 1.99_12
  499.  
  500. =back
  501.  
  502. For example if the C<LogLevel> is C<error> and the following code is
  503. executed:
  504.  
  505.   my $slog = $s->log;
  506.   $slog->debug("just ", "some debug info");
  507.   $slog->warn(@warnings);
  508.   $slog->crit("dying");
  509.  
  510. only the last command's logging will be performed. This is because
  511. I<warn>, I<debug> and other logging command which are listed right to
  512. I<error> will be disabled.
  513.  
  514.  
  515.  
  516. =head2 C<emerg>
  517.  
  518. See L<LogLevel Methods|/LogLevel_Methods>.
  519.  
  520.  
  521.  
  522. =head2 C<alert>
  523.  
  524. See L<LogLevel Methods|/LogLevel_Methods>.
  525.  
  526.  
  527.  
  528. =head2 C<crit>
  529.  
  530. See L<LogLevel Methods|/LogLevel_Methods>.
  531.  
  532.  
  533.  
  534. =head2 C<error>
  535.  
  536. See L<LogLevel Methods|/LogLevel_Methods>.
  537.  
  538.  
  539.  
  540. =head2 C<warn>
  541.  
  542. See L<LogLevel Methods|/LogLevel_Methods>.
  543.  
  544.  
  545.  
  546. =head2 C<notice>
  547.  
  548. See L<LogLevel Methods|/LogLevel_Methods>.
  549.  
  550.  
  551. =head2 C<info>
  552.  
  553. See L<LogLevel Methods|/LogLevel_Methods>.
  554.  
  555.  
  556. =head2 C<debug>
  557.  
  558. See L<LogLevel Methods|/LogLevel_Methods>.
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565.  
  566. =head1 General Functions
  567.  
  568.  
  569.  
  570.  
  571.  
  572. =head2 C<LOG_MARK>
  573.  
  574. Though looking like a constant, this is a function, which returns a
  575. list of two items: C<(__FILE__, __LINE__)>, i.e. the file and the line
  576. where the function was called from.
  577.  
  578.   my($file, $line) = Apache::Log::LOG_MARK();
  579.  
  580. =over 4
  581.  
  582. =item ret1: C<$file> ( string )
  583.  
  584. =item ret2: C<$line> ( number )
  585.  
  586. =item since: 1.99_12
  587.  
  588. =back
  589.  
  590. It's mostly useful to be passed as the first argument to those logging
  591. methods, expecting the filename and the line number as the first
  592. arguments (e.g., C<L<$s-E<gt>log_serror|/C__s_E_gt_log_serror_>> and
  593. C<L<$r-E<gt>log_rerror|/C__r_E_gt_log_rerror_>> ).
  594.  
  595.  
  596.  
  597.  
  598.  
  599.  
  600. =head1 Aliases
  601.  
  602. =head2 C<$s-E<gt>warn>
  603.  
  604.   $s->warn(@warnings);
  605.  
  606. is the same as:
  607.  
  608.   $s->log_error(Apache::Log::LOG_MARK, Apache::LOG_WARNING,
  609.                 APR::SUCCESS, @warnings)
  610.  
  611. For example:
  612.  
  613.   $s->warn('routine server warning');
  614.  
  615. =head2 C<Apache-E<gt>warn>
  616.  
  617. =head2 C<Apache::warn>
  618.  
  619.   Apache->warn(@warnings);
  620.  
  621.  
  622.  
  623.  
  624. =head1 Unsupported API
  625.  
  626. C<Apache::Log> also provides auto-generated Perl interface for a few
  627. other methods which aren't tested at the moment and therefore their
  628. API is a subject to change. These methods will be finalized later as a
  629. need arises. If you want to rely on any of the following methods
  630. please contact the L<the mod_perl development mailing
  631. list|maillist::dev> so we can help each other take the steps necessary
  632. to shift the method to an officially supported API.
  633.  
  634.  
  635. =head2 C<log_pid>
  636.  
  637. META: what is this method good for? it just calls getpid and logs
  638. it. In any case it has nothing to do with the logging API. And it uses
  639. static variables, it probably shouldn't be in the Apache public API.
  640.  
  641. Log the current pid
  642.  
  643.   Apache::Log::log_pid($pool, $fname);
  644.  
  645. =over 4
  646.  
  647. =item obj: C<$p> ( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )
  648.  
  649. The pool to use for logging
  650.  
  651. =item arg1: C<$fname> ( file path )
  652.  
  653. The name of the file to log to
  654.  
  655. =item ret: no return value
  656.  
  657. =item since: subject to change
  658.  
  659.  
  660. =back
  661.  
  662.  
  663.  
  664.  
  665.  
  666.  
  667. =head1 See Also
  668.  
  669. L<mod_perl 2.0 documentation|docs::2.0::index>.
  670.  
  671.  
  672.  
  673.  
  674. =head1 Copyright
  675.  
  676. mod_perl 2.0 and its core modules are copyrighted under
  677. The Apache Software License, Version 2.0.
  678.  
  679.  
  680.  
  681.  
  682. =head1 Authors
  683.  
  684. L<The mod_perl development team and numerous
  685. contributors|about::contributors::people>.
  686.  
  687. =cut
  688.  
  689.