Home > Back-end >  Multithreaded log printing series, printing confusion, the program did not collapse, complete don�
Multithreaded log printing series, printing confusion, the program did not collapse, complete don�

Time:10-04

I'm in the subway ticket machine development, the program is running on the industrial PC, there are multiple threads, contains business operations, hardware, database operations, with the communication module, etc., including hardware thread operation, dynamic libraries and hardware module of encapsulated communication, nearly nine module, serial communication module and the hardware used, I was a log file record each thread, logging class is to use the same, one day suddenly found mixed with other threads in a single thread of log logging, log and a year ago, but I log only save nearly two months, don't know where come of, the program also can be used normally, but after a problem no logging, subsequent reconciliation found wrong, have a great god help see, is what causes,

Development languages: C/C + +
Development tools: VS2010
Industrial PC platform: Windows 7 embedded version

Below is log screenshots, each file is a thread of print, the upper part is normal, to the lower part is wrong

 2020-03-09 03:58:00. 612 & lt; GetAllParamVersion> Type '9210', the current '1900010101', the future of '9999123199', update the date '19000101023000' 
The 2020-03-09 03:58:00. 612 & lt; GetAllParamVersion> Type '9220', the current '1900010101', the future of '9999123199', update the date '19000101023000'
The 2020-03-09 03:58:00. 612 & lt; GetAllParamVersion> Type '9230', the current '1900010101', the future of '9999123199', update the date '19000101023000'
The 2020-03-09 03:58:00. 614 & lt; GetAllParamVersion> Type '9240', the current '1900010101', the future of '9999123199', update the date '19000101023000'
The 2020-03-09 03:58:00. 614 & lt; GetAllParamVersion> Type '9290', the current '2019100801', the future of '9999123199', update the date '20191126145903'
327-27 06:58:35. & lt; TCP> The Send x40100c0c [0] to SC: EB3500000003
The 2019-11-27 06:58:39. 960 & lt; SendToSC> The message (0 x00100c0c), m_waitAckFlag: 0
The 2019-11-27 06:58:39. 960 & lt; TCP> The Send x00100c0c [0] to SC: EB3400000003
The 2019-11-27 06:58:39. 981 & lt; TCP> Recv the from SC: EB3500000003
The 2019-11-27 06:58:39. 981 & lt; TCP> SLE client: 6 byte (s) converted, serial id is 00.
The 2019-11-27 06:58:39. 981 & lt; SC> Receive the link test the response from the client [0]
The 2019-11-27 06:58:44. 754 & lt; TCP> Recv the from SC: EB3400000003
The 2019-11-27 06:58:44. 754 & lt; TCP> SLE client: 6 byte (s) converted, serial id is 00.



 2020-03-09 07:35:09. 394 Get clock offset=0.811569, abs=0.811569 
The 2020-03-09 07:35:09. 394 Did not need time sync
The 2020-03-09 07:35:39. 313 Get clock offset=0.812896, abs=0.812896
The 2020-03-09 07:35:39. 313 Did not need time sync
R1LAST HOPPER2LAST) values (' 2019-12-26 23:39:34 '0, 34);
The 2019-12-26 23:39:34. 681 insert into SETTLE_SJTSTAT (STARTSETTLETIME, SEQNO HOPPER1LAST, HOPPER2LAST) values (' 2019-12-26 23:39:34 '0, 34);
The 2019-12-26 23:39:34. 702 insert into SETTLE_SJTSTAT (STARTSETTLETIME, SEQNO HOPPER1LAST, HOPPER2LAST) values (' 2019-12-26 23:39:34 '0, 34);
The 2019-12-26 23:39:34. 732 insert into SETTLE_CASHSTAT (STARTSETTLETIME, SEQNO HOPPER1LAST, HOPPER2LAST, NOTE1LAST, NOTE2LAST, NOTERECYCLE, NOTEBOXREMAIN, COINBOXREMAIN) values (' 2019-12-26 23:39:34, 34,0,0,0,0,0,0,0);



The following is a log print code

 bool CSleLog: : openLogFile () 
{
If (NULL!=m_logFile)
The fclose (m_logFile);

String logDate=TimeUtil: : getCurrentDate ();
M_logDate=logDate;

String log_base_path=m_path;

if (! File: : the exists (log_base_path))
{
File: : makePath (log_base_path);
}

Log_base_path +=logDate;

if (! File: : the exists (log_base_path))
{
File: : makePath (log_base_path);
}


The string filename=m_logModule log_base_path + "\ " + + ". The log ";
M_logFile=fopen (filename. C_str (), "at +");
If (NULL!=m_logFile)
{
String headStr=m_logModule + "" + m_version +" \ n ";
Fprintf (m_logFile, headStr c_str ());
The fflush (m_logFile);
}

Return (NULL!=m_logFile);
}


 void CSleLog: : info (const char * format,... ) 
{
The lock (lock_type log_mutex);

Enum {
Max_buf_length=8192,
};

//if (NULL==m_logFile)
//return;

//m_currLogCount + +;
//if (m_currLogCount & gt; Max_Log_Line_Count)
//{
//openLogFile ();
//m_currLogCount=1;
//}

Try
{
String logDate=TimeUtil: : getCurrentDate ();
If (m_logDate.com pare said (logDate)!=0)
{
OpenLogFile ();
//m_currLogCount=1;
}

If (NULL==m_logFile)
return;

Char buffer [max_buf_length + 1)={0};
Va_list ap;
Va_start (ap, format);
_vsnprintf (buffer, max_buf_length, format, ap);
Va_end (ap);

The string content (buffer);
Fprintf (m_logFile, "% s % s", TimeUtil: : getCurrentTimeStamp (). The c_str (), content. c_str ());
The fflush (m_logFile);
}
The catch (... ) {}
}

CodePudding user response:

The log push asynchronous message queue lock, working inside the can

CodePudding user response:

I want to understand, why will appear this problem, the file will only be occupied by a single thread, and other content is where come of, can you explain in detail
  • Related