In Kafka, logmanager manages all the logs on the broker (each topic-partition is a log ). By reading the source code, we can see that the specific functions are as follows:
1. Clear the Message Queue according to the preset rules.
2. Perform the flush operation on the Message Queue according to the preset rules ).
3. Connect zookeeper to perform zookeeper operations related to broker, topic, and partition.
4. Manage all the logs on the broker.
The fol
1. If you runProgramError:"Exception in thread "Main" Java. Lang. noclassdeffounderror: ORG/slf4j/loggerfactory", This is because the project lacks both the slf4j-api.jar and slf4j-log4j12.jar jar packages.
2. If an error occurs in the running program:"Java. Lang. noclassdeffounderror: ORG/Apache/log4j/logmanager", This is because the project lacks the jar package log4j. jar.
3. Error:"Exception in thread "Main" Java. Lang. nosuchmethoderror: org.
who need it.
Implementation
Model column download
For more information, see the sample program content: inversion of logging.(* The execution example can be executed normally only after the system administrator privilege is granted .)
Ilogger
To switch the Log Module, you must first create an abstract ilogger interface. So that the system can use the log function only by relying on this abstraction module. The Log Module for system replacement needs to implement this ilogger interface to prov
corner of the software design, so this module should be easy to call.
First, you can use the EventLog class in the. NET Framework for system logs. This class can add Application log records to the Windows event viewer, which can easily meet the above system log Requirements, so I chose to use it to build my system log part.
Second, you can use files or database tables to record operation logs. The advantage of using a file record is that it is easy to view and transmit. The disadvantage is
A log that supports different logger name writes to different files, different logger name logs are written to different MongoDB collection. Logmanager is easier to call, because the internal methods are all using underscores, the use of the underscore is that the protection and private methods do not need to call the outside world, do not need to understand him, at the time of the call Pycharm will not automatically complete the hint of these underli
Log System:The log records all the events, system initialization, status, and performance information of the ogre-based program each time it runs. The output content is stored on the disk file. The default file name is ogre. log. You can also manually display the creation log system, which needs to be implemented before the Root object is created.// Create an instance of LogManager prior to using LogManager
the defined value is related to the type, but not the object state.
As I have mentioned earlier, the so-called "object" can be called a type instance. Taking the class type as an example, after defining a class type, you need to create an object of this type, it must be instantiated. You can call its attributes or methods. For example, the name, password, signin, and signout methods of the user type are all related to objects. To call these attributes and methods, you can only call them by in
parent
==>logmanager: The management of all logger within the entire JVM, logger generation, acquisition, and so on, depend on it and also include configuration file reads. Logmanager will have a Hashtable "private hashtable
==>handler: Used to control log output, For example, the JDK comes with Consolehanlder to redirect the output stream to the System.err output, and every time the logger method is invok
not the object state.
As I have mentioned earlier, the so-called "object" can be called a type instance. Taking the class type as an example, after defining a class type, you need to create an object of this type, it must be instantiated. You can call its attributes or methods. For example, the name, password, signin, and signout methods of the user type are all related to objects. To call these attributes and methods, you can only call them by instantiating objects, as shown below:User user =
java.util.logging.LogManagerthe manages the internal Logger hierarchy, and initiates Logger the configuration of the ' s, either through the Configu Ration class or configuration file.There is a single instantiated in the LogManager whole JVM. It's a singleton, in the other words. Here's how to obtain the LogManager instance:Logmanager manager = Logmanager.getlogmanager (); You won't often need to interact
download the source code of log4net myself and see how it works.
If we need to configure different ilogs, the process is like this. First, we need to create an ILoggerRepository to configure the Log Level and various Appender, then, you can use LogManager to obtain an Ilog object in ILoggerRepository to write logs. The Code is as follows:
Public static ILog GetLogger (string repositoryName = "") {if (string. isNullOrEmpty (repositoryName) return
If we need to configure different ilogs, the process is like this. First, we need to create an ILoggerRepository to configure the Log Level and various Appender, then, you can use LogManager to obtain an Ilog object in ILoggerRepository to write logs. The Code is as follows:
Copy codeThe Code is as follows:Public static ILog GetLogger (string repositoryName = ""){If (string. IsNullOrEmpty (repositoryName) return L
Sun developed a logger in jdk1.4, and related classes are organized in the Java. util. Logging package. The most important is the logger class. Its instances can help us record log information.
We often use the following two steps to record log information:
Logger log = logger. getlogger ("log name ");
Log.info ("information to be recorded ");
So, what is behind this simple two-step operation?
Let's take a look at the implementation of the logger. getlogger (...) method:
Public static synchroniz
The default external configuration file is the lib/logging. properties file in JRE. You can open this file and modify the following two actions:
. Level = ALL//...Java. util. logging. lelehandler. level = ALL
This method affects all jre users.
In order not to affect all users, we can also read the specified configuration file through the readConfiguration (InputStream ins) of LogManager.
[Example 1.3]:
configuration file, so you need to customize the path to the log4j profile at this time. looking for a profile: Typically, log4j creates a log instance by calling Logmanager's GetLogger (String/class) method to analyze the Logmanager source code, Logmanager did the following at initialization:
static {//By default we use a defaultrepositoryselector which always returns ' H '.
Hierarchy h = new
;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. Web. UI. webcontrols. webparts;
Using log4net;
Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Ilog logger = logmanager. getlogger ("test ");
Logger. debug ("test information ");
}
}
Finally, you can find the log file in the r
Log4j 2.0 advanced usage in development-default level (2)
After several years of development, Log4j finally ushered in its sister version, Log4j 2.0. With the emphasis on reusable component development, in addition to developing a reusable log operation class from start to end, Apache provides us with a powerful log operation package-Log4j. Major upgrades must bring significant features. We will explain the disruptive features of 2.0 in the future. Today we will look at one of its features, the
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.