Log tracking method and device, electronic equipment and computer readable storage medium

By generating global temporary variables in the application context and using decorators to generate link identifiers and user account information, the problems of severe code intrusion and high log storage costs in existing technologies are solved, achieving low-cost and efficient log tracing and storage.

CN116483793BActive Publication Date: 2025-11-07NETEASE (HANGZHOU) NETWORK CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202310425574.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-04-18
Publication Date
2025-11-07
Estimated Expiration
2043-04-18

AI Technical Summary

Technical Problem

Existing technologies suffer from serious code intrusion and poor readability when tracking log information, especially when logging is performed at various interfaces, resulting in high development and maintenance costs, as well as increased log storage costs.

Method used

By generating global temporary variables in the application context, using decorators to generate link identifiers and user account information, and passing this information in the context, the location of the log collection module is determined by a preset detection function, thus realizing automatic log collection and printing.

Benefits of technology

It reduces development and maintenance costs, minimizes business layer code intrusion, lowers log storage costs, and improves the uniformity and efficiency of log analysis.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116483793B_ABST
    Figure CN116483793B_ABST
Patent Text Reader

Abstract

The application provides a log tracking method and device, electronic equipment and a storage medium. The method comprises: in response to receiving an operation request, generating a global temporary variable corresponding to the operation request in an application context, and obtaining a user login identifier corresponding to the operation request; calling a decorator to generate a link identifier of a link corresponding to the operation request through a universally unique identifier, and obtaining user account information corresponding to the user login identifier; saving the link identifier and the user account information in the global temporary variable, and passing the global temporary variable in the context; in response to receiving a collection request, calling a preset detection function to determine whether a log collection module is located in a request context; if the log collection module is located in the request context, calling the log collection module to obtain the link identifier and / or the user account information for logging into the client in the global temporary variable, and printing the link identifier and / or the user account information to a log output file.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computers, and in particular to a log tracking method and device, an electronic device, and a computer readable storage medium. BACKGROUND

[0002] In related technologies, in order to track log information, different log information is recorded according to actual needs at positions where operation logs need to be recorded, but performing log printing at each interface causes a large amount of code intrusion and low code readability. SUMMARY

[0003] Therefore, the present application aims to provide a log tracking method, device, electronic device, and storage medium.

[0004] To achieve the above object, in a first aspect, the present application provides a log tracking method, comprising:

[0005] In response to receiving an operation request from a client, generating a global temporary variable corresponding to the operation request in an application context, and obtaining a user login identifier corresponding to the operation request;

[0006] Calling a decorator to generate a link identifier of a link corresponding to the operation request through a universally unique identifier, and obtaining user account information corresponding to the user login identifier;

[0007] Saving the link identifier and the user account information in the global temporary variable, and passing the global temporary variable in the context;

[0008] In response to receiving a collection request from a client, calling a preset detection function to determine whether a log collection module indicated by the collection request is located in a request context;

[0009] If the log collection module is located in the request context, calling the log collection module to obtain the link identifier and / or user account information for logging into the client in the global temporary variable, and printing the link identifier and / or the user account information to a log output file.

[0010] In a second aspect, the present application provides a log tracking device, comprising:

[0011] A generating module configured to, in response to receiving an operation request from a client, generate a global temporary variable corresponding to the operation request in an application context, and obtain a user login identifier corresponding to the operation request;

[0012] The acquisition module is configured to call the decorator to generate a link identifier of a link corresponding to the operation request through a universally unique identifier, and acquire user account information corresponding to the user login identifier;

[0013] The transmission module is configured to save the link identifier and the user account information in the global temporary variable, and transmit the global temporary variable in a context.

[0014] The determination module is configured to, in response to receiving a collection request from a client, call a preset detection function to determine whether a log collection module indicated by the collection request is located in a request context.

[0015] The tracking module is configured to, if the log collection module is located in the request context, call the log collection module to acquire the link identifier and / or the user account information of the user logging in the client in the global temporary variable, and print the link identifier and / or the user account information into a log output file.

[0016] In a third aspect, the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the log tracking method of the first aspect when executing the program.

[0017] In a fourth aspect, the present application provides a non-transitory computer readable storage medium, which stores computer instructions for causing a computer to execute the log tracking method of the first aspect.

