| 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; |
| 24 | |
| 25 | import org.lttng.ust.jul.LTTngUst; |
| 26 | |
| 27 | public class LTTngLogHandler extends Handler { |
| 28 | public LogManager logManager; |
| 29 | |
| 30 | public LTTngLogHandler(LogManager logManager) { |
| 31 | super(); |
| 32 | |
| 33 | this.logManager = logManager; |
| 34 | |
| 35 | /* Initialize LTTng UST tracer. */ |
| 36 | LTTngUst.init(); |
| 37 | } |
| 38 | |
| 39 | @Override |
| 40 | public void close() throws SecurityException {} |
| 41 | |
| 42 | @Override |
| 43 | public void flush() {} |
| 44 | |
| 45 | @Override |
| 46 | public void publish(LogRecord record) { |
| 47 | /* |
| 48 | * Specific tracepoing designed for JUL events. The source class of the |
| 49 | * caller is used for the event name, the raw message is taken, the |
| 50 | * loglevel of the record and the thread ID. |
| 51 | */ |
| 52 | LTTngUst.tracepoint(record.getMessage(), record.getLoggerName(), |
| 53 | record.getSourceClassName(), record.getSourceMethodName(), |
| 54 | record.getMillis(), record.getLevel().intValue(), |
| 55 | record.getThreadID()); |
| 56 | } |
| 57 | } |