Commit | Line | Data |
---|---|---|
43e5396b DG |
1 | /* |
2 | * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com> | |
3 | * | |
4 | * This library is free software; you can redistribute it and/or modify it | |
5 | * under the terms of the GNU Lesser General Public License, version 2.1 only, | |
6 | * as published by the Free Software Foundation. | |
7 | * | |
8 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | |
11 | * for more details. | |
12 | * | |
13 | * You should have received a copy of the GNU Lesser General Public License | |
14 | * along with this library; if not, write to the Free Software Foundation, | |
15 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
16 | */ | |
17 | ||
18 | package org.lttng.ust.jul; | |
19 | ||
20 | import java.lang.String; | |
21 | import java.util.logging.Handler; | |
22 | import java.util.logging.LogRecord; | |
23 | import java.util.logging.LogManager; | |
a15440fd | 24 | import java.util.logging.Level; |
96caa5ed DG |
25 | import java.util.logging.Logger; |
26 | import java.util.Collections; | |
a15440fd | 27 | import java.util.HashMap; |
96caa5ed | 28 | import java.util.Map; |
43e5396b DG |
29 | |
30 | import org.lttng.ust.jul.LTTngUst; | |
31 | ||
96caa5ed | 32 | public class LTTngLogHandler extends Handler { |
9aabed2d DG |
33 | /* Am I a root Log Handler. */ |
34 | public int is_root = 0; | |
9663e532 | 35 | public int refcount = 0; |
9aabed2d | 36 | |
43e5396b DG |
37 | public LogManager logManager; |
38 | ||
96caa5ed | 39 | /* Logger object attached to this handler that can trigger a tracepoint. */ |
9663e532 DG |
40 | public Map<String, LTTngEvent> enabledEvents = |
41 | Collections.synchronizedMap(new HashMap<String, LTTngEvent>()); | |
a15440fd | 42 | |
96caa5ed | 43 | /* Constructor */ |
43e5396b DG |
44 | public LTTngLogHandler(LogManager logManager) { |
45 | super(); | |
46 | ||
47 | this.logManager = logManager; | |
48 | ||
49 | /* Initialize LTTng UST tracer. */ | |
50 | LTTngUst.init(); | |
51 | } | |
52 | ||
87d64abb DG |
53 | /* |
54 | * Cleanup this handler state meaning put it back to a vanilla state. | |
55 | */ | |
56 | public void clear() { | |
9663e532 | 57 | this.enabledEvents.clear(); |
87d64abb DG |
58 | } |
59 | ||
43e5396b DG |
60 | @Override |
61 | public void close() throws SecurityException {} | |
62 | ||
63 | @Override | |
64 | public void flush() {} | |
65 | ||
66 | @Override | |
67 | public void publish(LogRecord record) { | |
68 | /* | |
69 | * Specific tracepoing designed for JUL events. The source class of the | |
70 | * caller is used for the event name, the raw message is taken, the | |
71 | * loglevel of the record and the thread ID. | |
72 | */ | |
9aabed2d DG |
73 | if (this.is_root == 1) { |
74 | LTTngUst.tracepointS(record.getMessage(), | |
75 | record.getLoggerName(), record.getSourceClassName(), | |
76 | record.getSourceMethodName(), record.getMillis(), | |
77 | record.getLevel().intValue(), record.getThreadID()); | |
78 | } else { | |
79 | LTTngUst.tracepointU(record.getMessage(), | |
80 | record.getLoggerName(), record.getSourceClassName(), | |
81 | record.getSourceMethodName(), record.getMillis(), | |
82 | record.getLevel().intValue(), record.getThreadID()); | |
83 | } | |
43e5396b DG |
84 | } |
85 | } |