[0018] As can be seen from the above, the log tracking method, device, electronic device and storage medium provided by the present application can generate a global temporary variable corresponding to an operation request in an application context and acquire a user login identifier corresponding to the operation request when receiving an operation request from a client. The decorator can be called to generate a link identifier of a link corresponding to the operation request through a universally unique identifier, and acquire user account information corresponding to the user login identifier. Further, the link identifier and the user account information can be saved in the global temporary variable, and the global temporary variable can be transmitted in the application context and the request context. When receiving a collection request from a client, a preset detection function can be called to determine whether a log collection module indicated by the collection request is located in a request context. If the log collection module is located in the request context, the log collection module can be called to acquire the link identifier and / or the user account information of the user logging in the client in the global temporary variable, and the acquired link identifier and / or user account information can be printed into a log output file. With the help of the decorator, the context management can be assisted, the development and operation and maintenance costs can be reduced, the business layer code invasion can be reduced, and the log storage cost can be further reduced. Attached Figure Description

[0019] To more clearly illustrate the technical solutions in this application or related technologies, the drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the drawings described below are only embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0020] Figure 1 An exemplary flowchart of a log tracing method provided in an embodiment of this application is shown.

[0021] Figure 2 A schematic diagram corresponding to an application scenario according to an embodiment of this application is shown.

[0022] Figure 3 A schematic diagram of an exemplary structure of a log tracking device provided in an embodiment of this application is shown.

[0023] Figure 4 This illustration shows an exemplary structural diagram of an electronic device provided in an embodiment of this application. Detailed Implementation

[0024] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with specific embodiments and the accompanying drawings.

[0025] It should be noted that, unless otherwise defined, the technical or scientific terms used in the embodiments of this application should have the ordinary meaning understood by one of ordinary skill in the art to which this application pertains. The terms "first," "second," and similar terms used in the embodiments of this application do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the elements or objects listed after the word and their equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are only used to indicate relative positional relationships; when the absolute position of the described object changes, the relative positional relationship may also change accordingly.

[0026] As described in the background section, in order to track log information, differentiated log information is usually recorded at the location where operation logs need to be recorded, according to actual needs.

[0027] Through the research of the inventor, it is found that in the related art, performing log printing at each interface causes problems of a large amount of code invasion and low code readability. In another related art, in order to avoid a huge workload caused by separately processing at each interface layer, a simple decorator can be used to add a uniformly formatted operation log at the beginning / end of each interface, but if it is necessary to record relevant information for the interface business layer log, it is necessary to separately supplement at each log recording point, and the problem of strong code invasion still cannot be avoided, and format inconsistency is easy to cause, which is not convenient for subsequent log analysis. In another related art, in order to track a link, a unique request id is generally generated for each request, which is recorded into a log through a log parameter, and the unique request id can be read in the context of the same request at all times. At present, this can be implemented by using a global ThreadLocal object. However, ThreadLocal can achieve context transmission of the link trace_id through the storage mode of independent copies of threads, but additional maintenance costs are increased.

[0028] Therefore, the present application provides a log tracking method and device, electronic equipment and storage medium. When receiving an operation request from a client, a global temporary variable corresponding to the operation request can be generated in an application context, and a user login identifier corresponding to the operation request can be obtained. A decorator can be called to generate a link identifier corresponding to the operation request by using a universally unique identifier, and user account information corresponding to the user login identifier can be obtained. Further, the link identifier and the user account information can be saved in the global temporary variable, and the global temporary variable can be transmitted in the application context and the request context. When receiving a collection request from the client, a preset detection function can be called to determine whether a log collection module indicated by the collection request is located in the request context. If the log collection module is located in the request context, the log collection module can be called to obtain the link identifier and / or the user account information for logging into the client in the global temporary variable, and the obtained link identifier and / or the user account information can be printed to a log output file. Using the decorator to assist in context management can reduce development and operation and maintenance costs, reduce code invasion of the business layer, and further reduce log storage costs.

[0029] The log tracking method provided by the embodiments of the present application will be specifically described below through specific embodiments.

[0030] Figure 1 An exemplary flowchart of a log tracking method provided by the embodiments of the present application is shown.

