CheRt
Advanced Member | Редактировать | Профиль | Сообщение | ICQ | Цитировать | Сообщить модератору Такая мини-библиотечка записи логов: Код: # Errors logging library. Write logs into file. # Using: $result=LogError('Error message'); # Don't set $! to 'Error message', script will make it self. # Template variables: # %year% - year, # %month% - month, # %year_day% - day of year, # %month_day% - day of month, # %week_day% - day of week, # %hour% - hour, # %minute% - minute, # %second% - second, # %message_text% - text of 'Error message', # %standart_error_output% - perl error variable ($!), # %eol% - new line (\n). $ErrorLog_File='./ErrorLog.dat'; $ErrorLog_Semathor='./ErrorLog.sem'; $ErrorLog_Template='[%year%/%month%/%month_day%, yd=%year_day%, wd=%week_day%, %hour%:%minute%:%second%] %message_text%; $! Returned: %standart_error_output% %eol%'; $ErrorLog_Result=1; sub LogError { my $text=shift; &LogError_LockSemathor; open(ELF, ">>$ErrorLog_File") || ($ErrorLog_Result=0); print ELF LogError_MakeOutput($text); close(ELF); &LogError_UnlockSemathor; return $ErrorLog_Result; undef $text; } sub LogError_MakeOutput { my $text=shift; my ($sec,$min,$hour,$month_day,$mon,$year,$week_day,$year_day)=LogError_MakeTime(); $_=$ErrorLog_Template; s/%year%/$year/igs; s/%month%/$mon/igs; s/%year_day%/$year_day/igs; s/%month_day%/$month_day/igs; s/%week_day%/$week_day/igs; s/%hour%/$hour/igs; s/%minute%/$min/igs; s/%second%/$sec/igs; s/%message_text%/$text/igs; s/%standart_error_output%/$!/igs; s/%eol%/\n/igs; return $_; ($sec,$min,$hour,$month_day,$mon,$year,$week_day,$year_day,$text,$_)=-1; } sub LogError_MakeTime { my ($sec,$min,$hour,$month_day,$mon,$year,$week_day,$year_day)=(localtime(time))[0..7]; if ($sec<10) { $sec="0$sec"; } if ($min<10) { $min="0$min"; } if ($hour<10) { $hour="0$hour"; } $year_day++; $mon++; $year+=1900; return ($sec,$min,$hour,$month_day,$mon,$year,$week_day,$year_day); ($sec,$min,$hour,$month_day,$mon,$year,$week_day,$year_day)=-1; } sub LogError_LockSemathor { open(LESEM, ">$ErrorLog_Semathor") || ($ErrorLog_Result=0); flock(LESEM,2); } sub LogError_UnlockSemathor { close(LESEM); } | Извиняюсь, если напортачил с английским - не скажу, что отлично им владею... Стоит ли накидать похожую на простое логирование - запись информации о запросах?!
---------- В огне бода нет и не будет! До встречи в СССР 2.0! |
| Всего записей: 1118 | Зарегистр. 14-12-2001 | Отправлено: 02:51 08-03-2006 | Исправлено: CheRt, 20:44 09-03-2006 |
|