C言語プロジェクトのログをファイルに出力する方法についてお伺いしたいです。
下記のサイトを参考に行いたいのですが、ログを出力させるディレクトリの指定をどこで行っているのかわかりません。
https://qiita.com/owaridesuyo0212/items/0758269947d34ab71904
下記がサイトに乗っているサンプルコードです。
test.c #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h> #define TEST_OK 0 /* テスト関数戻り値(正常)*/ #define TEST_NG -1 /* テスト関数戻り値(異常)*/ #define LOG_FILE "LOG/log.txt" /* ログディレクトリ(通常) */ #define ERR_LOG_FILE "LOG/err_log.txt" /* ログディレクトリ(エラー)*/ FILE *log_file; /* 通常ログ */ FILE *err_log_file; /* 異常ログ */ /* 関数プロトタイプ宣言 */ int test_function(int num); /* テスト関数 */ void LOG_PRINT(char log_txt[256], ...); /* 通常ログ出力関数 */ void ERR_LOG_PRINT(char err_txt[256], ...); /* エラーログ出力関数*/ int main(void) { int ret = TEST_OK; int num = 0; LOG_PRINT(">>> TEST START !!! \n"); /* テスト関数起動 */ ret = test_function(num); if(ret != TEST_OK) { ERR_LOG_PRINT("test_function() NG!\n"); LOG_PRINT("<<< TEST NG END !!!\n"); return TEST_NG; } LOG_PRINT("<<< TEST END !!!\n"); return TEST_OK; } int test_function(int num) { int ret = TEST_OK; LOG_PRINT(">>>>>> test_function() START !!! \n"); if(num <= 0) { ret = TEST_NG; } LOG_PRINT("<<<<<< test_func() END !!!\n"); return ret; } void LOG_PRINT(char log_txt[256], ...) { time_t timer; struct tm *date; char str[256]; /* 時間取得 */ timer = time(NULL); date = localtime(&timer); strftime(str, sizeof(str), "[%Y/%x %H:%M:%S] ", date); if ((log_file = fopen(LOG_FILE, "a")) == NULL) { ERR_LOG_PRINT("file open error!!\n"); exit(EXIT_FAILURE); /* エラーの場合は通常、異常終了する */ } /* 文字列結合 */ strcat(str,log_txt); fputs(str, log_file); fclose(log_file); return; } void ERR_LOG_PRINT(char err_txt[256], ...) { time_t timer; struct tm *date; char str[256]; /* 時間取得 */ timer = time(NULL); date = localtime(&timer); strftime(str, sizeof(str), "[%Y/%x %H:%M:%S] ", date); if ((err_log_file = fopen("LOG/err_log.txt", "a")) == NULL) { printf("ERROR !!\n"); exit(EXIT_FAILURE); /* エラーの場合は通常、異常終了する */ } /* 文字列結合 */ strcat(str,err_txt); fputs(str, err_log_file); fclose(err_log_file); return; } 【結果】 LOG/log.txt [2017/05/05/17 00:05:00] >>> TEST START !!! [2017/05/05/17 00:05:00] >>>>>> test_function() START !!! [2017/05/05/17 00:05:00] <<<<<< test_func() END !!! [2017/05/05/17 00:05:00] <<< TEST NG END !!!

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/09/22 00:50
2017/09/22 00:54