Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sockets;
- import java.io.*;
- import java.time.format.DateTimeFormatter;
- import java.time.LocalDateTime;
- public class log {
- public void EscribirLog(String tipo, String IP, String comando){//tipo: {conexion, error, comando, response} IP: puede ser del servidor como del cliente, comando: ls, get, put, delete
- try {
- BufferedWriter log = new BufferedWriter(new FileWriter("log.txt", true));
- DateTimeFormatter formato = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
- LocalDateTime hora_actual = LocalDateTime.now();
- String hora_escribir = formato.format(hora_actual);
- if (tipo.equals("conexion"))
- {
- String linea = hora_escribir + tipo + IP + "conexion entrante\n";
- log.write(linea);
- log.close();
- }
- else if (tipo.equals("comando"))
- {
- String linea = hora_escribir + tipo + IP + comando+"\n";
- log.write(linea);
- log.close();
- }
- else if (tipo.equals("error"))
- {
- String linea = hora_escribir + tipo + "conexion rechazada por " + IP + "\n";
- log.write(linea);
- log.close();
- }
- else if (tipo.equals("response"))
- {
- String linea = hora_escribir + tipo + "servidor envía respuesta a " + IP + "\n";
- log.write(linea);
- log.close();
- }
- } catch (IOException e) {
- System.out.println("Ocurrió un error, es culpa del paro.");
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement