|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* AppserverIo\Logger\Processors\ThreadContextProcessor |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link http://github.com/appserver-io/logger |
|
18
|
|
|
* @link http://www.appserver.io |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace AppserverIo\Logger\Processors; |
|
22
|
|
|
|
|
23
|
|
|
use AppserverIo\Logger\Logger; |
|
24
|
|
|
use AppserverIo\Logger\LogMessageInterface; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Logger processor that adds the thread context as name attribute. The thread context |
|
28
|
|
|
* will be queried from the ProfileLogger, to the log context. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Tim Wagner <[email protected]> |
|
31
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
|
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
33
|
|
|
* @link http://github.com/appserver-io/logger |
|
34
|
|
|
* @link http://www.appserver.io |
|
35
|
|
|
*/ |
|
36
|
|
|
class ThreadContextProcessor implements ProcessorInterface |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Key for the context name in the message context. |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
*/ |
|
44
|
|
|
const CONTEXT_KEY = 'name'; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Adds the thread context as name attribute to the log message context. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \AppserverIo\Logger\LogMessageInterface $logMessage The log message we want to add the thread context name to |
|
50
|
|
|
* |
|
51
|
|
|
* @return string The processed log message |
|
52
|
|
|
* @see \AppserverIo\Logger\Processors\ProcessorInterface::process() |
|
53
|
|
|
*/ |
|
54
|
|
|
public function process(LogMessageInterface $logMessage) |
|
55
|
|
|
{ |
|
56
|
|
|
$logMessage->appendToContext(ThreadContextProcessor::CONTEXT_KEY, Logger::$threadContext); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|