Refactor liblttng-ust-jul in liblttng-ust-agent
[lttng-ust.git] / liblttng-ust-java-agent / java / org / lttng / ust / agent / jul / LTTngLogHandler.java
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.agent.jul;
19
20 import java.lang.String;
21
22 import java.util.logging.Handler;
23 import java.util.logging.LogRecord;
24
25 class LTTngLogHandler extends Handler {
26 private Boolean is_root;
27
28 public LTTngLogHandler(Boolean isRoot) {
29 super();
30 this.is_root = isRoot;
31 /* Initialize LTTng UST tracer. */
32 try {
33 System.loadLibrary("lttng-ust-jul-jni"); //$NON-NLS-1$
34 } catch (SecurityException e) {
35 e.printStackTrace();
36 } catch (UnsatisfiedLinkError e) {
37 e.printStackTrace();
38 } catch (NullPointerException e) {
39 /* Should never happen */
40 e.printStackTrace();
41 }
42 }
43
44 public Boolean isRoot() {
45 return this.is_root;
46 }
47
48 @Override
49 public void close() throws SecurityException {}
50
51 @Override
52 public void flush() {}
53
54 @Override
55 public void publish(LogRecord record) {
56 /*
57 * Specific tracepoing designed for JUL events. The source class of the
58 * caller is used for the event name, the raw message is taken, the
59 * loglevel of the record and the thread ID.
60 */
61 if (this.is_root) {
62 tracepointS(record.getMessage(),
63 record.getLoggerName(), record.getSourceClassName(),
64 record.getSourceMethodName(), record.getMillis(),
65 record.getLevel().intValue(), record.getThreadID());
66 } else {
67 tracepointU(record.getMessage(),
68 record.getLoggerName(), record.getSourceClassName(),
69 record.getSourceMethodName(), record.getMillis(),
70 record.getLevel().intValue(), record.getThreadID());
71 }
72 }
73
74 /* Use for a user session daemon. */
75 private native void tracepointU(String msg, String logger_name, String class_name,
76 String method_name, long millis, int log_level, int thread_id);
77
78 /* Use for a root session daemon. */
79 private native void tracepointS(String msg, String logger_name, String class_name,
80 String method_name, long millis, int log_level, int thread_id);
81 }
This page took 0.030432 seconds and 4 git commands to generate.