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;
38 /* Event name on which this loglevel is applied on. */
39 private String event_name
;
40 /* This level is a JUL int level value. */
44 public LTTngLogLevel(String event_name
, int level
, int type
) {
45 this.event_name
= event_name
;
50 public String
getName() {
51 return this.event_name
;
54 public int getLevel() {
58 public int getType() {
63 public class LTTngLogHandler
extends Handler
{
64 public LogManager logManager
;
66 private HashMap
<String
, LTTngLogLevel
> logLevels
=
67 new HashMap
<String
, LTTngLogLevel
>();
69 public LTTngLogHandler(LogManager logManager
) {
72 this.logManager
= logManager
;
74 /* Initialize LTTng UST tracer. */
78 public void setLogLevel(String event_name
, int level
, int type
) {
79 LTTngLogLevel lttngLogLevel
= new LTTngLogLevel(event_name
, level
,
81 logLevels
.put(event_name
, lttngLogLevel
);
85 public void close() throws SecurityException
{}
88 public void flush() {}
91 public void publish(LogRecord record
) {
92 int fire_tp
= 0, rec_log_level
, ev_type
, ev_log_level
;
93 LTTngLogLevel lttngLogLevel
;
94 String event_name
= record
.getLoggerName();
96 lttngLogLevel
= logLevels
.get(event_name
);
97 if (lttngLogLevel
!= null) {
98 rec_log_level
= record
.getLevel().intValue();
99 ev_log_level
= lttngLogLevel
.getLevel();
100 ev_type
= lttngLogLevel
.getType();
103 case LTTngLogLevelABI
.LOGLEVEL_TYPE_RANGE
:
104 if (ev_log_level
<= rec_log_level
) {
108 case LTTngLogLevelABI
.LOGLEVEL_TYPE_SINGLE
:
109 if (ev_log_level
== rec_log_level
) {
113 case LTTngLogLevelABI
.LOGLEVEL_TYPE_ALL
:
118 /* No loglevel attached thus fire tracepoint. */
127 * Specific tracepoing designed for JUL events. The source class of the
128 * caller is used for the event name, the raw message is taken, the
129 * loglevel of the record and the thread ID.
131 LTTngUst
.tracepoint(record
.getMessage(), record
.getLoggerName(),
132 record
.getSourceClassName(), record
.getSourceMethodName(),
133 record
.getMillis(), record
.getLevel().intValue(),
134 record
.getThreadID());