[0031] Reference Figure 1 The log tracking method provided by the embodiments of the present application specifically includes the following steps:

[0032] S102: In response to receiving an operation request from a client, generating a global temporary variable corresponding to the operation request in an application context, and obtaining a user login identifier corresponding to the operation request.

[0033] S104: Calling a decorator to generate a link identifier of a link corresponding to the operation request through a universally unique identifier, and obtaining user account information corresponding to the user login identifier.

[0034] S106: Saving the link identifier and the user account information in the global temporary variable, and passing the global temporary variable in the application context and the request context.

[0035] S108: In response to receiving a collection request from a client, calling a preset detection function to determine whether a log collection module indicated by the collection request is located in a request context.

[0036] S110: If the log collection module is located in the request context, calling the log collection module to obtain the link identifier and / or user account information for logging in the client in the global temporary variable, and printing the link identifier and / or the user account information to a log output file.

[0037] In some embodiments, the method can be applied to a server, i.e., a service end, when a request is received in a current development framework of the service end from a certain client, the request can be an operation request of a user interacting with the client, such as a login request, an access request or an interaction request, etc., and then a global temporary variable corresponding to the request can be generated in an application context, for accompanying the request, and then passed in the development framework. Specifically, the current development framework can be a Flask framework, which can include an application context (also referred to as AppContext), in which a global temporary variable can be generated, which can be represented as Flask.g, which is a global temporary variable corresponding to a single request, which is created when the request is received and can be destroyed when the request ends. Therefore, it should be noted that the Flask framework layer uniformly completes the generation and destruction of the global temporary variable. It should be noted that the global temporary variable has the characteristics of a global variable, because the global temporary variable is accessible across functions, enabling function sharing. However, the global temporary variable is not a global variable in the traditional sense, because the global temporary variable is only valid in the scope of the request context, and will be destroyed when the request ends, having a temporary characteristic.

[0038] Further, there can be multiple requests at the same time, in order to ensure that each request is independent in the development framework, a local class (such as the local.Local class) in a preset function library (such as the werkzeug in the Flask framework) can be called to generate a thread identifier corresponding to each request thread, such as a thread ID, and the thread identifier is uniquely bound to the global temporary variable corresponding thereto. For example, requests A and B are received, the thread in which request A is located is thread 1, and the thread in which request B is located is thread 2, the thread identifier corresponding to request A can be 1, and the thread identifier corresponding to request B can be 2, thereby achieving mutual independence of global temporary variables of different requests, and mutual isolation and non-interference between threads.

[0039] Figure 2 A schematic diagram corresponding to an application scenario according to an embodiment of the application is shown.

[0040] In some embodiments, with reference to Figure 2 The decorator can be applied to the view corresponding to the current request, and the decorator is essentially a function. Specifically, a custom parameter level logging decorator can be selected, and a function module of the decorator can be called. For example, the decorator can be called to generate a link identifier of a link corresponding to the current request by a universally unique identifier (i.e., uuid), such as trace_id. The user login identifier corresponding to the user who sent the request can be obtained in the current request of the user, to identify the identity of the user and distinguish different users. Further, the function module in the decorator can log the storage database (such as a cookie) of the user's local terminal according to the user login identifier, and the user account information corresponding to the user login identifier can be obtained in the storage database, and it is determined whether the user account indicated by the user account information is valid or has request permission, to verify whether the user account is valid. For example, when it is determined that the user account indicated by the user account information is valid, the link identifier and the user account information are saved in a global temporary variable and are passed in the context. Specifically, the global temporary variable can be passed in each context in the current development framework in turn. It should be noted that the context in the development framework includes but is not limited to an application context and a request context.

