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 /* Am I a root Log Handler. */
47 public int is_root
= 0;
49 public LogManager logManager
;
51 /* Indexed by name and corresponding LTTngEvent. */
52 private HashMap
<String
, LTTngEvent
> eventMap
=
53 new HashMap
<String
, LTTngEvent
>();
55 public LTTngLogHandler(LogManager logManager
) {
58 this.logManager
= logManager
;
60 /* Initialize LTTng UST tracer. */
64 public void setEvent(LTTngEvent event
) {
65 eventMap
.put(event
.name
, event
);
69 public void close() throws SecurityException
{}
72 public void flush() {}
75 public void publish(LogRecord record
) {
76 int fire_tp
= 0, rec_log_level
, ev_type
, ev_log_level
;
78 LTTngLogLevel lttngLogLevel
;
79 String logger_name
= record
.getLoggerName();
81 /* Get back the event if any and check for loglevel. */
82 event
= eventMap
.get(logger_name
);
84 rec_log_level
= record
.getLevel().intValue();
85 ev_log_level
= event
.logLevel
.level
;
86 ev_type
= event
.logLevel
.type
;
89 case LTTngLogLevelABI
.LOGLEVEL_TYPE_RANGE
:
90 if (ev_log_level
<= rec_log_level
) {
94 case LTTngLogLevelABI
.LOGLEVEL_TYPE_SINGLE
:
95 if (ev_log_level
== rec_log_level
) {
99 case LTTngLogLevelABI
.LOGLEVEL_TYPE_ALL
:
104 /* No loglevel attached thus fire tracepoint. */
113 * Specific tracepoing designed for JUL events. The source class of the
114 * caller is used for the event name, the raw message is taken, the
115 * loglevel of the record and the thread ID.
117 if (this.is_root
== 1) {
118 LTTngUst
.tracepointS(record
.getMessage(),
119 record
.getLoggerName(), record
.getSourceClassName(),
120 record
.getSourceMethodName(), record
.getMillis(),
121 record
.getLevel().intValue(), record
.getThreadID());
123 LTTngUst
.tracepointU(record
.getMessage(),
124 record
.getLoggerName(), record
.getSourceClassName(),
125 record
.getSourceMethodName(), record
.getMillis(),
126 record
.getLevel().intValue(), record
.getThreadID());