Record logs in a unified mode
Recording logs of various levels is an indispensable function for all applications. There are too many third-party frameworks available for the implementation of log records, such as log4net, nlog, loggr, and serilog, of course, we can also choose the Microsoft native diagnostic framework (the relevant API is defined in the namespace "system. in diagnostics .. Net core provides an independent LOG model so that we can use a unified API to program log records. We can
prepare the basic knowledge
Four components of the logging
Loggers provides interfaces that applications can use directly
Handlers send logs to the appropriate destination
Filters provides a way to filter log information
Formatters specifying the Log display format
See the code below #!/usr/bin/env python#-*-coding:utf-8-*-#pyversion:p ython3.5#owner:fuzjimport Logginglogger = Logging.getlogger ("test.conf") #创建一个
First, starting from a usage scenarioDevelop a log system that outputs logs to the console and to log filesPython code
Import logging
# Create a Logger
Logger = Logging.getlogger (' MyLogger ')
Logger.setlevel (logging. DEBUG)
# Create a handler to write to the log file
FH = logging. Filehandler (' Test.log ')
Fh.setlevel (logging. DEBUG)
# Create another handler for output to the
without altering any of the original log interfaces;
Back to top of pageLogs for single-threaded environmentsIn general, the log class is implemented as a singleton, making it easy to invoke. For simplicity, the write operation for the log code in the example is printed directly to the console. The following is the initial definition of the Logger class:Listing 1. Initial definition of the Logger clas
--------------------------------------------------------------------------------One: Introduction to LOG4J components
A: log4j three important components--loggers, appenders, Layouts
These three components work together to make it possible for developers to record information based on categories and levels of information, and to be able to run the control of information logging in a way that has been stored in a location.
B: Logger hierarchy (
restriction that cannot be solved: Virtual member functions cannot be used. However, considering that we only call the C ++ function in Lua, it is not necessary to import C ++ to Lua perfectly. This restriction is completely acceptable.
In addition, class member variables cannot be directly accessed in Lua, and can be accessed through class member functions, such as SetValue/GetValue ).
// The following is a simple C ++ class:
Class Logger
{
[Blog recommendation] logging module of python Howto (1)
This blog post is from Bkjia. If you have any questions, go to the blog page for an interactive discussion!Blog: http://xdzw608.blog.51cto.com/4812210/1608718
This article comes from the understanding of the source code added to the howto-logging section in py2.7.9 docs. The official documentation link is as follows, I am using the downloaded pdf version, should be consistent: https://docs.python.org/2/howto/logging.ht
log4jthree main componentsLoggers: A tool for logging logs, which is used to record the log information we want.Appenders (output source): Where the log output can be, console, file, stream location, database, and so on.Layouts (layout mode): The log needs to record which basic information, in what format to record the display of this information.A Logger must have at least one Appender, and a Appender has a Layout.LoggersThe
Logging Module Introduction
Python's logging module provides a common logging system that can be easily used by Third-party modules or applications. This module provides different log levels and can record logs in different ways, such as files, HTTP get/post,smtp,socket, etc., and can even implement specific logging methods for itself.The logging module is the same as the log4j mechanism, but the specific implementation details are different. module provides
Monolog is a log class library for PHP. Compared to other log class libraries, it has the following features:
Powerful. Logs can be sent to files, sockets, mailboxes, databases, and various Web services.
Follow the PSR3 interface specification. can be easily replaced with other log class libraries that follow the same specification.
Good extensibility. Through Handler , Formatter and Processor These interfaces, the Monolog class library can be extended and customized.
Basic
15th General API15.1 Log 15.1.1 Log API Introduction1, java.util.logging package provides the log function related classes and interfaces, do not need to configure the log components, can be used in the standard Java platform is its advantage. The starting point for using the log is the logger class, and the constructor for the logger class is labeled protected. A class that is not a java.util.logging packa
/index ');The code adds// This calls the Xiaoming.js file under the Routes folder var routesxiaoming= require ('./routes/xiaoming ');InApp.use ('/', routes);Next add// Xiaoming is the method on the Display page xiaoming,routesxiaoming is the above route name app.use ('/xiaoming ', routesxiaoming); // the directory displayed on the page http://localhost:8100/xiaomingThen in the command form restart input node App.js enter http://localhost:8100/xiaoming in the browserDisplay effect:is not the effe
add the start command, such as the default start, and the NPM start to represent the node./bin/www command.App.js fileLoad Dependent Library, originally this class library is encapsulated in Connect, now need to note load separatelyVarexpress = require (' Express ');Varpath = require (' path ');Varfavicon = require (' Serve-favicon ');Varlogger = require (' Morgan ');Varcookieparser = require (' Cookie-parser ');Varbodyparser = require (' Body-parser
1. How Routing control worksCode in the Routes/index.jsWhen accessing the home page, call the Ejs template engine, render the Index.ejs template file, generate a static page, and display it in the browser.function (req, res) { // capture GET request to access home page res.render (' index ', {title: ' Express ' });The official notation is to implement a simple routing assignment in App.js, and then to find the corresponding route function in the Index.js, and finally implement the routing fun
Save the list of stations to the database and create the service locallynode. JS Create Httpserver1. Build an express-based operating environmentGlobal Installation Express-gengeratorCNPM install-g Express-gengerator2. Create an express project and create a local serviceExpress ServerBuild the server directory, the bin under the directory is an executable file, run the www file under the bin to start the serviceNode server/bin/wwwStartup successfully opened browser localhost:3000App.js under Ser
1. PrefaceFor the current cloud platform solution, because of network, host status and many other factors, a single host of services on the chance of a significant increase in problems. This requires that we be able to monitor the health status of each host and every micro-service instance. so for Nodejs related projects need to do related micro-service health Check interface. without altering the original Express framework, I found a sample of the corresponding health check on the Official Ex
In real life, logging is important. Bank transfer will have a record of the transfer, the aircraft during the flight, there will be a black box (flight data logger) to record everything during the flight. If there are any problems, people can use log data to figure out what exactly happened. Logging is equally important for system development, commissioning, and operation. Without logging, you can hardly figure out what's going on when the program cra
information with the above configuration method?
Before you solve the above problems, you need to understand a few of the more important concepts,Logger,Handler,Formatter,FilterA few important concepts
The Logger recorder exposes an interface that the application code can use directly.
Handler processor that sends (logger-generated) log records
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.