Welcome in the new year to my blog. On a Paris devops maillist reply to a monitor and log monitoring on, I think a long time ago one of my blog plan. Although the time of writing this blog, I was in charge of operation and maintenance work, but this paper is addressed to developers. For me, understand how logging and recording what is one of the most daunting task of software engineers must clear. This is so, because this task and forecast 2014 Nike KD 7 653997-001 Mens Basketball Shoes Orange Blue White Factory Outlet (divination) Similarly, you do Nike Air Max not know the time when you need to debug what information ...... I hope this 10 recommendations can help you better in the application log make operation and maintenance engineers benefit. :.) 1. You should never write your own log, even with printf or write to the log file of their own, or they deal with their own logrotate. Please give your operation and maintenance comrades provincial peace of mind, or the system calls the standard library API to complete it. In this way, you can ensure the operation of the program to get along with other system components, the log is written to the correct location or network 378037 010 Original?CBlack-True Red-White Air Jordan 11 Retro Nike Kids Sneakers Factory Outlet service, without the need for special system configurations. If you want to use the system API, which is syslog (3), learning how to use it well. If you prefer to use logging library, in Java you have many options, such as Log4j, JCL, slf4j and logback. My favorite combination slf4j and logback because they are particularly to the force, but also relatively easy to configure (configuration also allows the use of JMX or reload the configuration file). slf4j best is that you can modify the position of logging console. If you are writing a library, it will become very important, because it allows users to use their own logging library console without the need to modify your library. Of course there are many other languages logging libraries, such as the ruby Log4r, stdlib logger, and almost perfect Jordan Sissel's Ruby-cabin. If you want to tangle CPU usage problems, then you do not look at the article. Also, do not put log statements in the tight inner loop body, or else you'll never see the difference come. 2. You should be at the appropriate level log if you follow the approach of the first point, then Nike Air Max 2011 Men you want to your program every log statement using different log levels. One of the most difficult tasks is to identify what should be the level of the log The following are some of my suggestions: TRACE level: if used in a production environment, this is a code smell (code smell). It can be used to Nike Air Jordan 5 Women track the development process bug, but do not submit to your version control system DEBUG level: put all things are recorded here. This is most commonly used in the debug process. I suggest that before entering the production stage to reduce the number of debug statements, leaving only the most interesting part, activate the debugger (troubleshooting) time. INFO level: the user behavior (user-driven) and the specific behavior of the system (such as a scheduled task ...) NOTICE level: This is the level used in a production environment. Do not think everything is wrong, the event log can record all together WARN level: record the event at this level it is likely to become an error. For example, a database call time exceeds the preset time, or will soon reach maximum capacity memory cache. This allows you to properly alert, or when debugging a better understanding of the system done before the failure ERROR level: put every Nike Basketball error conditions are documented in this. For example API call returns an error, or internal error condition FATAL level: Doom came. It is rarely used in the program should not be any real number. At this level it means that the program carried log to an end. For example, a network daemon can not bind to the socket, then it could do only log to here, and then quit running. Remember, in your program, the default run level is highly variable. For example, I usually run my server-side code with INFO, but my desktop program using DEBUG. This is because it is hard to debug on a machine you do not have access permission, but when you're doing customer service, than to teach them how to modify the log level and then generate the log to you, my approach can make you are much more relaxed. Of course, you may have other approaches:) 3 honor the log category most logging library I mentioned in the first point allows you to specify a logging category. It can be classified log information, and configuration-based logging framework at the end of a certain 378037 010 Original?CBlack-True Red-White Air Jordan 11 Retro Nike Kids Sneakers Factory Outlet form of log or not. Typically, Java developers use the full statement at the log, qualified class name as the category name. If your program follow the principle of single responsibility (Single responsibility principle, the original is wrong), this mode is also good. In Java's logging library, Log categories are divided by grade, for example, will match the top com.daysofwonder.ranking.ELORankingComputation com.daysofwonder.ranking. This allows engineers to configure an operator under this category all ranking subsystems specified action logging. If desired, you can also generate subcategory logging configuration. Expand open, we explain the debugging particular case. Suppose you are doing an answering service requested by the user Mens Nike Free 3.0 V2 Shoes Black Blue client software (such as REST API). It is for my.service.api \u0026 lt; apitoken \u0026 gt; were log (which apitoken used to identify users). Then you can choose to my.service.api categories log, recording all the api, or my.service.api a violation of the user's API \u0026 lt;. Bad-user-api-token \u0026 gt; carried log. Of course, this requires the system to allow you to modify the logging configuration on the fly. 4. You should write meaningful log This is probably the most important recommendations. There is nothing like a deep understanding of your internal procedures, but write vague log worse. Before you write the log information, always remind myself that there is a sudden, 2015 Nike Free 5.0 when the only thing you have is from Nike Air Jordan XX8 the log file, which you have to understand what happened. This may be a subtle gap between dismissal and promotion. When developers write the log of the time, it (log statement) is written directly in the code of the environment in a variety of conditions, we should be written based on information about the current environment. Unfortunately, in the log file and not the environment, which may lead to such information it can not be understood. Resolve this situation (when writing warn and error level is particularly important) one way is to add additional information to the log message, if not, then the effect of this operation is to write. Also, do not let a log information based on the contents of the previous one. This is because the previous information may be due (with current information) is in a different category or level and not be written. Worse is that it is multi-threaded or asynchronous operation because, in another place (or in another manner) appears. 5. The log message should this proposal might appear strange in English, especially the French guy (French guy) is. I still think that English is more concise than the French, better adapted to technical language. If a message which contains more than 50 percent of English words, you have no reason to write in French, log it lost the battle of the Anglo-French side, here are the reasons behind this suggestion: English means that your log is encoded in ASCII. This is important, because you do not really know what will happen log information, or through which it was filed before the software layer and media. If you use a special message inside character sets, as well as UTF-8, it may Mens Nike Free 3.0 V2 Shoes Black Gold not be displayed correctly (render), even worse, it could be damaged in transit, it becomes unreadable. But this is also a problem, when you log user input, there may be a variety of character sets or coding. If your program is that most people use, and you do not have enough resources to do international, English will be your best choice. If you have international, then let the end-user interface and closer (closer) (This usually will not be your log) if you internationalized your log (for example, all warning and error level information), to give them a specific The meaningful error codes. Thus, the user has nothing to do with the language of the search to find relevant information. This model has been applied well for a long time in the virtual memory (VMS) operating system, and I must admit it is very useful. If you've ever designed this mode, you can also try this mode: APP-S-CODE or APP-S-SUB-CODE, which represent: APP: 3 letter abbreviations applications S: Severity 1 word abbreviations (such as D for debug, I on behalf of info) SUB: This sub-section CODE code is subordinate application: a digital code, specify this issue errors to log 6. You should bring nothing more than such a context log information is worse Transaction failed or Air Jordan Outlet User operation succeeds another or API exception: java.lang.IndexOutOfBoundsException no corresponding context, this information is just noise, they do not make sense for the debugging process values or space works (add value and consume space). Bring the context of information is much more valuable, such as: Transaction 234632 failed: cc number checksum incorrect or User 54543 successfully registered e-mail \u0026 lt; a href = \u0026 quot; mailto: user@domain.com\u0026quot; \u0026 gt; user @ domain. com \u0026 lt; / a \u0026 gt; and or IndexOutOfBoundsException: index 12 is greater than collection size 10 in this example above exception, if you want it to spread, to ensure that in dealing with the current level of take the appropriate context, let debugging easier, as an example of java: public void storeUserRank (int userId, int rank, String game) {try {... deal database ...} catch (DatabaseException de) {throw new RankingException (\u0026 quot; Can not store ranking for user \u0026 quot; + userId + \u0026 quot; in game \u0026 quot; + game + \u0026 quot; because \u0026 quot; + de.getMessage ());}} Thus, rank API upper client can have sufficient contextual information log this error. 378037 010 Original?CBlack-True Red-White Air Jordan 11 Retro Nike Kids Sneakers Factory Outlet A better approach is to let the context parameters become exception, rather than the message, if desired, the upper can amend it (use remediation). A simple method is to use the MDC reservations context of some java logging library implementation. MDC is a per-thread associative array (per thread associative array). Logger settings can be modified so that each line log always outputs MDC content. If your application uses per-thread mode, which can help solve the problem of reservations context. This example java for a given request, using the MDC record each user's information: class UserRequest {... public void execute (int userid) {MDC.put (\u0026 quot; user \u0026 quot;, userid); // ... all logged message now will display the user = \u0026 lt; userid \u0026 gt; for this thread context ... log.info (\u0026 quot; Successful execution of request \u0026 quot;); // user request processing is now finished, no need to log our current user anymore MDC .remote (\u0026 quot; user \u0026 quot;);}} Tip, MDC system in asynchronous logging mode was not good, such as Akka's logging system. Because MDC is stored in a per-thread storage area, and in an asynchronous system can not guarantee that you log in to write a thread is that the MDC. In this case, you need to use every log statement manually to log these contexts. 7. You should use a machine to play the log format parsing Log information people are very friendly, but the machine on the disaster. Sometimes manually read these log files are not enough, you need to make some automated process (for example, by an alert and review). Or if you want to centrally store your log, to conduct the search. Below, if you log embedded in the context of what happens in the string: log.info (\u0026 quot; User {} plays {} in game {} \u0026 quot;, userId, card, gameId); this will generate this text: 2013 -01-1217: 49: 37,656 [T1] INFOc.dgUserRequestUser1334563plays4ofspadesingame23425656 Now, if you want it to be resolvable, you need the following (not tested) regular expression: / User (\\ d +) plays (+.) ingame (\\ d +) $ / Well, this is not easy and error-prone, it has access to your code the string parameter. This method is how, I believe Jordan Sissel in his ruby-cabin library first introduced: in your log which joined machines can parse context format. We the above examples so you can use JSON: 2013-01-1217: 49: 37,656 [T1] INFOc.dgUserRequestUserplays {'user': 1334563, 'card': '4ofspade', 'game': 23425656} Now your log analyzer can more easily write more directly indexed, and you can release logstash all power. 8. The log should not be too much or too little of it listening to seemingly very stupid. number of log is to have a proper balance. The log will derive much valuable things difficult. When manually browse this very Nike Air Max 2011 Men confusing log, try to debug products in the morning to 3:00 of a problem is not a good thing. Too little log, you might not be able to debug the problem: Debug like to go on a difficult puzzle, you need to get enough pieces. Unfortunately, this is no magic rule to know what to log. It is necessary to Nike Air Max 2011 strictly comply with the first and second point, the program can be very flexible, easy to increase or decrease the length of the log (verbosity). One solution to this problem is to carry out log in the development process as much as possible (not to be added for program debugging log confused). When an application into the production process, the generated log conduct an analysis, changes in log statements in accordance with the problems identified. Especially when debugging, the part you need, you can have more context or logging, be sure to include these statements in the next release (you can, at the same time to solve this problem to make it stay fresh in memory). Of course, this requires a lot of communication between operation and maintenance personnel and developers. This is a complex task, but I recommend you reconstruct logging statement, as much as you refactor your code. So we can have a tight feedback loop in modifying its products, log and log statement. If there is a continuous delivery of your organizational processes, then it will be very effective, as the ongoing reconstruction. Logging statements with code comments sibling code metadata. Keeping with the code-phase synchronous logging statement is very important. No access to information unrelated to the code running worse than debugging. 9. You should consider the reader why the application do log only answer is that someday someone will read it (or its meaning). More importantly, guess who will read it, this is a very interesting thing. For different 'Who', you will want to write the contents of log information, context, category and level will be a big difference. The 'who' include: an attempt to solve their own problems users (imagine a client or desktop application) in debugging a system administrator or product operation and maintenance engineers a debug problems during development, or in the solving product problems developer Developers understand the internal procedures, so give him much more complex than the log information to the end user. For your target readers to adjust your way of expression, as well as adding additional category to this end (dedicate separate catagories). 10. You should not only for debugging log as the log have different readers, it also has the use of different reasons. Even debugging is the most obvious purpose of reading log, you can also be effectively used in the log: REVIEW: sometimes demand commercially. This can get meaningful events and management or legitimate user. Typically there will be some statement describing the system user to do something (such as who is logged in, who edited ......) on file: log is marked with a timestamp (sometimes subtle level), the program could become a filing of a good tool for each part. Such as recording the start and end of an operation, you can automate (by parsing log) or in debugging, performance metrics, without the need to put these measures added to the program. Statistics: If you every time a specific event (such as specific errors or events) log, you can run the program (or user behavior) were interesting statistics. This can add (hook) to an alarm system to continuously find a lot of error. Summary I hope this can help you generate more useful log. If I forget some essential (for you) suggested that, please understand. By the way, after you read this blog if not better log, I'm not responsible for :) If these 10 recommendations were not enough, add more useful despite suggestions in the comments.wrote Developer: 10 recommend logging
