2 * Copyright (C) 2013 - David Goulet <dgoulet@efficios.com>
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.
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
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
18 package org
.lttng
.ust
.jul
;
20 import java
.lang
.String
;
21 import java
.util
.logging
.Handler
;
22 import java
.util
.logging
.LogRecord
;
23 import java
.util
.logging
.LogManager
;
24 import java
.util
.logging
.Level
;
25 import java
.util
.HashMap
;
27 import org
.lttng
.ust
.jul
.LTTngUst
;
29 /* Note: This is taken from the LTTng tools ABI. */
30 class LTTngLogLevelABI
{
32 public static final int LOGLEVEL_TYPE_ALL
= 0;
33 public static final int LOGLEVEL_TYPE_RANGE
= 1;
34 public static final int LOGLEVEL_TYPE_SINGLE
= 2;
37 public class LTTngLogHandler
extends Handler
{
39 * Indicate if the enable all event has been seen and if yes logger that we
40 * enabled should use the loglevel/type below.
42 public int logLevelUseAll
= 0;
43 public int logLevelAll
= 0;
44 public int logLevelTypeAll
;
46 public LogManager logManager
;
48 /* Indexed by name and corresponding LTTngEvent. */
49 private HashMap
<String
, LTTngEvent
> eventMap
=
50 new HashMap
<String
, LTTngEvent
>();
52 public LTTngLogHandler(LogManager logManager
) {
55 this.logManager
= logManager
;
57 /* Initialize LTTng UST tracer. */
61 public void setEvent(LTTngEvent event
) {
62 eventMap
.put(event
.name
, event
);
66 public void close() throws SecurityException
{}
69 public void flush() {}
72 public void publish(LogRecord record
) {
73 int fire_tp
= 0, rec_log_level
, ev_type
, ev_log_level
;
75 LTTngLogLevel lttngLogLevel
;
76 String logger_name
= record
.getLoggerName();
78 /* Get back the event if any and check for loglevel. */
79 event
= eventMap
.get(logger_name
);
81 rec_log_level
= record
.getLevel().intValue();
82 ev_log_level
= event
.logLevel
.level
;
83 ev_type
= event
.logLevel
.type
;
86 case LTTngLogLevelABI
.LOGLEVEL_TYPE_RANGE
:
87 if (ev_log_level
<= rec_log_level
) {
91 case LTTngLogLevelABI
.LOGLEVEL_TYPE_SINGLE
:
92 if (ev_log_level
== rec_log_level
) {
96 case LTTngLogLevelABI
.LOGLEVEL_TYPE_ALL
:
101 /* No loglevel attached thus fire tracepoint. */
110 * Specific tracepoing designed for JUL events. The source class of the
111 * caller is used for the event name, the raw message is taken, the
112 * loglevel of the record and the thread ID.
114 LTTngUst
.tracepoint(record
.getMessage(), record
.getLoggerName(),
115 record
.getSourceClassName(), record
.getSourceMethodName(),
116 record
.getMillis(), record
.getLevel().intValue(),
117 record
.getThreadID());