tomcat服务器下logs文件下各个文件的含义

tomcat服务器下logs文件下各个文件的含义

Tomcat 日志分类:

分为了一下五类:

catalina 、 localhost 、 manager 、 admin 、 host-manager

1. Catalina.out:

Linux下所有的错误日志和打印语句,都放在此文件中;

package com.forcoldplay.itcast;

import java.io.File;
import java.io.IOException;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;

import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class FServlet extends HttpServlet {
    //private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public FServlet() {
        super();
        // TODO Auto-generated constructor stub
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //response.getWriter().append("Served at: ").append(request.getContextPath());
    
        System.out.println("doGet()...");
        ServletContext application =  this.getServletContext();
        Integer count = (Integer)application.getAttribute("count");
        if(count == null){
            count = 1;
        } else {
            count++;
        }
        

        response.setContentType("text/html;charset=utf-8");
        
        response.getWriter().print("        <style>");
        response.getWriter().print("          .black-background {");
        response.getWriter().print("               background-color: black;");
        response.getWriter().print("           }");
        response.getWriter().print("          p {");
        response.getWriter().print("                font-size: 26px;");
        response.getWriter().print("                font-family: monospace;");
        response.getWriter().print("            color: white;");
        response.getWriter().print("          }");
        response.getWriter().print("        </style>");
        //response.getWriter().print("        <!DOCTYPE encoding=\"utf-8\" html>");
        response.getWriter().print("        <html>");
        response.getWriter().print("           <head>");    
        response.getWriter().print("            <meta charset=\"UTF-8\">");
        response.getWriter().print("                <title>隐藏页面</title>");
        response.getWriter().print("            </head>");
        response.getWriter().print("            <body bgcolor= black>");
        response.getWriter().print("                <br> </br>");
        response.getWriter().print("                <br> </br>");
        response.getWriter().print("                <br> </br>");
        response.getWriter().print("                  <p align = \"center\">THIS PROGRAM WAS</p>");
        response.getWriter().print("                <p align = \"center\">WRITTEN BY</p>");
        response.getWriter().print("                <p align = \"center\">OPEN-REACH</p>");
        response.getWriter().print("                  <p align = \"center\">WHO LOVES NORIKO</p>");
        response.getWriter().print("                <p align = \"center\">...</p>");
        response.getWriter().print("                <br> </br>");
        response.getWriter().print("                <br> </br>");
        response.getWriter().print("                <br> </br>");
        response.getWriter().print("                <br> </br>");
        response.getWriter().print("                <br> </br>");    
        response.getWriter().print("<p size=3>访问次数:" + count + "</p>");
        application.setAttribute("count", count);
        response.getWriter().print("            </body>");
        response.getWriter().print("        </html>");
    
        

        
        
         // 收件人电子邮箱
          String to = "2860720308@qq.com";
     
          // 发件人电子邮箱
          String from = "2860720308@qq.com";
     
          // 指定发送邮件的主机为 smtp.qq.com
          String host = "smtp.qq.com";  //QQ 邮件服务器
     
          // 获取系统属性
          Properties properties = System.getProperties();
     
          // 设置邮件服务器
          properties.setProperty("mail.smtp.host", host);
     
          properties.put("mail.smtp.auth", "true");
          // 获取默认session对象
          Session session = Session.getDefaultInstance(properties,new Authenticator(){
            public PasswordAuthentication getPasswordAuthentication()
            {
             return new PasswordAuthentication("2860720308@qq.com", "qq邮箱授权码"); //发件人邮件用户名、授权码
            }
           });
     
          try{
             // 创建默认的 MimeMessage 对象
             MimeMessage message = new MimeMessage(session);
     
             // Set From: 头部头字段
             message.setFrom(new InternetAddress(from));
     
             // Set To: 头部头字段
             message.addRecipient(Message.RecipientType.TO,
                                      new InternetAddress(to));
     
             // Set Subject: 头部头字段
             message.setSubject("有人访问了你的隐藏页面");
     
             // 设置消息体
             String ip = request.getRemoteAddr();
             message.setText("访问的IP地址为:"+ip);

             // 发送消息
             Transport.send(message);
             System.out.println("Sent message successfully....from runoob.com");
          }catch (MessagingException mex) {
             mex.printStackTrace();
          }    
        
          Date date = new Date();
          System.out.println(date);
          Calendar calendar = Calendar.getInstance();
          Date time = calendar.getTime();
          System.out.println(time);
    
    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doGet(request, response);
    }

}

2.Catalina.日期.log

这个主要是记录tomcat启动时候的信息,类似于我们在eclipse中启动服务的时候在控制台看到的信息。在里面可以看到启动的JVM参数以及操作系统等日志信息。如果没有使用log4j等日志机制,系统的的错误信息与打印语句也在这个日志文件中记录。(linux下所有的日志都在catalina.out中)

3. host-manager.日期.log:

​ 这个是放tomcat的自带的manager项目的日志信息的,一般看不到有什么重要的信息,在部署tomcat项目的时候,除了把war文件直接拷贝到tomcat的webapp目录下,还有一种方法可以浏览器中管理和部署项目,那就是使用tomcat manager。

​ 默认情况下,tomcat manager是不可用的,因为它的用户角色和密码并没有正确配置。

​ 试着浏览了下这些文件,里面什么都没有

4. localhost.日期.log:

​ 主要是应用初始化(listener, filter, servlet)未处理的异常最后被tomcat捕获而输出的日志。

5.localhost_access_log.日期.txt:

这个是存放访问tomcat的请求的所有地址以及请求的路径、时间,请求协议以及返回码等信息。

6.manager.日期.log:

这个是放tomcat的自带的manager项目的日志信息的,同3

日志级别

每类日志的级别分为如下 7 种:

SEVERE (highest value) > WARNING > INFO > CONFIG > FINE > FINER > FINEST (lowest value)

日志级别的修改:

修改/conf/logging.properties文件

示例:

①设置 catalina 日志的级别为: FINE

1catalina.org.apache.juli.FileHandler.level = FINE

②禁用 catalina 日志的输出:

1catalina.org.apache.juli.FileHandler.level = OFF

③输出 catalina 所有的日志消息:

1catalina.org.apache.juli.FileHandler.level = ALL

Last modification:November 17th, 2019 at 07:07 pm
如果觉得我的文章对你有用,请随意赞赏

Leave a Comment