|
Last change
on this file since 46 was 14, checked in by lstark, 17 years ago |
|
first version of hvcontrol added
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 |
|
|---|
| 2 | #include "Log.h"
|
|---|
| 3 |
|
|---|
| 4 | Log::Log(char logpath[]) {
|
|---|
| 5 |
|
|---|
| 6 | char logfile[FILENAME_MAX_SIZE];
|
|---|
| 7 | time_t time_now_secs;
|
|---|
| 8 | struct tm *time_now;
|
|---|
| 9 |
|
|---|
| 10 | time(&time_now_secs);
|
|---|
| 11 | time_now = localtime(&time_now_secs);
|
|---|
| 12 |
|
|---|
| 13 | // Open log file
|
|---|
| 14 | sprintf(logfile, "%s/hvutil_%04d_%02d_%02d_%02d_%02d_%02d.log",
|
|---|
| 15 | logpath,
|
|---|
| 16 | 1900 + time_now->tm_year,
|
|---|
| 17 | 1 + time_now->tm_mon,
|
|---|
| 18 | time_now->tm_mday,
|
|---|
| 19 | time_now->tm_hour,
|
|---|
| 20 | time_now->tm_min,
|
|---|
| 21 | time_now->tm_sec);
|
|---|
| 22 | if ((logptr = fopen(logfile, "w")) == NULL) {
|
|---|
| 23 | fprintf(stderr,"Log::Log: could not open file %s => check DAQ config file\n", logfile);
|
|---|
| 24 | exit(1);
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | LogWrite("start logfile\n");
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 | Log::~Log() {
|
|---|
| 32 | LogWrite("end logfile\n");
|
|---|
| 33 | fclose(logptr);
|
|---|
| 34 | printf("Logfile closed\n");
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 | int Log::LogWrite(char logtext[]) {
|
|---|
| 39 | time_t time_now_secs;
|
|---|
| 40 | struct tm *time_now;
|
|---|
| 41 |
|
|---|
| 42 | time(&time_now_secs);
|
|---|
| 43 | time_now = localtime(&time_now_secs);
|
|---|
| 44 |
|
|---|
| 45 | fprintf(logptr, "[%04d:%02d:%02d:%02d:%02d:%02d] %s",
|
|---|
| 46 | 1900 + time_now->tm_year,
|
|---|
| 47 | 1 + time_now->tm_mon,
|
|---|
| 48 | time_now->tm_mday,
|
|---|
| 49 | time_now->tm_hour,
|
|---|
| 50 | time_now->tm_min,
|
|---|
| 51 | time_now->tm_sec,
|
|---|
| 52 | logtext);
|
|---|
| 53 | fflush(logptr);
|
|---|
| 54 |
|
|---|
| 55 | return 0;
|
|---|
| 56 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.