Main. Sh (ProgramPortalCode)
The debug parameter determines whether the debug function of the logging module outputs logs for debugging. This is actually one of my concepts:
Once I decide to write the next output statement here for debugging, I will not delete this statement
I have seen a lot of developers (including myself) like to add a bunch of output statements (alert, printf, MessageBox) in the program to print a bunch of meaningless statements (such as ssssssssss, 111111) and the value of the variable, and then delete it. Then, add the variable and then delete it...
In fact, they want to determine the program status, to see if the program is running to the position where the output statement is added, or to see what the value of the program at that time is, however, they think that these log statements are not part of the business logic, but are only used for assistance and are extremely messy in writing, so they are reluctant to retain them, however, this item is very useful during debugging (especially in the development environment without one-step debugging), or even if the development is completed and deleted, when the next requirement changes, we will re-modify the program that is already correct, and we will be forced to add the deleted statement
My current philosophy is: Once I need to add the log output, I will never delete it. Therefore, I need to write every output to ensure that each output is easy to understand, it makes sense. In addition, by setting the debugging status, these statements are not output at runtime, which can avoid efficiency reduction. The following is my example, because awk does not have a ready-made logstore, this logging module is manually written by myself.
#! /Bin/ShCat$ Booklistfile | igawk-FStat.Awk-V debug =True-V stat_date = $ stat_date-V user_file = $ auditeduserfile-V stat_file = $ statfile-V script_file = $ sqlfile
Stat. awk (business logic module)
The modules referenced at the top of the file can be reused. In order to embody the modular code, no source code is provided. You only need to know what each module can do.
- Assert. awk provides the assert Function
- Logging. awk provides the debug function
- Makesql. awk provides makeinsertsql and makedeletesql functions.
One thing I'm proud of is that after I finish writing makesql. awk and think about how they should be reused, I will no longer fight for dirty jobs like SQL.
@ Include lib/assert. Awk @ Include lib /Logging. Awk @ Include lib /Makesql. Awk Function Makeuserlist (filename, userlist, __argvend __){ While (Getline <FILENAME = 1 ) {Userlist [$ 0 ]} Function Readstatresult (filename, statresult ,__ argvend __, I) {I = 1 While (Getline <FILENAME =1 ) {Statresult [I] = $ 0 I ++ } Begin {makeuserlist (user_file, userlist) readstatresult (stat_file, result) assert (length (result) = 5 , " Assertion faild: Read stat result " )} {Listid = $ 1 Userid = $2 Digest = $ 3 Debug ( " Debug 1: userid is " Userid) If (Userid In Nowuserlist) {debug ( " Debug 1.1 userid " Userid " Is find again " )} Else {Debug ( " Debug 1.2 userid " Userid " Is first find " ) Nowuserlist [userid] }}end {debug ( " \ Ndebug 2: In end block " ) Newusercounter = 0 For (I In Nowuserlist) {userid = I debug ( " Debug 2.1 Current userid is " Userid) If (I In Userlist) {debug ( " Debug 2.1.1 userid " Userid " Is not new user! " )} Else {Debug ( " Debug 2.1.2 userid " Userid " Is new user! " ) Newusercounter ++ } Debug ( " Debug 2.2 today new user count is " Newusercounter) removeinfo [ " Stat_date " ] = Stat_date makedeletesql ( " Stat_shuqi_book_list " , Removeinfo, script_file) stat [ " Posted_list " ] = Result [ 1 ] Stat [ " Posted_user " ] = Result [ 2 ] Stat [ " New_posted_list " ] = Result [ 3 ] Stat [ " New_posted_user " ] = Newusercounter stat [ " Posted_greet_list " ] = Result [ 4 ] Stat [ " New_posted_greet_list " ] = Result [ 5 ] Stat [ " Stat_date " ] = Stat_date stat [ " PV " ] = 0 Makeinsertsql ( " Stat_shuqi_book_list " , Stat, script_file )}