usage.apt
4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
~~ Licensed to the Apache Software Foundation (ASF) under one or more
~~ contributor license agreements. See the NOTICE file distributed with
~~ this work for additional information regarding copyright ownership.
~~ The ASF licenses this file to You under the Apache License, Version 2.0
~~ (the "License"); you may not use this file except in compliance with
~~ the License. You may obtain a copy of the License at
~~
~~ http://www.apache.org/licenses/LICENSE-2.0
~~
~~ Unless required by applicable law or agreed to in writing, software
~~ distributed under the License is distributed on an "AS IS" BASIS,
~~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~~ See the License for the specific language governing permissions and
~~ limitations under the License.
------
Apache log4php usage example
------
------
------
Apache Log4php Usage Example">
+--
<?php
/**
* This is a log4php usage example file
*
*/
/**
* Set LOG4PHP_DIR to Your log4php root dir or it will
* be set automatically at the first require_once().
* Here 'log4php' is an 'include_path' subdir.
*/
define('LOG4PHP_DIR', 'log4php');
/*
1. If you want to use a custom Configurator,
set the LOG4PHP_CONFIGURATOR_CLASS constants to Your Configurator class file.
The class name must have the same base name of the classfile.
Ex: define('LOG4PHP_CONFIGURATOR_CLASS', '/my/path/LoggerMyConfigurator');
Log4php will try to include '/my/path/LoggerMyConfigurator.php'
and instantiate a 'LoggerMyConfigurator' class.
2. If you want to use a configuration file that's not the default,
set the LOG4PHP_CONFIGURATION constants to Your configuration filename.
Ex: define('LOG4PHP_CONFIGURATION', '/my/path/my_config.conf');
Note that if config extension is NOT .xml and LOG4PHP_CONFIGURATOR_CLASS
is not defined, the LoggerPropertyConfigurator will be used.
3. If you want to bypass the initial configuration procedure, set the
'LOG4PHP_DEFAULT_INIT_OVERRIDE' to true.
Ex: define('LOG4PHP_DEFAULT_INIT_OVERRIDE', true);
*/
require_once(LOG4PHP_DIR. '/LoggerManager.php');
/*
Or You can use:
require_once('/my/log4php/path/LoggerManager.php');
and LOG4PHP_DIR will be automatically set to '/my/log4php/path'.
*/
class Test {
var $logger;
function Test()
{
$this->logger =& LoggerManager::getLogger('Test');
}
function testLog()
{
$this->logger->debug('this is a DEBUG log generated by Test::testLog() class');
$this->logger->info('this is an INFO log generated by Test::testLog() class');
$this->logger->warn('this is a WARN log generated by Test::testLog() class');
$this->logger->error('this is an ERROR log generated by Test::testLog() class');
$this->logger->fatal('this is a FATAL log generated by Test::testLog() class');
}
}
class TestTest extends Test {
var $logger;
function TestTest()
{
$this->Test();
$this->logger =& LoggerManager::getLogger('Test.Test');
}
function testLog()
{
LoggerNDC::push('NDC generated by TestTest::testLog()');
$this->logger->debug('this is a DEBUG log generated by TestTest::testLog() class');
$this->logger->info('this is an INFO log generated by TestTest::testLog() class');
$this->logger->warn('this is a WARN log generated by TestTest::testLog() class');
$this>->logger->error('this is an ERROR log generated by TestTest::testLog() class');
$this->logger->fatal('this is a FATAL log generated by TestTest::testLog() class');
LoggerNDC::pop();
}
}
function Bar()
{
$logger =& LoggerManager::getLogger('bar');
/*
note that the message here is an array
*/
$logger->debug(array('one', 'two', 'tree'));
$logger->info('this is an INFO log generated by Bar() function');
$logger->warn('this is a WARN log generated by Bar() function');
$logger->error('this is an ERROR log generated by Bar() function');
$logger->fatal('this is a FATAL log generated by Bar() function');
}
$logger =& LoggerManager::getLogger('main');
$logger->debug('this is a DEBUG log generated by main() function');
$logger->info('this is an INFO log generated by main() function');
$logger->warn('this is a WARN log generated by main() function');
$logger->error('this is an ERROR log generated by main() function');
$logger->fatal('this is a FATAL log generated by main() function')
$test = new Test();
$test->testLog();
$testTest = new TestTest();
$testTest->testLog();
Bar();
?>
+--