Slashdot Mirror


How Should an Application's Logs Work?

emmjayell writes "You've been there, loaded up a new application (think server-based app like Apache or Samba ...), it's working okay for a few days or a few months, then the intermittent problems start. Usually it's the CEO or someone else of relative importance that is the first victim. You can't readily duplicate the problem, so you go to find out where the application put's it's logs - maybe it's in var/log/messages - maybe in it's own directory - sometimes it's right there and available in some administrative GUI. So what makes you happiest when diagnosing the problem? Do you want tools to access it? UI or command line? Do you want it formatted to use tools like cut and sed? Do you have any examples of an app that does a great job with system logging and diag logging? Background: My team is working on an application that is gearing up for a first release. We have a logging framework in place already (we are using Apache: logging.apache.org/) -- so that covers how we are logging, but not what we should log and how it should be laid out for optimal use."

93 comments

  1. My favorite logging app... by Zugot · · Score: 3, Insightful

    JBoss 4. Even though I can't figure it the first time most time I look at it, the answer is always in the log.

    Even though it is resource intensive, I prefer the developer log everything, and let me decide how verbose or terse I want the logs to be.

    --
    -- Bryan
    1. Re:My favorite logging app... by oyenstikker · · Score: 1
      --
      The masses are the crack whores of religion.
    2. Re:My favorite logging app... by zero_offset · · Score: 0, Offtopic

      Too many posts hit +4. Decrease the number of moderators.

      I hate going off-topic, but we all know /. discourages "meta-discussion" (e.g. discussion about slash itself). Anyway, I'd say a better solution would be to expand the moderation cap. Instead of topping out at +5, let the range run from +20 to -20, for example. I find a few of the -1 posts amusing or interesting -- after all I don't always agree with the mods. Really worthless GNAA crap or whatever will disappear down a deep dark hole (no pun intended), and it'll give the users a much broader range for evaluating the "worth" of up-modded posts. This is particularly worthwhile now that Karma is not a numeric quantity and is basically something nobody has good reason to care much about any more.

      Just some rambling thoughts.

      --

      Slashdot quality declines as the number of hot grits posts decreases. - Provolt's Law, Apr-09-2005

  2. Windows by dawnread · · Score: 0, Offtopic

    Event log. Standard place to find all logs.

  3. Where's the log file?? by Bozzio · · Score: 1

    Should the administrator of the software already know where the log file is saved? If he/she wanted the application to create a log file, then he/she would have made sure it work before unleashing the application.

    --
    I just pooped your party.
    1. Re:Where's the log file?? by DaveyBob · · Score: 1

      I usually emit a line to System.out.println saying where the log file is going. Saves me hours of hunting for it!

  4. loggin and microsoft by Velex · · Score: 4, Funny

    Any kid of log is fine with me as long as it's there and it gives me some kind of insight into what's going wrong, e.g. "can't open this file," "that file's corrupt," "null pointer." Of course, text files are nice, because you can actually search through them.

    Sadly, most applications for M$ operating systems usually just leave things like, "Error #543892157893421 occured." When you go to look up what error 84901257893423 is, no one in the world seems to have had it. Tech support proceeds to blame your hardware vendor, who blames your software vendor, ad nauseum. Seems like most applications for m$ operating systems just pull error numbers out of their asses.

    --
    Join the Slashcott! Stay away entirely Feb 10 thru Feb 17! Close all tabs to prevent autorefresh!
    1. Re:loggin and microsoft by Anonymous Coward · · Score: 0

      Uh, still seems to be better than what the average user can obtain from modern GNU/Linux distributions. Often software just crashes leaving no clue as to why is did.

      Haven't tried a Mac much yet, any information on application crashes in Mac OS?

    2. Re:loggin and microsoft by hubie · · Score: 1
      Tech support proceeds to blame your hardware vendor, who blames your software vendor, ad nauseum.
      This is standard computer procedure. Years ago I was working in a group where we used a Data General minicomputer. We were having some flaky behavior with it so we had a field tech come in and work on it. This guy, a hardware guy, determines that it is a problem with the software. He calls into DG to work out the software issue, and the DG software people start telling him that it must be a hardware issue. They're telling the hardware guy, who has took the machine apart and tested all the hardware, that it is a hardware issue because it certainly couldn't have been the software!
    3. Re:loggin and microsoft by magefile · · Score: 1

      Crash? What is this crash you speak of?

    4. Re:loggin and microsoft by Anonymous Coward · · Score: 0

      Only application I managed to crash on Mac OS X was ... Chess. I'm not joking, I do not really understand why it crashed or how I did it since I launched it, played a bit then when I closed the program, nothing. It stopped responding.

    5. Re:loggin and microsoft by Kalgash · · Score: 3, Informative
    6. Re:loggin and microsoft by Nyarly · · Score: 2, Funny
      Sometimes I fastasize abotu getting the SW field tech and HW field tech at the same time, and locking them both in a dis-used closet with the box until it works. Probably, I'd open the closet months later to find two stinking corpses and the server whirring with quiet malevolence.

      To paraphrase, utopia cannot begin until the last SW field tech is strangled with the entrails of the last HW field tech.

      --
      IP is just rude.
      Is there any torture so subl
    7. Re:loggin and microsoft by MrScience · · Score: 1

      Well, there's your problem. You're looking up a number that isn't the original error. :)

      --

      You quitting proves that the karma kap worked. The most annoying of the whores shut up. --CmdrTaco

  5. When Where Who What by NoSuchGuy · · Score: 4, Insightful

    Maybe you want to know

    When from Where did What by Whom

    When = ISO 8601 Timestamp (from)
    Where = IP Adress / Name of computer...
    Who = which Login /registered user did
    What requested file foo/bar?a=213b=dfg

    --
    Grundgesetz * 23. Mai 1949 - 30. November 2007 - http://www.vorratsdatenspeicherung.de/
    1. Re:When Where Who What by AndroidCat · · Score: 2, Insightful

      Yes, standard timestamps! (Especially when timezones are involved.) It's extremely irritating parsing stuff into a db for processing when someone uses a non-standard format for no good reason. I've seen sites with different formats in HTTP headers for Date and Last-Modified. Huh? And almost every domain registrar uses a slightly different format.

      --
      One line blog. I hear that they're called Twitters now.
    2. Re:When Where Who What by Anonymous Coward · · Score: 0

      My God, Yes! Many of us spent four years in college getting a CS or Engineering degree but the diffiuclty of that pales in comparison to figuring out a non-standard timestamp.

    3. Re:When Where Who What by AndroidCat · · Score: 1

      Think thousands of records with a small handful formatted in the Splutlestan National Format. Adding a few lines takes care of that, until the phase of the Moon changes or something and they go to a new format. It makes code fragile.

      --
      One line blog. I hear that they're called Twitters now.
    4. Re:When Where Who What by GoofyBoy · · Score: 1

      >I also log every sql query with that info

      For "big" applications you really can't do this because of bind variables. (You can, but it would add another level of complexity to your logging)

      If you don't know I mean, then lucky you. :)

      --
      The surprise isn't how often we make bad choices; the surprise is how seldom they defeat us.
    5. Re:When Where Who What by PaxTech · · Score: 1

      You log the DB query to the database, but do you log the insert of the log data? Then do you log the insert of the insert of the log data?

      What about the insert of the insert of the insert of the log data?

      And then you should probably be logging the insert of the insert of the insert of the insert of the log data.. and don't forget the insert of the insert of the insert of the insert^#(I*$&%*&

      Error: maximum recursion depth exceeded.

      --
      All movements for social change begin as missions, evolve into businesses, and end up as rackets.
    6. Re:When Where Who What by One+Div+Zero · · Score: 1

      Oracle products can do this. Yes, it has been proven that it isn't 100% failsafe, but they got it so it'll return an error on the original query fast enough and rare enough that it isn't an issue.

    7. Re:When Where Who What by Anonymous Coward · · Score: 0

      Actually, I have it email me if the log can't get inserted. I make the query impossible to error out, so if I get that email I know the DB id down or the server is down or something.

    8. Re:When Where Who What by bobbyjack · · Score: 1

      But what if your email is down? ;-)

      Seriously, there's no way out of this one. Anyone have a logging-to-file system that, er, logs its logging in a file ...

    9. Re:When Where Who What by Anonymous Coward · · Score: 0

      well, you can log to a file too, but I don't like text files. I want it in gmail, or through a mysql gui. Then again, I don't make super advanced stuff, so it's not a huge deal, but it's a HUGE timesaver. If you want sql logging, do it natively through the database to avoid overhead.

    10. Re:When Where Who What by wik · · Score: 1

      Once you waste time trying to parse the timestamp output of the %(#&'ing boost C++ libraries, you'll know the pain. Why can't they at least output in one of the dozen formats that /bin/time understands?

      --
      / \
      \ / ASCII ribbon campaign for peace
      x
      / \
    11. Re:When Where Who What by Fulcrum+of+Evil · · Score: 1

      For "big" applications you really can't do this because of bind variables. (You can, but it would add another level of complexity to your logging)

      I've done it in Java, and it's no big deal. You simply implement PreparedStatement with a logging feature, then dump the parameters + sql in the event of an exception. If you don't want to do that, you can usually get the pre-bind query in the event of an exception.

      --
      "We returned the General to El Salvador, or maybe Guatemala, it's difficult to tell from 10,000 feet"
  6. just some corrections... by Anonymous Coward · · Score: 0

    Shouldn't the administrator of the software already know where the log file is saved? If he/she wanted the application to create a log file, then he/she would have made sure it worked before unleashing it.

  7. Comment removed by account_deleted · · Score: 2, Interesting

    Comment removed based on user account deletion

  8. syslog! by Anonymous Coward · · Score: 4, Insightful
    The distressing part is that there's an answer: the syslog daemon, a quite capable application. The problem is that some prominent apps don't use it at all. This is in part due to the limitations of syslog, but the solution is not to reinvent the wheel, it's to modify the wheel so that it does as you wish. syslog doesn't have the facilities you want? Change it so it does. It doesn't deal with things like splitting logs for virtual (web) hosts? Change is so it does.

    I say this as a sysadmin for a large number (several thousands) of servers. So many problems could be solved by Apache et al using, and modifying where necessary, the existing solutions. But they don't, they roll their own, and so we see problems.

    I realize this is a sorta OT rant, but it's causing major problems for me at work and so I think it's justified. Stuff like rotatelog has functionality to tell Apache "dump your logs, I'm rotating the file!" (which by the way doesn't always work) which could be easily rolled into a single notification of the syslog daemon. But it isn't. For whatever perverse reason, Apache and many others decided to roll their own.

    It pisses me the fuck off, having to deal with it. The greatest shortcoming by far of OSS is this insistency on reimplemtning proven, robust, existing solutions in favor of a trivial fix. This is a particularly egregious example, one the OSS world would be served well by acknowledging.

    1. Re:syslog! by Sentry21 · · Score: 3, Interesting

      Well, I'd like to abandon syslog in favour of logging to an SQL database for everything (a central sysloggable database would be nice, a standard API and what have you). Text logs are nice, but given the choice, I'd rather put everything into MySQL. It's searchable, it's archivable, it's a lot faster to process than plaintext. A hundred megs of logs takes forever to process with perl, but if it's in the database, you can make a lot of queries live.

      SELECT SUM(transfersize)/1024 FROM logs.apache WHERE vhost = "files.darien.ca" AND date > "2005-05-01 00:00:00" AND date "2005-06-01 00:00:00"

      Now I have the amount of bandwidth (in kilobytes) that was served from my files site in the month of May. Doing this with raw logs is absurdly slow in comparison, and only gets moreso as time goes on. If you want to archive them in compressed format, you can do 'mysqldump --where="date ..." --database logs' and such.

      So my recommendation for logging: support mysql!

    2. Re:syslog! by DrSkwid · · Score: 3, Insightful

      In my experience, logging each request to a database isn't fast enough and eventually it becomes CPU overloaded.

      tab separated plain text logging is just fine and dandy. Syslog is great because it has a standard format so any tools you make will just keep on trucking.

      If you want a db of it do it in batch mode when you need it i.e.

      zcat messages.0.gz | syslogtodb | grep httpd | mysql httpd

      Why waste those CPU cycles indexing millions of lines of logging you'll never look at ?

      --
      There are places where the networks are not touching,and there are places where they are-Boeing's Lori Gunter
    3. Re:syslog! by dodobh · · Score: 1

      syslog-ng.
      Alternatively, there is a Pg logging module for Apache (dblog, IIRC).

      --
      I can throw myself at the ground, and miss.
    4. Re:syslog! by EnronHaliburton2004 · · Score: 3, Informative

      Apache and many others decided to roll their own.

      That's partially because Apache runs on Windows, which doesn't use syslog by default. Syslog also runs differently on different Unixes, and since not all Unixes are open-source, you can't always fix it.

    5. Re:syslog! by Anonymous Coward · · Score: 0

      2 slow for general use

    6. Re:syslog! by LoztInSpace · · Score: 1

      In Oracle at least, you can map a text file as a table (an external table I think it's called). Then you get the benefit of all your database processing without the overhead during the log.

    7. Re:syslog! by dhammabum · · Score: 1
      The problem with not being able to independently log virtual web hosts separately can be solved by using different facilities: local1 for host1, etc. There are up to 16 of these depending on the syslog variant. A bit of a kludge but it is there.

      I agree with the parent's rant that Unix progs don't necessarily exploit existing interfaces like syslog or tcp wrappers guess - my pet peeve is people not universally using --version or --help as parameters - perhaps if everyone continues to complain....

      Another sibling of this post states Apache et al don't use syslog because Windows(TM) doesn't have it: bollocks. One of syslogs strengths is remote logging, it is trivial to provide a syslog client in an application. IMO, this is a serious shortcoming as I don't want to have to look at tens of computers for separate log files, they should be centralised.

      --
      I am not a robot. I am a unicorn.
    8. Re:syslog! by SuiteSisterMary · · Score: 1

      Or, just do the Best of Both Worlds(tm) and dump your log to the database every night as part of the log rotation.

      --
      Vintage computer games and RPG books available. Email me if you're interested.
    9. Re:syslog! by Fulcrum+of+Evil · · Score: 1

      It pisses me the fuck off, having to deal with it. The greatest shortcoming by far of OSS is this insistency on reimplemtning proven, robust, existing solutions in favor of a trivial fix. This is a particularly egregious example, one the OSS world would be served well by acknowledging.

      If you're adminning apps that use log4j, know that a syslog appender exists and can be used with a configuration change.

      --
      "We returned the General to El Salvador, or maybe Guatemala, it's difficult to tell from 10,000 feet"
  9. The logs are in the log directory by sydb · · Score: 4, Informative

    as I once said to a colleague. /var/log

    If you have simple logging needs, log via syslog and leave the details to the site.

    For more complex needs, especially if you have several logs, /var/log/appname/* is good.

    Obviously, the logs should be a text file. You ask if special tools should be provided. For text files we already have grep, sed, awk, perl.

    The exception is if you are providing some kind of administrative GUI, say a web app. Logs that relate to specific functionality should be near the controls for that functionality. By using a GUI you are saying "I don't want to get my hands dirty" which, for time-pressed admins, is a perfectly legitimate approach for apps with complicated configuration architectures (Sendmail, WebShere 5). So the GUI should take away the complexity of having to know where the logs are. It should always be possible, though, to get at the text of the logs and run standard tools against them.

    MHO.

    --
    Yours Sincerely, Michael.
  10. Favorite logging by rjh · · Score: 2

    My favorite logs are the ones where I get control over what events get logged and in what detail they get logged. There's no such thing as a one-size-fits-all software solution; why do we believe in one-size-fits-all logging?

    The alternative is to log everything in great detail, but do so in such a way as to make it truly trivial for me to strip out everything except the specific events in which I'm interested, in the level of detail in which I'm interested.

    1. Re:Favorite logging by AndroidCat · · Score: 1

      Configurable logging with wide control over groups and level of logging is a blessing, especially when you're trying to figure out what's going wrong at a customer site with Idiot Inside. You can always turn it down/off when you don't need it or the customer site is close to a tropical beach.

      --
      One line blog. I hear that they're called Twitters now.
    2. Re:Favorite logging by archeopterix · · Score: 1
      My favorite logs are the ones where I get control over what events get logged and in what detail they get logged. There's no such thing as a one-size-fits-all software solution; why do we believe in one-size-fits-all logging?
      We, who don't, use the log4j framework. If I had one word to put into an ad for log4j it would be "flexibility". You can configure (at runtime!) what where and how your app logs things. Severity level, application-defined types of events, event data (wan't dd/yyyy/mm date format? can do!), files (rotated or not) - all this is configurable without touching a single line of code in your app.

      One thing it does not do for you is putting log statements into your code. The more logging info your app provides, the more your user can configure.

    3. Re:Favorite logging by NateTech · · Score: 1

      And configurable logs that can be configured WITHOUT restarting the parent application are even better.

      --
      +++OK ATH
  11. IT'S IS NOT ITS by Anonymous Coward · · Score: 0

    That's the message I get in my Grammar Nazi log when I put your submission through my "Grammar Macht Frei 2.0" application.

    1. Re:IT'S IS NOT ITS by Anonymous Coward · · Score: 0

      Witzbold!

  12. log4j by Anonymous Coward · · Score: 3, Informative

    is easily the best logging package.

    Configurable log levels, and you can define your own appenders.

    Eg, I typically configure an email appender for severe/fatal errors, so they come straight to my inbox. Often I know of problems before the users do as a result of this.

    Also, something described in one the Pragmatic Series of books is an RSS appender - just point your RSS reader at the channel, and wait for any errors to occur.

    1. Re:log4j by speculatrix · · Score: 1

      agreed, log4j is excellent

      the big problem with logging from java web pages is that many programmers forget that the server is multi-threaded; the answer is to have a local variable created at the start of each page from a static synchronized number which allows you to track which thread is generating the debug.

  13. It's a log by Anonymous Coward · · Score: 0, Troll

    Write to a god damned text file. Add a timestamp. Be verbose. Is it really that hard to figure out?

    1. Re:It's a log by Anonymous Coward · · Score: 2, Funny

      Write to a god damned text file. Add a timestamp. Be verbose. Is it really that hard to figure out?

      You've been there, sitting at a console peering at your application's newly created text log file after a crash. The question, naturally, turns to editors. Should you open it with vi? Maybe emacs? Is nano the tool you're looking for?

      What editor makes you happiest when viewing log files? Do you enjoy navigating with intuitive kay combinations? Does syntax highlighting make your day? Do you have any examples of an editor that does a great job with system log files? Background: My team is new to the command-line, but we're gearing up for this brave new experience.

    2. Re:It's a log by Anonymous Coward · · Score: 1, Informative

      less is the tool for log viewing, it will even show binary gob without freaking your terminal.

    3. Re:It's a log by Anonymous Coward · · Score: 0

      amen. Next up on ask slashdot: what's the best way to wipe my ass? Is ass wiping even necessary?

    4. Re:It's a log by NanoGator · · Score: 1

      " Is nano the tool you're looking for?"

      I resent that!

      --
      "Derp de derp."
  14. sendmail by Intron · · Score: 1

    Here's a great app to look at both for how to do logs right and how to do them wrong. The default setup gives one line for each email, including time/IP addr/status, all of which is good. It can also be incomprehensible and not well documented - bad.

    --
    Intron: the portion of DNA which expresses nothing useful.
  15. A good reference by delirium+of+disorder · · Score: 4, Informative
    Not log specific, but this describes the Unix-Way(tm) of doing file formats.

    http://www.faqs.org/docs/artu/ch05s02.html

    --
    ------ Take away the right to say fuck and you take away the right to say fuck the government.
  16. Document and be grep-friendly by Proteus · · Score: 4, Interesting

    I really don't much care where logs are kept or what particular format they are in. However, it's important that the man page tells me where the logs are, and clearly documents the format of the log files. What do flags mean? What do particular messages mean?

    Also, formatting the logs in such a way that they can be quickly searched with grep or parsed by a simple script is most helpful. One of my favorite loggers does this:

    MESG: 2005-05.May-09@09.02.54CDT: Started run
    WARN: 2005-05.May-09@09.03.17CDT: Couldn't find file 'control.rc', creating
    ERR!: 2005-05.May-09@09.03.18CDT: Unable to create 'control.rc', terminating
    MESG: 2005-05.May-09@09.02.54CDT: Completed run. 1 error, 1 warning.

    This lets me see everything in chronological order, but I can quickly parse the log. Splitting on ':' will yeild the first two feilds consistently, and the first four chars are *always* the type of log message. So doing something like:

    $ egrep '^ERR!: 2005-05.May-09' report.log

    Lets me immediately see all the errors for a given day. The key to good logging is, IMO, making sure that the logs can be parsed effectively.

    --
    We may not imagine how our lives could be more frustrating and complex—but Congress can. – Cullen Hightower
    1. Re:Document and be grep-friendly by Anonymous Coward · · Score: 3, Informative

      That's actually a pretty bad log format

      #1 wastes space with colons. that means you technically have the split on ": ", not " ".

      #2 doesn't put the date first. That means if you're merging logs from multiple sources, you can't just sort them.

      #3 uses some bizarre ridiculous date format that the author probably made up himself. Where does "May" come from? Is it dependent on the locale? Why does it have "05.May"?? What is CDT? There is more than one time zone that has abbreviation CDT. And if you're talking Central Daylight, well, sometimes that will be *CST* which makes parsing and conversion to UTC just that much more difficult.

      #4 The severities can't be matched by Perl and Ruby's "\w". One of them has an exclamation mark.

      So, if you're a programming, don't use that log format please! Do this:

      2005-05-06 02:04:06 error The printer is on fire!
      2005-05-06 02:05:12 notice The printer is no longer on fire.

      Where the dates are in the local time zone.

      Better yet, just print to stderr WITHOUT dates, and let an external logging package (like multilog) add them.

    2. Re:Document and be grep-friendly by P-Nuts · · Score: 1
      2005-05-06 02:04:06 error The printer is on fire! 2005-05-06 02:05:12 notice The printer is no longer on fire.

      These errors are famously generated by the unix lp drivers, which assumed that any error a printer reported that wasn't offline or out of paper was on fire.

    3. Re:Document and be grep-friendly by bobbyjack · · Score: 1

      OK, I generally agree, but I'll play devil's advocate on a couple of points.

      "#1 wastes space with colons."
      It actually looks like it's using the colon as the field separator to avoid having to deal with whitespace in the message. Although colons could also be present in the message, they're far less likely to occur than spaces. True, it's probably a nasty optimization, and I'm not sure why the colons are augmented with spaces, but it's not all bad.

      "#2 doesn't put the date first."
      Agreed, but, as you point out in #3, his date format makes just that one file non-sortable anyway! And if you're going to be merging and sorting logs of different formats, cut'ing out one field isn't too much of an overhead.

      "#3 uses some bizarre ridiculous date format..."
      Yeah, can't argue with that! ;)

      "#4 The severities can't be matched by Perl and Ruby's..."
      I so nearly know what you're referring to here... :)

    4. Re:Document and be grep-friendly by Anonymous Coward · · Score: 0

      All logs should be in GMT/UTC (+0000), and no DST. Otherwise, you need another field for the timezone offset -?\d{3}0 e.g. 0430 for strange parts of asia. And you _still_ can't sort those logs merged from multiple timezones without processing.

      You certainly can't use alphabetic timezone abbreviations without adding on non-standard suffixes. EST is a timezone in both the USA and AUS. Whoops!

      Anyone who's dealt with diagnosing network problems or fielding emails from users when your product breaks and they decide to send you logs and let you deal with it... using anything except GMT/UTC will quickly drive you insane.

  17. Comment removed by account_deleted · · Score: 1

    Comment removed based on user account deletion

  18. Always rotate your log files by EnronHaliburton2004 · · Score: 2, Insightful

    Whatever your logging strategy, please remember to rotate your logfiles.

    You'd be amazed how many Internet applications crash simply because the logs fill up the partition that hosts the application.

    This problem was threefold, because:

    1. The logfiles should never get that size
    2. Logs should usually exist on a seperate partition like /var or your custom directory under /a
    3. People usually ignore the messages in a Production debug log

    I run 12 moderate websites. We easily generate 5GB of logfiles a week (Rotated). It used to be 10GB, but then I switched off debug logging and fixed the most common errors.

    When I started my current job 1 year ago, I deleted 40GB of logs which ran back to year 2000.

    1. Re:Always rotate your log files by Anonymous Coward · · Score: 0

      Or just use multilog and never worry about it again.

      I used to put daemon management, logging, and all that crap in my apps. Then I switched to daemontools and discovered what a stupid idea that was.

      Just write a program that does something. It doesn't even have to put itself into the background (what nonesense) or even have a main loop (just let it die after one iteration). Have it print logging to stderr with catagory tags of some kind:

      general.error Bad stuff is happening
      parsing.info Did that thing

      Then run it under daemontools, You might need to check on it in 2-3 years to make sure the power supply hasn't died or something, but that's about it.

    2. Re:Always rotate your log files by PastaLover · · Score: 1

      It should be quite configurable though, so you don't loose logs. Some sites require logs to be kept for a long time (also helps if you have an intrusion into your systems which started 6 months ago or so). Needless to say, you will generally want to filter off the stuff you're interested in, zip it and move it to a backup.

    3. Re:Always rotate your log files by EnronHaliburton2004 · · Score: 1

      I absolutely agree, but forgot to put that in my post.

      Log rotation should definately be flexible.

  19. Coerce Consistency by BoyBlunder · · Score: 5, Informative
    I work for a log analysis firm, and the bane of our lives are logs where the information is presented inconsistently from one message to the next. So in some cases a message might have, say, an IP Address as the first word, and in another message its somewhere else in the line with as IP address:port, etc. It's a right royal PITA to write code to extract the IP address in this example if you have to find out every potential message that the app will ever issue in order to automate analysis.

    So, in order to make storage, analysis and reporting easy, your framework should attempt to coerce a consistent approach to the data logged - even the plaintext "human readable" data if you can. If you can do the same with metadata about the event (e.g. ID fields, links to online KBs etc), so much the better.

    BB

  20. FYI by mmkkbb · · Score: 2, Informative

    MS requires that non-MS software sets bit 29 on all custom error codes, giving absurd decimal interpetations of these codes.

    --
    -mkb
  21. User configurable levels of logging by Goyuix · · Score: 2, Insightful

    It is nice to allow the end user to specify the verbosity of the log file - do you log each request, only failures, or every entrance/exit to a function? If the log is to assist in diagnosing the error, it is nice to be able to turn on extra information that would normally just quickly fill up disk space.

    1. Re:User configurable levels of logging by Anonymous Coward · · Score: 0

      Yes, I second this. We have to go through a big process to turn debug on in our production environment because of the sudden increase in the amount of data. However, some apps use this approach where a user (mainly B2B apps) can set debug on as part of their request.
      The user sees nothing new but the logs for that particular request are in full -- its handy for fixing problems and cuts down the messing around by hours. It is the nicest solution I've seen.

  22. Errors should be clear by __david__ · · Score: 4, Insightful

    I agree with what others have said--I don't care about the format too much as long as it's text and has a timestamp in front.

    What really matters to me is that errors get logged nicely. "Error number #57575" or even "permission denied" doesn't help at all. It needs to be specific "permission denied while opening file /blah/blah" is infintely better since it lets you actually fix the error without looking something up on google. Speaking of that, if you *do* have some kind of strange error you are reporting and you know it's not going to make sense, at least make it long and unique so I *can* look it up on google. Terseness can be a good quality in a program, but it is *not* a good quality in an error log.

    Just remember, the people installing your software and using probably don't the first thing about the way it works on the inside. You have to explain to them what went wrong and give them clues on how to fix it in a short error line.

    Oh, it's also nice to have a link back to the original source line that caused the problem. In C, use __FILE__, __LINE__, and __func__ (if you have it) so that if I'm really stumped I can download your source, quickly find the error and start working backwards to find the cause. However, this could get confusing if there are a number of different versions of your code floating around, and it's not as important as the other things I mentioned.

    -David

  23. The client was denied access by configuration rule by Parsec · · Score: 3, Insightful

    To paraphrase an Apache (1.x) error I recently encountered, was: "The client was denied access by configuration rule.".

    First of all: which rule did the denial? Second: does the program recall the file or line this rule was in or on? Simply having the text or location of a rule would be a huge help in debugging.

  24. For Postfix with large mail volume use... by LuckyStarr · · Score: 1

    pflogsumm.

    Set it up with cron, get a mail every day and keep them for a few days. Saves you a lot of headache.

    For all other stuff use egrep (or grep), awk and sed. I did my own scripts to search for specific abuses. vim in command line mode may also come in handy.

    --
    Meme of the day: I browse "Disable Sigs: Checked". So should you.
  25. Tips for writing scriptable UNIX programs by reed · · Score: 2, Insightful

    Related to logging, is program output. If you are writing tools that run at a Unix console, then someday you'll want to run them from scripts and use their output:

    1. Use stdout and stderr appropriately: I should be able to run "foo > file" and see warnings on my console, but only get useful data in the file. Don't write messages to stdout if they aren't useful output. C++ has std::clog too. Don't make scripts use "grep -v" to remove random status messages or whatever.!

    2. prefix your warnings/errors with the name of the program. So if a bunch of programs run in a script-- or in the background-- you can sort them out.

    3. Indicate if something in an error or a warning.

    4. Don't get too emotional, unless it's really neccesary:

    Bad: WARNING! SOMETHING REALLY HORIBLE HAPPENED! AHH!!!

    Good: fooprogram: Warning: Something really horrible happened!

    Notice that you can use a ! at the end for emphasis, but it's not obnoxious.

    Make reasonable suggestions if you think an error might be caused by user error:

    fooprogram: Error: No status file found. (Use fooprogram -s to initialize.)
    fooprogram: Error: No response from server at localhost:2323. Did you run it first?

    (But try not to be too patronizing!)

    5. Use error codes. (in exit() or return from main). Make an enum or #defines somewhere. Document them in the man page and/or --help output.

  26. Bind Variable? by Karma+Farmer · · Score: 1

    What the heck is a bind variable?

    1. Re:Bind Variable? by bobbyjack · · Score: 1

      Thank you for encouraging me to go learn something new. I'll try to summarise; others more experienced than myself will have to forgive or correct any misinterpretation.

      'Bind variables' are, essentially, a database optimization. If you repeatedly execute many queries with the same structure, but different data values, you'll cause the underlying DBMS to repeatedly parse those statements. If you give the DBMS enough of a hint that the statements are, essentially, of the same structure, you can buy quite a lot of that parsing time back.

      A good example piece of SQL using a bind variable:
      (culled from http://www.rittman.net/archives/000832.html)

      SELECT first_name, last_name, postcode FROM customers WHERE id = :cust_no;

      Each time you execute that statement, you'll pass it a different value for cust_no, but the DBMS will only parse that statement once.

      This almost certainly varies with application - not sure MySQL offers this support quite yet.

      Not sure how this combines with stored procs, either.

    2. Re:Bind Variable? by Karma+Farmer · · Score: 1

      You described "Parameterized Queries."

      I'm not sure "parameterized queries" is what the GGP meant by "bind variables", because he mentioned that "bind variables" might only be used on "large applications." Truthfully, I thought everyone always used parameterized queries on all calls to the dabase, from all applications, large and small.

      And yes, the Perl MySQL drivers have supported this for at least the last 6 years.

    3. Re:Bind Variable? by bobbyjack · · Score: 1

      The description was based on a reading of the article to which I linked. Bind variables may well be the same as parameterized queries; maybe this is all just application-specific semantics.

      Parameterized queries are pretty much a given if you're writing stored procs anyway (yes, we're all doing that). And I bet there's a single occurence somewhere of a non-parameterized query that's more efficient than a parameterized one.

    4. Re:Bind Variable? by GoofyBoy · · Score: 1

      I did mean exactly what was explained.

      By "large" I meant "heavily used". It just has to be worth it to see the performance improvement that not parsing the statement for the 1000th time in an hour.

      Not everyone uses parameterized queries because not everyone has to worry/encountered this optimization. One of the biggest negatives I get from programmers is that using bind variables makes it hard to figure out exactly what is happening.

      --
      The surprise isn't how often we make bad choices; the surprise is how seldom they defeat us.
    5. Re:Bind Variable? by rtz · · Score: 1

      To me, the performance boost by re-using prepared statements is one of the least important reasons to use bind variables.

      With bind variables you are sidestepping the entire problem of escaping special characters in your data, and many charset problems are solved automatically by the database driver.

      SQL injection becomes almost[*] impossible, that alone justifies using it everywhere (IMHO).

      [*] Only almost, because sometimes outside parameters are used to choose the name of a table or column, bind variables can't save you there.

    6. Re:Bind Variable? by GoofyBoy · · Score: 1

      Excellent point. I usually assume that the application level is going to prevent something like that.

      --
      The surprise isn't how often we make bad choices; the surprise is how seldom they defeat us.
  27. Some logging suggestions. by Glonoinha · · Score: 1

    While we are on the subject, let me make the following recommendations :

    1. When your app creates a new log file, put in a header. In the header put the following information : retention period, logging level, full application path and name, where the source code to this application is located, who (at the time the code was last changed) can accurately interpret the contents of this log file, the original intent / purpose of the log file, the time / date stamp of the creation of the file. If you can look at the header of any log file and understand all that you are half way there.

    2. If your log file is for debugging purposes, put in a line with ProgramName::SourceCodeFile.ext::RoutineName() and include any parameters passed in when the routine was called. If you know the parameters most of the time you can recreate the problem and step through the code by hand.

    3. You can put whatever you want in if there is an error, but for God's sake don't suppress the Java dump (stack trace) that comes at the end. Nothing worse than having absolutely nothing to work with when debugging a crash.

    4. Consider having the app create a new file on a per-day basis. It doesn't take any more room (don't forget the header as it is a new file) and you don't have to kill the application to delete the old log files. Keeps the log file sizes manageable.

    --
    Glonoinha the MebiByte Slayer
  28. tyvm by Velex · · Score: 1

    +1, informative

    --
    Join the Slashcott! Stay away entirely Feb 10 thru Feb 17! Close all tabs to prevent autorefresh!
    1. Re:tyvm by Kalgash · · Score: 3, Funny

      You're welcome. And thanks for the posted BONUS. The /. may not reflect it but you and I both know it's there.

  29. Windows 2000 by Chemisor · · Score: 2, Informative

    You know what logs I really like? The Windows 2000 system logs. All the services write in them, so there is never any hunting for files. They can have a lot of information packed into them, if the application takes some time to do it. They rotate automatically. They have severity icons so you know which ones are the errors and which are not. And they are all in a nice GUI list, so you don't need a command line PhD to view them. User friendly, indeed!

    1. Re:Windows 2000 by Drantin · · Score: 1

      Well, as it seems you mostly like the gui rather than the logs themselves; you need someone to whip up a clone for OS tools that allows for profiles of where logs are kept and displays them in a GUI similar to the windows one...

      --
      Actio personalis moritur cum persona. (Dead men don't sue)
    2. Re:Windows 2000 by Chemisor · · Score: 1

      > you mostly like the gui rather than the logs themselves

      It's more than that. The format matters too. The Linux way is to dump everything into a text file and let the human figure it out. There is no clear boundary between log messages, for example. Some messages are logged with several entries. There is no way to tell what the severity of the error is except by filtering certain logs into different files.

    3. Re:Windows 2000 by gnu-user · · Score: 1

      That's funny, I hate the windows logging GUI....

      Any real problem, and it's like finding a needle in a haystack. grep is a much more useful tool in sorting out what's going on.

      To be fair, the Windows Event Log GUI has a filtering mechanism, but I find grep to be much easier to use in practice. Further, the filtering mechanism is limited to the logging services notion of catagories ("Source" "Event Catagory", "Severity" "System"). Most of the time that I need to troubleshoot problems these catagories obscure rather then help. Real problems rarely are neatly catagroized. On the other hand, grepping on a relevant substring, and ALL the appropriate messages come up.

      grep is dirt simple to use. Absurdly simpler then the GUI (though not as pretty).

      For what it's worth the excellent folks at sysinternals (ne wininternals) have a grepable version of the event log.

  30. Make sure you ID the section of code by jjn1056 · · Score: 1

    I usually make a list of event codes to help ID the type of event or error and it's serverity. Then I make sure that whoever reads the log entry can find the line of code that generated the error.

    For example, if I am coding in perl on apache I might have a handler called 'employees.pm' ....
    sub add_employee
    {
    try { [something that generates an error]}
    catch {
    log("Error 1001 at employees.add_employee.100: Can't find the file $filename");
    }

    try { [something else that generates an error]}
    catch {
    log("Error 2001 at employees.add_employee.110: Bad ID of $ID assigned");
    }

    try { [something that generates an error]}
    catch {
    log("Error 1001 at employees.add_employee.120: Can't find the file $path/$somefile");
    }

    }

    This way I can easy find exactly where in the code the error was generated. I can also create a cron to grep the log for certain type of error codes and SMS a warning to my mobile.

    I'm sure there are perl modules that make it easier to do this, but I've been doing it this way for a while without trouble.

    --
    Peace, or Not?
    1. Re:Make sure you ID the section of code by cnvogel · · Score: 1

      frankly, I think that's not a good way to write code.

      Exceptions are great to *REDUCE* the clutter created by the endless if(doit){ error() }; sequences in non-exception-savy programming languages, but you just seem to use exceptions as some different type of return code for your functions.

      You assume that some specific exception is thrown by your functions, because you don't distinguish between the possible causes in your catch{} blocks.

      I'd say, a better way of writing would have been:

      try {
      all_your();
      functions();
      from_above();
      } catch {
      # catch different exceptions here
      }

      and in that catch{} block (don't know how perl does it...) you can distinguish between different types of exceptions, using you own subclasses of exceptions for your application specific errors. Note that even in the "generic" class of exceptions script languages allow you to obtain backtraces within the exception handler so even in some very obscure case you could spew out a error message like:

      2005-05-12 07:24:02 obscure/function.pl(open_devnull):123 open("/dev/null"): no such file or directory, called by function.pl(prepare_env):876, main.pl(initialize):1954, main.pl(TOPLEVEL): 9154

      while for the "somewhat expected" errors you could write out:

      2005-05-12 07:24:02 Could not open /dev/null: permission denied, please check if your chroot environment is set up correctly.

  31. Allow turning off/on without reboot needed by DaveyBob · · Score: 1

    We use log4j, which lets us dynamcally flip into debug mode, with more verbose info, when we want. So I've recently added support in our app for turning on debug mode logging on the fly. That's pretty big if the app's going into a hosting center...restarting the app may mean a walk to a secured room in another building, or at least remoting into the box. But even then, there's work in progress with that app you may not want to lose. What I did was set up a timer so that debug mode is turned off automagically after 24 hours, just in case the hosting center staff forget to turn it off. Be sure to test for screwy conditions that can cause the log to fill with junk.

  32. How do you alert someone that something's wrong? by DaveyBob · · Score: 1

    So your log's filled with interesting tidbits of code gone wild...who is going to find out about it? Good options are: - SNMP (for hosting centers) - Email (for hosting centers, and otherwise) - Sysout (if somebody watches the screen)

  33. Regular Expressions!!! by Anonymous Coward · · Score: 0

    Make sure you can express every single conceivable output line in each log file using the *same* regular expression. If you have optional fields (that don't appear in every line), use a set of containing braces if necessary, to keep the field mappings consistent.

    The degree to which this simplifies logfile analysis (of any kind) is staggering..

  34. Integrate with the OS' logging by mi · · Score: 1

    Do not invent your own.

    Use the openlog(3) and syslog(3). Document the facility you are going to use (like LOG_LOCAL0) and allow it to be changed through config-file or command-line option.

    Once there, use different priorities for messages of different importance (from LOG_DEBUG to LOG_EMERG) -- the verbosity can be set once during the config-processing through the openlog(3).

    There are tools to process such logs, rotate them, and to send messages to a central location. You don't need to worry about timestamping either. On better OSes (with modern syslog-daemons) run-time processing of certain messages (identified by the above-mentioned facility) is possible -- a sysadmin will be able to set things to her own liking.

    If you have to support Windows -- it has logging too, and there are API-compatible syslog.h implementations.

    --
    In Soviet Washington the swamp drains you.