From: Simon Strandgaard Date: 2006-01-27T06:11:43+09:00 Subject: logging with rake Hi list, Howto capture stdout + stderr from jobs invoked with rake? I run rake from cron. I have a def log(msg) str = Time.now.to_s + ": " + msg + "\n" file = $settings['logfile'] File.open(file, 'a+') {|f| f.write str } end it only tells where it went wrong, but not what went wrong. any ideas how to do better logging with the following code? -- Simon Strandgaard desc "creates a hotcopy backup of the repository." task :backup => [:clean] do ok = true log('create hotcopy') tmpdir = $settings['backup_tmpdir_name'] repo_path = $settings['backup_repository_path'] create_hotcopy(repo_path, tmpdir) log('compressing') zipfile = $settings['backup_zipfile'] compress_dir(tmpdir, zipfile) log('encrypting') passphrase = $settings['passphrase'] cryptfile = $settings['backup_cryptfile'] encrypt_file(zipfile, cryptfile, passphrase) log('splitting into chunks') # split file into small chunks (that can go with the mail) prefix = $settings['backup_chunk_prefix'] size = $settings['backup_chunk_size'] split_file(cryptfile, size, prefix) # send a mail with each chunk attached rev = youngest_revision(tmpdir) time = Time.now.strftime('%Y%m%d') subject = "hotcopy#{time}_rev#{rev}" reciever = $settings['backup_recievers'] mime = 'application/octet-stream' chunks = Dir.glob(prefix + '*').sort log("revision #{rev}, consists of #{chunks.size} chunks.") chunks.each_with_index do |filename, index| log("sending chunk##{index+1}.") bodytext = "this is chunk##{index+1} out of #{chunks.size} in total." attachments = [[filename, mime]] begin send_mail(reciever, subject, bodytext, attachments) rescue => e log("ERROR: failed sending, #{e.inspect}") ok = false end end msg = ok ? "OK" : "with error!" log("backup completed #{msg}\n\n") end