how to log my java program flow in database?

2019-06-03 15:11发布

I want to log what methods and what values are called in my java program in a text file or data base.

      For example:========================================

      this my java program


     Class A
      { 



        public void hello()

         {

           if(call.equalsto("world")
          {

           helloworld();
           }

            if(call.equalsto("boy")
          {

           helloboy();
           }

            if(call.equalsto("girl")
                        {

           hellogirl();
           }

           }


      public void helloworld()
           {


          system.out.println("hi world")
           }


        public void helloboy()
           {


          system.out.println("hi boy")
           }

                public void hellogirl()
           {


          system.out.println("hi girl")
           }

       }

So I call methods based on the input type. How to log which method is called and which value is printed as log in a text file or database?

2条回答
三岁会撩人
2楼-- · 2019-06-03 16:04

You can use any Java logger, take log4j for example, its good documented and simple to use, take a look at this example and this one.

You can download it here.

There are several other logging tool for java, see a comparision on this list.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-06-03 16:09

You can try log4j for all kind of logging use cases. http://logging.apache.org/log4j/1.2/

查看更多
登录 后发表回答