Logging. 02_ Thread Handling

Source: Internet
Author: User

To facilitate logging in the business system, you can create a thread class that is dedicated to logging

Type

Tcustomlogthread = Class (TThread)

In order to ensure the validity and security of the thread logging, a critical section can be added to protect the log, while the high-frequency logging can effectively protect the logging security

Var

Fcs:trtlcriticalsection; --winapi.windows.pas

--Create--release

InitializeCriticalSection (FCS); DeleteCriticalSection (FCS);

--Enter protection--after the log processing is completed, to exit the protection, or else the thread can never log

EnterCriticalSection (FCS); LeaveCriticalSection (FCS);

------------------------------------------------------------------------

In addition, D also provides a class to encapsulate the above

Var

Fcs:tcriticalsection; --System.SyncObjs.pas--Recommended use of this type

--Create--release

FCS: = tcriticalsection.create; Fcs. Destroy;

--Enter--leave

Fcs. Enter; (FCS. Acquire) FCS. Leave; (FCS. Release)

----------------------------------------------------------------------------------------------

Protection operation: A. Access Protection; B. Logging c. exit protection

If you need to log the log level, or the type of log classification, can be handled by the following two ways

A: In the log thread, the attributes that need to be classified are identified for processing the log file or processing the contents of the Log Content node when the log is executed.

B: Another way is to create a new object class, to provide the relevant log thread object in the custom class, to record the logs of different classifications separately

In the case of scenario B, you need to configure the critical polygons in your custom class to ensure that different log threads have security access to the same log resource

If it is scenario a, you can add a critical section to the log thread to ensure security when logging functions are called by the outside world

Logging. 02_ Thread Handling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.