how to log my java program flow in database?

半世苍凉 提交于 2019-12-08 08:10:28

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/14973901/how-to-log-my-java-program-flow-in-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!