[0041] In some embodiments, the parse_param method can be overridden based on the logging.Logger base class, where logging.Logger is a log processing module and the parse_param method is an execution method that can uniformly manage log output. Since the log module is used in multiple processes, such as Flask worker processes and asynchronous task processing processes, and only in the Flask request context (i.e., request context), the trace_id and user account information corresponding to the request can be tracked to form a call chain and then track the corresponding logs. Therefore, when receiving a collection request from the client, a preset detection function can be called to determine whether the log collection module indicated by the collection request is in the request context, where the preset detection function can be has_app_context, which can be used to test code-level data. Specifically, has_app_context can determine whether the log collection module in the current scenario is located in the request context by judging whether there is a top element of the _request_ctx_stack stack. If it is determined that there is a top element of the _request_ctx_stack stack, it is determined that the log collection module is located in the request context, i.e., the operation of collecting logs needs to be performed in the request context. It should be noted that _request_ctx_stack is a global stack that saves the request context and is an instance of LocalStack. When the current request starts, a RequestContext object is created and pushed into the _request_ctx_stack stack. For the application context, there is also a global stack named _app_ctx_stack. If the top of the _app_ctx_stack stack is empty at this time, the current AppContext is pushed into the current _app_ctx_stack. If the current request ends, the request context and the application context will also be successively out of the stack, saving the stack space.

[0042] It should be noted that the collection request can come from the client, and the request can be used to indicate the called log collection module, which can be used to collect log information, such as link identifiers in global temporary variables and / or user account information used to log in to the client.

[0043] Further, when the log collection module is determined to be in the request context, since the link identifier and the user account information are determined to be in the request context, the link identifier and / or the user account information in the global temporary variable can be obtained by an obtaining function, such as a getattr function, in the log collection module. Specifically, the context object to be invoked can be determined according to the current request, it is determined whether the context object to be invoked is a global temporary variable, and if the context object to be invoked is a global temporary variable, the obtaining function can be called to obtain the link identifier and / or the user account information in the global temporary variable.

[0044] It should be noted that the collection of logs can be automatically performed by the server, for example, when the link identifier and / or the user account information are stored in the global temporary variable, a corresponding log file can be generated, and when it is determined that the log file is generated, the server can automatically call the log collection module to collect the log file.

[0045] In some embodiments, in order to facilitate the analysis work after obtaining the logs, the log format can be unified. Specifically, the log structure body parameter input type corresponding to the log output file (that is, the log msg parameter input type) can be formatted into a dictionary type, where the log structure body parameter input type supports multiple types such as strings, dictionaries, objects, and the like, and then a log structure body dictionary (that is, a log msg dictionary) is determined. Further, the parameter type corresponding to the link identifier and / or the user account information is formatted into a dictionary type, and then the link identifier and / or the user account information is added to the msg dictionary, and the link identifier and / or the user account information is printed to the log output file.

[0046] Reference Figure 2 The user can collect the log output file through the big data platform, and then further analyze the log output file.

[0047] In some embodiments, since the decorator is applied to a specific view, when a request is received, the function modules in the decorator can be automatically executed, and the link identifier and the user account information are added to all application-level / business-level logs under the corresponding interface by default.

[0048] It can be seen from the above that the application provides a log tracking method and device, an electronic device and a storage medium. When receiving an operation request from a client, a global temporary variable corresponding to the operation request can be generated in an application context, and a user login identifier corresponding to the operation request can be obtained. A decorator can be called to generate a link identifier of a link corresponding to the operation request through a universally unique identifier, and user account information corresponding to the user login identifier can be obtained. Further, the link identifier and the user account information can be saved in the global temporary variable, and the global temporary variable can be passed in the application context and the request context. When receiving a collection request from the client, a preset detection function can be called to determine whether a log collection module indicated by the collection request is located in the request context. If the log collection module is located in the request context, the log collection module can be called to obtain the link identifier in the global temporary variable and / or the user account information used to log in the client, and the obtained link identifier and / or user account information can be printed to a log output file. With the help of the decorator and the context management, the development and operation and maintenance costs can be reduced, the business layer code invasion can be reduced, and the log storage cost can be further reduced.

[0049] It should be noted that the method of the embodiments of the application can be executed by a single device, such as a computer or a server. The method of the embodiments can also be applied to a distributed scenario, and completed by multiple devices cooperating with each other. In this distributed scenario, one of the multiple devices can only execute one or more steps in the method of the embodiments of the application, and the multiple devices can interact with each other to complete the method.

[0050] It should be noted that some embodiments of the application have been described above. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in a different order than the order described above and still achieve the desired result. In addition, the processes depicted in the figures do not necessarily require the particular order shown or sequential order to achieve the desired results. In certain implementations, multitasking and parallel processing can be advantageous.

