How to write logs into file on disk?

168 views
Skip to first unread message

ThanhNS

unread,
Sep 26, 2006, 4:18:14 AM9/26/06
to jPOS Users
Hello everybody. I'm new to jPOS and I'm studying logger subsystem. I
tried to write logs into file on disk but I had following problem:
-------------------------------
java.io.FileNotFoundException: ..\log\log.txt (The system cannot find
the path s
pecified)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:177)
at java.io.FileOutputStream.<init>(FileOutputStream.java:102)
at
org.jpos.util.RotateLogListener.openLogFile(RotateLogListener.java:16
1)
at
org.jpos.util.RotateLogListener.<init>(RotateLogListener.java:101)
at
org.jpos.util.RotateLogListener.<init>(RotateLogListener.java:113)
at log.LogTest.setupLogger(LogTest.java:22)
at log.RotateLog.main(RotateLog.java:81)
-------------------------------

Here is source code:
-------------------------------
package log;

import java.io.*;
import org.jpos.iso.*;
import org.jpos.iso.packager.*;
import org.jpos.iso.channel.*;
import org.jpos.util.*;
import org.jpos.util.Logger;

public class RotateLog implements Runnable {
ISOChannel channel;
ISOMUX mux;
Logger logger;
public void setupLogger() {
// create a Logger object
logger = new Logger();
try {
// add a Simple listener that dumps log events to System.out
logger.addListener(new SimpleLogListener (System.out));
// add yet another Listener; this one will create
// files on your /tmp directory
logger.addListener(new RotateLogListener
("/tmp/jpos.log", 3600*1000, 5));
} catch (IOException e) {
e.printStackTrace();
}
}
public void setupMUX () {
ISOPackager p = new ISO87APackager();
// We want to log Packager events (there's no need to..)
// so we attach a Logger to the packager. We set an
// appropiate realm name (that should make sense
// to your application and a human operator)
p.setLogger (logger, "localhost.channel.packager");

//
// Create an ISOChannel. This one will connect
// to your ECHO service (you're using Unix, aren't you? :-)
//
channel = new ASCIIChannel ("localhost", 8000, p);

// assign a logger and an apropiate realm to your
// channel.
((LogSource)channel).setLogger (logger, "localhost.channel");

// create an ISOMUX with appropiate logger and realm
mux = new ISOMUX (channel);
mux.setLogger (logger, "localhost.mux");

// start your MUX
Thread t = new Thread (mux);
t.start();
}
public void run () {
// Send an ISORequest every 10 seconds
for (;;) {
ISOMsg m = new ISOMsg();
try {
m.set (new ISOField (0, "0800"));
m.set (new ISOField (11, "000001"));
m.set (new ISOField (41, "29110001"));
ISORequest rq = new ISORequest (m);
//
// New to this release is the fact that you
// can asign a Logger to your ISORequest. this
// will send a single log event with your
// request and it's response, as well as
// the elapsed time or an indication of
// expiration
//
rq.setLogger (logger, "isorequest");
mux.queue (rq);
ISOMsg r = rq.getResponse (10000);
Thread.sleep (10000);
} catch (ISOException e) {
} catch (InterruptedException e) { }
}
}
public static void main (String args[]) {
LogTest l = new LogTest();
l.setupLogger();
l.setupMUX ();
// Launch a SystemMonitor
new SystemMonitor (60000, l.logger, "monitor");
(new Thread(l)).start();
}
}
-------------------------------

Anyone please help me. Thank you very much.

Alejandro Revilla

