/* _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ 【機能概要】 : ログ出力SR 各アプリから出力要求されたログ情報をログレベルと環境変数に従い、 ログファイルに出力する。可変長引数(va_list)を利用。 【作成日】 : 2021.04.23 【呼出形式】 : GG_MsgOut ( const char * cFileName # ログ出力ファイル名 , long Level # ログレベル(AP指定) , const char * cFormat,... # ログ出力フォーマット ) 【戻り値】 : なし _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ */ #include #include #include #include #include "compatible_function.h" int g_iProcessId = 0; //プロセスID int g_iTraceCount= 1; //トレース long g_lTraceLevel= -1; //トレースレベル基準値 void GG_MsgOut (const char * cFileName,long Level,const char * cFormat,... ){ FILE *fpMsg; //ログファイルポインタ char cAccessTime[16]; va_list args; va_start(args,cFormat); //トレースレベル基準値が初期値の場合は環境変数から取得する if ( g_lTraceLevel == -1 ){ g_lTraceLevel = getEnvLong("GG_LogLevel",0); if ( g_lTraceLevel < 0 ){ g_lTraceLevel = 0; } } //プロセスIDが初期値の場合はシステムから取得する if ( g_iProcessId == 0 ){ g_iProcessId = getpid(); } if ( Level > g_lTraceLevel ) return ; //ログ出力ファイルのオープン fpMsg = fopen( cFileName , "a" ) ; if ( NULL == fpMsg ){ fpMsg = fopen( cFileName , "w" ) ; if ( NULL == fpMsg ){ //ファイルオープンエラーの場合、ログは標準出力 fpMsg = stdout; } #ifndef WIN32 else{ chmod( cFileName, 00666 ) ; } #endif } #ifndef WIN32 else{ chmod( cFileName, 00666 ) ; } #endif //プロセスID、ログ出力通番の出力 fprintf(fpMsg,"(%05d) (%08d) ",g_iProcessId,g_iTraceCount); if((g_lTraceLevel >= 9)||(g_lTraceLevel == 0)){ //時刻、システムログレベル、APログレベルの出力 getLocalTimeString(cAccessTime,sizeof(cAccessTime),"%H:%M:%S.%U"); fprintf(fpMsg,"(%15s) (g_lTraceLevel:%ld:Level:%ld)",cAccessTime,g_lTraceLevel,Level); } //ログ本文の出力 vfprintf(fpMsg,cFormat,args); va_end(args); fprintf(fpMsg,"\n"); if ( g_iTraceCount < 99999999 ){ g_iTraceCount ++ ; } else{ g_iTraceCount = 0; } if( fpMsg != stdout ){ fclose( fpMsg ); } return ; } //外部からシステムログレベルを変更 void GG_MsgOut_SetTraceLevel ( long Level ){ g_lTraceLevel = Level ; }