[Help] How to log chat

Discussion in 'Plugin Development' started by ludo0777, Feb 3, 2012.

?

Can you help?

  1. Yes

    2 vote(s)
    100.0%
  2. No

    0 vote(s)
    0.0%
Thread Status:
Not open for further replies.
  1. I need to add logging functionality to my plugin so that it logs everything everyone says into a file. Can anyone help?

    I need to know:
    • How to create the file it logs all the messages into
    • How to write the messages into the file

    Help please!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  2. Offline

    Evangon

    If your new to plugins, don't tamper with file creation until you get the basics down. If not, here's my little part of a plugin:
    Code:JAVA
    1.  
    2. File log = new File(this.getDataFolder(), new SimpleDateFormat("MM-dd-yyyy").format(Calendar.getInstance().getTime()) + "log.txt");
    3.  
    4. protected void edit(File f, String plyr, String target, String msg, Boolean command){
    5. try {
    6. BufferedWriter write = new BufferedWriter(new FileWriter(f, true));
    7. if(override){
    8. write = new BufferedWriter(new FileWriter(f, false));
    9. }
    10. write.newLine();
    11. if(command.equals(true)){
    12. write.write(plyr + " : Targeted " + target + " to execute " + msg);
    13. } else {
    14. write.write(plyr + " : Targeted " + target + " to say " + msg);
    15. }
    16. write.flush();
    17. write.close();
    18. } catch (FileNotFoundException e) {
    19. server.broadcastMessage(ChatColor.RED + "ForceChat failed to access it's log file. Reason: Does not exist!");
    20. e.printStackTrace();
    21. } catch(IOException e) {
    22. System.out.print("Unable to access file. Does the file exist? File:" + f.getName());
    23. e.printStackTrace();
    24. }
    25. }
    26.  

    Again, this is intermediate/advanced (most likely intermediate-beginner)
     
Thread Status:
Not open for further replies.

Share This Page