/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.jxtadoop.log; import java.io.*; import java.net.*; import java.util.regex.Pattern; import org.apache.commons.logging.*; import org.apache.commons.logging.impl.*; /** * Change log level in runtime. */ @SuppressWarnings({"unused"}) public class LogLevel { public static final String USAGES = "\nUSAGES:\n" + "java " + LogLevel.class.getName() + " -getlevel <host:port> <name>\n" + "java " + LogLevel.class.getName() + " -setlevel <host:port> <name> <level>\n"; /** * A command line implementation */ public static void main(String[] args) { if (args.length == 3 && "-getlevel".equals(args[0])) { process("http://" + args[1] + "/logLevel?log=" + args[2]); return; } else if (args.length == 4 && "-setlevel".equals(args[0])) { process("http://" + args[1] + "/logLevel?log=" + args[2] + "&level=" + args[3]); return; } System.err.println(USAGES); System.exit(-1); } private static void process(String urlstring) { try { URL url = new URL(urlstring); System.out.println("Connecting to " + url); URLConnection connection = url.openConnection(); connection.connect(); BufferedReader in = new BufferedReader(new InputStreamReader( connection.getInputStream())); for(String line; (line = in.readLine()) != null; ) if (line.startsWith(MARKER)) { System.out.println(TAG.matcher(line).replaceAll("")); } in.close(); } catch (IOException ioe) { System.err.println("" + ioe); } } static final String MARKER = "<!-- OUTPUT -->"; static final Pattern TAG = Pattern.compile("<[^>]*>"); }