1##################################################
2package Log::Log4perl::MDC;
3##################################################
4
5use 5.006;
6use strict;
7use warnings;
8
9our %MDC_HASH = ();
10
11###########################################
12sub get {
13###########################################
14    my($class, $key) = @_;
15
16    if($class ne __PACKAGE__) {
17        # Somebody called us with Log::Log4perl::MDC::get($key)
18        $key = $class;
19    }
20
21    if(exists $MDC_HASH{$key}) {
22        return $MDC_HASH{$key};
23    } else {
24        return undef;
25    }
26}
27
28###########################################
29sub put {
30###########################################
31    my($class, $key, $value) = @_;
32
33    if($class ne __PACKAGE__) {
34        # Somebody called us with Log::Log4perl::MDC::put($key, $value)
35        $value = $key;
36        $key   = $class;
37    }
38
39    $MDC_HASH{$key} = $value;
40}
41
42###########################################
43sub remove {
44###########################################
45    %MDC_HASH = ();
46
47    1;
48}
49
50###########################################
51sub get_context {
52###########################################
53    return \%MDC_HASH;
54}
55
561;
57
58__END__
59
60=head1 NAME
61
62Log::Log4perl::MDC - Mapped Diagnostic Context
63
64=head1 DESCRIPTION
65
66Log::Log4perl allows loggers to maintain global thread-specific data,
67called the Nested Diagnostic Context (NDC) and
68Mapped Diagnostic Context (MDC).
69
70The MDC is a simple thread-specific hash table, in which the application
71can stuff values under certain keys and retrieve them later
72via the C<"%X{key}"> placeholder in
73C<Log::Log4perl::Layout::PatternLayout>s.
74
75=over 4
76
77=item Log::Log4perl::MDC->put($key, $value);
78
79Store a value C<$value> under key C<$key> in the map.
80
81=item my $value = Log::Log4perl::MDC->get($key);
82
83Retrieve the content of the map under the specified key.
84Typically done by C<%X{key}> in
85C<Log::Log4perl::Layout::PatternLayout>.
86If no value exists to the given key, C<undef> is returned.
87
88=item my $text = Log::Log4perl::MDC->remove();
89
90Delete all entries from the map.
91
92=item Log::Log4perl::MDC->get_context();
93
94Returns a reference to the hash table.
95
96=back
97
98Please note that all of the methods above are class methods, there's no
99instances of this class. Since the thread model in perl 5.8.0 is
100"no shared data unless explicetly requested" the data structures
101used are just global (and therefore thread-specific).
102
103=head1 AUTHOR
104
105Mike Schilli, E<lt>log4perl@perlmeister.comE<gt>
106
107=cut
108