2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.apache.log4j.varia;
20 import org.apache.log4j.Logger;
21 import org.apache.log4j.BasicConfigurator;
23 import java.io.IOException;
24 import java.io.DataInputStream;
25 import java.io.DataOutputStream;
26 import java.net.Socket;
29 A simple application to send roll over messages to a potentially
30 remote {@link ExternallyRolledFileAppender}.
32 <p>It takes two arguments, the <code>host_name</code> and
33 <code>port_number</code> where the
34 <code>ExternallyRolledFileAppender</code> is listening.
37 @author Ceki Gülcü
38 @since version 0.9.0 */
41 static Logger cat = Logger.getLogger(Roller.class);
52 Send a "RollOver" message to
53 <code>ExternallyRolledFileAppender</code> on <code>host</code>
54 and <code>port</code>.
59 void main(String argv[]) {
61 BasicConfigurator.configure();
63 if(argv.length == 2) {
64 init(argv[0], argv[1]);
66 usage("Wrong number of arguments.");
73 void usage(String msg) {
74 System.err.println(msg);
75 System.err.println( "Usage: java " + Roller.class.getName() +
76 "host_name port_number");
81 void init(String hostArg, String portArg) {
84 port = Integer.parseInt(portArg);
86 catch(java.lang.NumberFormatException e) {
87 usage("Second argument "+portArg+" is not a valid integer.");
94 Socket socket = new Socket(host, port);
95 DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
96 DataInputStream dis = new DataInputStream(socket.getInputStream());
97 dos.writeUTF(ExternallyRolledFileAppender.ROLL_OVER);
98 String rc = dis.readUTF();
99 if(ExternallyRolledFileAppender.OK.equals(rc)) {
100 cat.info("Roll over signal acknowledged by remote appender.");
102 cat.warn("Unexpected return code "+rc+" from remote entity.");
105 } catch(IOException e) {
106 cat.error("Could not send roll signal on host "+host+" port "+port+" .",