[0051] Figure 3 An exemplary structural schematic diagram of a log tracking device provided by the embodiments of the application is shown.

[0052] Based on the same inventive concept, the application also provides a log tracking device corresponding to any of the above-mentioned method embodiments.

[0053] Reference Figure 3 The log tracking device comprises a generation module, an obtaining module, a passing module, a determination module and a tracking module, wherein,

[0054] a generating module, configured to generate a global temporary variable corresponding to the operation request in the application context and acquire a user login identifier corresponding to the operation request in response to receiving the operation request from the client;

[0055] an acquiring module, configured to call a decorator to generate a link identifier of a link corresponding to the operation request through a universally unique identifier and acquire user account information corresponding to the user login identifier;

[0056] a passing module, configured to save the link identifier and the user account information in the global temporary variable and pass the global temporary variable in the application context and the request context;

[0057] a determining module, configured to determine whether a log collection module indicated by the collection request is located in the request context by calling a preset detection function in response to receiving the collection request from the client;

[0058] a tracking module, configured to acquire the link identifier and / or user account information for logging in the client in the global temporary variable by calling the log collection module if the log collection module is located in the request context, and print the link identifier and / or the user account information into a log output file.

[0059] In a possible implementation, the generating module is further configured to:

[0060] call a local class in a preset function library to generate a thread identifier of a thread in which the current request is located, and uniquely bind the thread identifier and the global temporary variable.

[0061] In a possible implementation, the acquiring module is further configured to:

[0062] log into a storage database of a local terminal of the user according to the user login identifier;

[0063] acquire user account information corresponding to the user login identifier in the storage database.

[0064] In a possible implementation, the passing module is further configured to:

[0065] determine whether a user account indicated by the user account information is valid;

[0066] if the user account indicated by the user account information is valid, save the link identifier and the user account information in the global temporary variable, and pass the global temporary variable in the application context and the request context.

[0067] In a possible implementation, the tracking module is further configured to:

[0068] in response to receiving the log calling request, determine a context object to be called according to the log calling request;

[0069] determine whether the context object to be called is the global temporary variable;

[0070] if the context object to be called is the global temporary variable, call the log collection module to obtain the link identifier and / or the user account information in the global temporary variable.

[0071] In a possible implementation, the tracking module is further configured to:

[0072] format a log structure parameter input type corresponding to the log output file into a dictionary type, and determine a log structure dictionary;

[0073] format a parameter type corresponding to the link identifier and / or the user account information into a dictionary type to add the link identifier and / or the user account information into the log structure dictionary, and print the link identifier and / or the user account information into the log output file.

[0074] In a possible implementation, the obtaining module is further configured to:

[0075] apply the decorator to a view corresponding to the current request to call the decorator to generate a link identifier of a link corresponding to the current request through a universally unique identifier.

[0076] In a possible implementation, the apparatus further includes a destroying module.

[0077] The destroying module is configured to:

[0078] determine whether the log output file has been sent to the client;

[0079] if the log output file has been sent to the client, destroy the global temporary variable corresponding to the current request.

[0080] For the convenience of description, the above apparatus is described in various modules in terms of functions. Of course, the functions of the modules can be implemented in one or more software and / or hardware in the implementation of the present application.

[0081] The apparatuses in the above embodiments are used to implement the corresponding log tracking methods in any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which are not described herein again.

[0082] Figure 4 An exemplary structural schematic diagram of an electronic device is shown.

[0083] Based on the same inventive concept, the present application also provides an electronic device corresponding to the method of any of the above embodiments, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the log tracking method of any of the above embodiments. Figure 4 An exemplary hardware structural schematic diagram of an electronic device is shown, which can comprise a processor 410, a memory 420, an input / output interface 430, a communication interface 440, and a bus 450. The processor 410, the memory 420, the input / output interface 430, and the communication interface 440 are connected to each other through the bus 450 for internal communication.

[0084] The processor 410 can be implemented by a general-purpose CPU (Central Processing Unit), a microprocessor, an ASIC (Application Specific Integrated Circuit), or one or more integrated circuits, etc., for executing related programs to implement the technical solutions provided by the embodiments of the present application.

