Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[new api] Log interceptor

Comments in 'Plugin Development' started by jython234, Jun 17, 2014.

  1. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    Hello all,
    I am working on a seecret project involving pocketmine. In order for it to work, Ineed to detect when something new is logged in the console. Is this possible? I belive so, I could read from the log file, but where do I detect if it changed?

    Thanks!
    You java dev, jython234
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I'm wondering if Windows (or whatever OS) has a built in API that lets you listen when, like, a file changed?
  3. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    The software is written in Java, and I want to avoid native libraries. Also, I am trying to make it cross-platform
  4. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    I tried doing this in the previous API and had little success. The only way to accomplish it would be to detect file changes to the console.log as the stdout is write only. I tried doing this in a separate thread and just wound up with memory leaks, it may be easier now.
  5. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    This may sound dumb but:
    Would you just make a loop in a separate thread? The loop would open the file and read it, and check if its contents are the same as the last change?

    You could also just "mod" pocketmine, so it would have a event fired when it logs something, but for what I'm making, that wouldn't work well.
  6. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    Yeah that is what you would do, or open a non-locking stream on the file and just read line, it should block until a new line is written.
  7. jython234
    Offline

    jython234 Notable Member Plugin Developer

    Joined:
    Nov 4, 2013
    Posts:
    324
    Plugins:
    1
    Minecraft User:
    jython234
    Ok thanks, I'll try it out later.

Share This Page

Advertisement