Use log4cplus (3)-log redirection and log4cplus redirection

Source: Internet
Author: User

Use log4cplus (3)-log redirection and log4cplus redirection

This article describes how to output log4cplus logs to qt widgets and encapsulate serverSocket.
Log4cplus supports custom output devices. You only need to inherit from Appender or Appender subclass and implement the append member method. After log4cplus is initialized successfully, add custom output devices to logger. When a user outputs information to logger, logger traverses all output devices and Outputs Information in the specified format on the output device.
Log4cplus is thread-safe, so you can safely use it in multiple threads.

The author encountered the ESPCrash problem during the compilation of the mini-tool. After searching for documents on the Internet for a long time, I did not do a good job. Then, of course, I solved the problem because: my gadgets are written in vs2013, And the log4cplus library is compiled in vs2010. Later, I compiled log4cplus with vs2013, And the gadgets are all normal; however, the case code provided by log4cplus started to crash (normal under vs2010). Later, Baidu and Google found that some people said this was a bug in vs2013, but it was not solved in the end.
Running process of the gadgets: Start the gadgets and enable the remote connection thread W. This will not block the main ui thread. When the receiving thread receives the remote connection, enable the receipt sub-thread R to interact with the remote end, each thread updates a widget. When thread W is closed, all sub-thread R created by W is closed, and then serverSocket is closed. The data received by the R thread is transmitted to the widget by throwing an event. Of course, instead of directly throwing the data to the widget, there is a thread dedicated to processing the event, receiving various events, and then passing through the signal slot, send to the specified window and update the window to the interface.

Result 1:

Figure 1

Main classes:

1. The worker thread listens to message events.
Class MessageListening: public QThread

2. Help the worker thread to process business objects. The user listens to client connection requests.
Class Work: public QObject
Worker thread
Class WorkThread: public QThread

3. The worker thread listens to message events.
Class MessageListening: public QThread

4. The server thread is responsible for interacting with the client.
Class ClientThread: public log4cplus: thread: AbstractThread

5. The main window of the gadgets is responsible for receiving and displaying log information.
Class debugHelper: public QWidget

6. the user list displays the currently connected users + default + created users
Class CCUserListWidget: public QTreeWidget

7. Custom output device
Class CCUIAppender: public ConsoleAppender

8. The log filtering data source is responsible for providing the filtered data to the view. The data source is from QStandardItemModel.
Class CCSortFilterProxyModel: public QSortFilterProxyModel

9. The log window provides a new
Class CCLogTableWidget: public QWidget

10. Create local logs to compare logs from multiple different sources
Class CCLogListWidget: public QWidget

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.