Custom Logs

Discussion in 'Plugin Development' started by MaTaMoR_, Jul 10, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    MaTaMoR_

    So i was wondering how can i make a logs system, i wanna make a log system for admins that way i can know what they do, so i really don't know where start, i can make a system to write something to a file, but how i can make a new file when the first is full ?
     
  2. Offline

    justin_393

    Just name the file by the date, and on every server reset check if the date changed and if so make a new file with the new date and log to that.
     
  3. Offline

    MaTaMoR_

    Okay, but how i can zip the old file ?
     
  4. Offline

    justin_393

  5. Offline

    MaTaMoR_

  6. Offline

    teej107

  7. Offline

    MaTaMoR_

    I thought it will create the file if not exists

    Edit : Now the system couldn't find out the path, wutttt.

    Code:
            logger = Logger.getLogger(getClass().getSimpleName());
            logger.setLevel(Level.ALL);
         
            FileHandler handler;
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
         
            try {
             
                Date date = new Date();
             
                String fileName = getDataFolder() + File.separator + sdf.format(date) + ".log";
             
                System.out.println(fileName);
             
                File file = new File(fileName);
             
                if(!file.exists()) {
                    file.createNewFile();
                }
             
                handler = new FileHandler(fileName, LIMIT, 1, true);
                handler.setFormatter(new SimpleFormatter());
             
                logger.addHandler(handler);
             
                toLogger(Level.INFO, newLogLine());
               
            } catch (IOException | SecurityException e) {
             
                e.printStackTrace();
                System.out.println("[" + getClass().getSimpleName() + "] Error ocurred while loading, disabling...");
                setEnabled(false);
             
            }
    
     
    Last edited: Jul 10, 2015
Thread Status:
Not open for further replies.

Share This Page