unread,
Sep 26, 2006, 6:58:21 AM9/26/06
to jpos-...@googlegroups.com
>
> Hello everybody. I'm new to jPOS and I'm studying logger subsystem. I
> tried to write logs into file on disk but I had following problem:
> -------------------------------
> java.io.FileNotFoundException: ..\log\log.txt (The system cannot find
> the path s
>
Your code doesn't match your exception, you are supposed to store logs
in /tmp and the exception shows ..\log ... please verify that your
directory exists and use forward slashes instead of backslashes when
specifying the path to the log directory.

--Alejandro

ThanhNS

unread,
Sep 26, 2006, 9:44:13 PM9/26/06
to jPOS Users
Sorry, output here:
----------------------------------------------
java.io.FileNotFoundException: \tmp\jpos.log (The system cannot find

the path sp
ecified)
at java.io.FileOutputStream.openAppend(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:177)
at java.io.FileOutputStream.<init>(FileOutputStream.java:102)
at
org.jpos.util.RotateLogListener.openLogFile(RotateLogListener.java:16
1)
at
org.jpos.util.RotateLogListener.<init>(RotateLogListener.java:101)
at
org.jpos.util.RotateLogListener.<init>(RotateLogListener.java:113)
at log.RotateLog.setupLogger(RotateLog.java:22)
at log.RotateLog.main(RotateLog.java:81)
<log realm="monitor" at="Wed Sep 27 08:37:08 ICT 2006.687">
<SystemMonitor>
<memory>
freeMemory=1806552
totalMemory=2031616
inUseMemory=225608
</memory>
<threads>
delay=0 ms
threads=5
Thread[Reference Handler,10,system]
Thread[Finalizer,8,system]
Thread[Signal Dispatcher,10,system]
Thread[CompilerThread0,10,system]
Thread[Thread-0,6,main]
Thread[Thread-1,5,main]
Thread[SystemMonitor,1,main]
Thread[Thread-3,5,main]
Thread[DestroyJavaVM,5,main]
</threads>
<name-registrar>
</name-registrar>
</SystemMonitor>
</log>
<log realm="localhost.channel/127.0.0.1:8000" at="Wed Sep 27 08:37:08
ICT 2006.9
21">
<connect>
localhost:8000
</connect>
</log>
<log realm="localhost.mux" at="Wed Sep 27 08:37:09 ICT 2006.15">
<mux>
<mux-stats connected="true">
Connections: 1
TX messages: 0
TX expired: 0
TX pending: 1
RX messages: 0
RX expired: 0
RX pending: 1
RX unmatched: 0
RX forwarded: 0
</mux-stats>
</mux>
</log>
<log realm="localhost.channel.packager" at="Wed Sep 27 08:37:09 ICT
2006.171">
<pack>

30383030303032303030303030303830303030303030303030313239313130303031
</pack>
</log>
<log realm="localhost.channel/127.0.0.1:8000" at="Wed Sep 27 08:37:09
ICT 2006.2
18">
<send>
<isomsg direction="outgoing">
<field id="0" value="0800"/>
<field id="11" value="000001"/>
<field id="41" value="29110001"/>
</isomsg>
</send>
</log>
<log realm="localhost.channel.packager" at="Wed Sep 27 08:37:09 ICT
2006.328">
<unpack>

30383030303032303030303030303830303030303030303030313239313130303031
<bitmap>{11, 41}</bitmap>
<unpack fld="11" packager="org.jpos.iso.IFA_NUMERIC">
<value>000001</value>
</unpack>
<unpack fld="41" packager="org.jpos.iso.IF_CHAR">
<value>29110001</value>
</unpack>
</unpack>
</log>
<log realm="localhost.channel/127.0.0.1:8000" at="Wed Sep 27 08:37:09
ICT 2006.4
53">
<receive>
<isomsg direction="incoming">
<field id="0" value="0800"/>
<field id="11" value="000001"/>
<field id="41" value="29110001"/>
</isomsg>
</receive>
</log>
<log realm="isorequest" at="Wed Sep 27 08:37:09 ICT 2006.562">
<ISORequest>
<request>
<isomsg direction="outgoing">
<field id="0" value="0800"/>
<field id="11" value="000001"/>
<field id="41" value="29110001"/>
</isomsg>
</request>
<response elapsed="984">
<isomsg direction="incoming">
<field id="0" value="0800"/>
<field id="11" value="000001"/>
<field id="41" value="29110001"/>
</isomsg>
</response>
</ISORequest>
</log>
---------------------------------------
where /temp/jpos.log file is autogenerated or is created manually?
Thank you very much.

ThanhNS

unread,
Sep 26, 2006, 9:47:50 PM9/26/06
to jPOS Users

Matias

unread,
Sep 26, 2006, 10:30:30 PM9/26/06
to jpos-...@googlegroups.com
As I already mentioned (reason why you should actually read replies), you
have not created the path you are trying to save the log to, and if there is
something still not clear, then you should probably head to:

Here

Nguyễn Sinh Thành

unread,
Sep 26, 2006, 11:18:51 PM9/26/06
to jpos-...@googlegroups.com
Here is code to use RotateLogListener:

    logger = new Logger();
    try {
        // add a Simple listener that dumps log events to System.out
        logger.addListener(new SimpleLogListener (System.out));
        // add yet another Listener; this one will create
        // files on your /tmp directory
        logger.addListener(new RotateLogListener
        ("/tmp/jpos.log", 3600*1000, 5));
    } catch (IOException e) {
        e.printStackTrace();
    }

As I already mentioned (reason why you should actually read replies), you
have not created the path you are trying to save the log to, and if there is
something still not clear, then you should probably head to:

I have read replies and I have created the path that I'm trying to save the log but I still had exception " java.io.FileNotFoundException: \tmp\jpos.log (The system cannot find the path specified)".
Reply all
Reply to author
Forward
0 new messages