[0085] The memory 420 can be implemented by a ROM (Read Only Memory), a RAM (Random Access Memory), a static storage device, a dynamic storage device, etc. The memory 420 can store an operating system and other application programs, and when the technical solutions provided by the embodiments of the present application are implemented by software or firmware, the related program codes are stored in the memory 420 and executed by the processor 410.

[0086] The input / output interface 430 is configured to connect an input / output module to realize information input and output. The input / output module can be configured as a component in the device (not shown in the figure) or externally connected to the device to provide corresponding functions. The input device can include a keyboard, a mouse, a touch screen, a microphone, various sensors, etc., and the output device can include a display, a speaker, a vibrator, an indicator light, etc.

[0087] The communication interface 440 is configured to connect a communication module (not shown in the figure) to realize the communication interaction between the device and other devices. The communication module can realize the communication through a wired manner (for example, a USB, a network cable, etc.) or a wireless manner (for example, a mobile network, WIFI, Bluetooth, etc.).

[0088] The bus 450 includes a path for transmitting information between various components (for example, the processor 410, the memory 420, the input / output interface 430, and the communication interface 440) of the device.

[0089] It should be noted that although the above device only shows the processor 410, the memory 420, the input / output interface 430, the communication interface 440, and the bus 450, in the specific implementation process, the device can also include other components necessary for normal operation. In addition, those skilled in the art can understand that the above device can also only contain the components necessary for the implementation of the embodiments of the present specification, and does not have to contain all the components shown in the figure.

[0090] The electronic device of the above embodiment is used to realize the corresponding log tracking method in any of the above embodiments, and has the beneficial effects of the corresponding method embodiments, which are not described here.

[0091] Based on the same inventive concept, corresponding to any of the above embodiment methods, the present application also provides a non-transitory computer readable storage medium, which stores computer instructions for causing the computer to execute the log tracking method according to any of the above embodiments.

[0092] The computer readable medium of the present embodiment includes permanent and non-permanent, removable and non-removable media, which can be realized by any method or technology to store information. The information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible by a computing device.

[0093] The computer instructions stored in the storage medium of the above embodiment are used to cause the computer to execute the log tracking method according to any of the above embodiments, and have the beneficial effects of the corresponding method embodiments, which are not described here.

[0094] Based on the same inventive concept, the disclosure also provides a computer program product comprising computer program instructions corresponding to the log tracking method described in any of the above embodiments. In some embodiments, the computer program instructions can be executed by one or more processors of a computer to cause the computer and / or the processors to perform the log tracking method described. The processor performing a corresponding step can belong to the corresponding performing subject corresponding to the step in each embodiment of the log tracking method.

[0095] The computer program product of the above embodiments is used to cause the computer and / or the processor to perform the log tracking method described in any of the above embodiments, and has the beneficial effects of the corresponding method embodiments, which are not described here again.

[0096] Those skilled in the art should understand that the discussion of any of the above embodiments is only exemplary, and is not intended to imply that the scope (including claims) of the present application is limited to these examples; the above embodiments or technical features between different embodiments can also be combined, the steps can be implemented in any order, and there are many other changes of different aspects of the embodiments of the present application as described above, which are not provided in detail for the sake of brevity. They.

[0097] In addition, in order to simplify the description and discussion, and so as not to make the embodiments of the present application difficult to understand, the known power / ground connections of integrated circuit (IC) chips and other components can or can not be shown in the provided drawings. In addition, the devices can be shown in the form of block diagrams in order to avoid making the embodiments of the present application difficult to understand, and this also takes into account the fact that the details of the implementation of these block diagram devices are highly dependent on the platform to be implemented the embodiments of the present application (i.e. these details should be fully within the understanding of those skilled in the art). Where specific details (e.g. circuits) are set forth in order to describe the exemplary embodiments of the present application, it will be apparent to those skilled in the art that the embodiments of the present application can be implemented without these specific details or with variations of these specific details. Therefore, these descriptions should be considered illustrative rather than limiting.

[0098] Although the present application has been described in conjunction with specific embodiments thereof, many alternatives, modifications and variations will be apparent to those skilled in the art in light of the foregoing description. For example, other memory architectures (e.g. dynamic RAM (DRAM)) can use the embodiments discussed.

[0099] Embodiments of the present application are intended to embrace all such alterations, modifications, and variations that fall within the broad scope of the appended claims. Accordingly, any one or more features of a given embodiment are intended to be illustrative only and not limiting of the scope of the application.

Claims

1. A log tracking method characterized by, The method comprises: in response to receiving an operation request from a client, generating a global temporary variable corresponding to the operation request in an application context, and obtaining a user login identifier corresponding to the operation request; wherein the global temporary variable is used for information transmission between the application context and a request context, and is destroyed at the end of the request; calling a decorator to generate a link identifier of a link corresponding to the operation request through a universally unique identifier, and obtaining user account information corresponding to the user login identifier; saving the link identifier and the user account information in the global temporary variable, and transmitting the global temporary variable in the application context and the request context; in response to receiving a collection request from a client, calling a preset detection function to determine whether a log collection module indicated by the collection request is located in a request context; if the log collection module is located in the request context, calling the log collection module to obtain the link identifier and / or user account information for logging into the client in the global temporary variable, and printing the link identifier and / or the user account information into a log output file.

2. The method of claim 1, wherein, After generating the global temporary variable corresponding to the operation request in the application context, the method further comprises: calling a local class in a preset function library to generate a thread identifier of a thread in which the operation request is located, and uniquely binding the thread identifier with the global temporary variable.

3. The method of claim 1, wherein, The method of obtaining the user account information corresponding to the user login identifier comprises: logging into a storage database of a local terminal of a user according to the user login identifier; obtaining the user account information corresponding to the user login identifier in the storage database.

4. The method of claim 1, wherein, The method of saving the link identifier and the user account information in the global temporary variable, and transmitting the global temporary variable in the application context and the request context comprises: determining whether a user account indicated by the user account information is valid; if the user account indicated by the user account information is valid, saving the link identifier and the user account information in the global temporary variable, and transmitting the global temporary variable in the application context and the request context.

5. The method of claim 1, wherein, The method of calling the log collection module to obtain the link identifier and / or the user account information in the global temporary variable comprises: determining a context object to be called according to the collection request; determining whether the context object to be called is the global temporary variable; if the context object to be called is the global temporary variable, calling the log collection module to obtain the link identifier and / or the user account information in the global temporary variable.

6. The method of claim 1, wherein, The method of printing the link identifier and / or the user account information into the log output file comprises: formatting a log structure parameter input type corresponding to the log output file into a dictionary type, and determining a log structure dictionary; The link identifier and / or the user account information corresponding parameter type is formatted as a dictionary type to add the link identifier and / or the user account information to the log structure dictionary, and the link identifier and / or the user account information is printed to a log output file.

7. The method of claim 1, wherein, The calling decorator generates a link identifier of a link corresponding to the operation request by a universally unique identifier, including: The decorator is applied to a view corresponding to an operation request to call the decorator to generate a link identifier of a link corresponding to the operation request by a universally unique identifier.

8. The method of claim 1, wherein, The method further includes: Determining whether the log output file has been sent to the client; If the log output file has been sent to the client, destroying the global temporary variable corresponding to the operation request.

9. A log tracking apparatus characterized by comprising: The apparatus includes: A generating module configured to, in response to receiving an operation request from a client, generate a global temporary variable corresponding to the operation request in an application context, and acquire a user login identifier corresponding to the operation request; wherein the global temporary variable is used for information transmission between the application context and a request context, and is destroyed at the end of a request; A acquiring module configured to call a decorator to generate a link identifier of a link corresponding to the operation request by a universally unique identifier, and acquire user account information corresponding to the user login identifier; A transmitting module configured to save the link identifier and the user account information in the global temporary variable, and transmit the global temporary variable in the application context and the request context; A determining module configured to, in response to receiving a collection request from a client, call a preset detection function to determine whether a log collection module indicated by the collection request is located in a request context; A tracking module configured to, if the log collection module is located in the request context, call the log collection module to acquire the link identifier and / or user account information of a user who logs in the client in the global temporary variable, and print the link identifier and / or the user account information to a log output file.

10. An electronic device comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, The processor implements the method of any one of claims 1-8 when executing the program.

11. A computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to implement the method of any one of claims 1-8.

Citation Information

Patent Citations

  • Log tracking method and device, computer equipment and storage medium

    CN108197200A