WO2023015853A1 - 一种应用日志打码方法、装置及计算机可读存储介质 - Google Patents
一种应用日志打码方法、装置及计算机可读存储介质 Download PDFInfo
- Publication number
- WO2023015853A1 WO2023015853A1 PCT/CN2022/074661 CN2022074661W WO2023015853A1 WO 2023015853 A1 WO2023015853 A1 WO 2023015853A1 CN 2022074661 W CN2022074661 W CN 2022074661W WO 2023015853 A1 WO2023015853 A1 WO 2023015853A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- log
- appender
- converter
- native
- conversion
- Prior art date
Links
- 238000000034 method Methods 0.000 title claims abstract description 53
- 238000006243 chemical reaction Methods 0.000 claims abstract description 77
- 230000007246 mechanism Effects 0.000 claims abstract description 12
- 238000004891 communication Methods 0.000 claims description 7
- 230000009466 transformation Effects 0.000 claims description 3
- 238000009420 retrofitting Methods 0.000 abstract 1
- 238000010586 diagram Methods 0.000 description 7
- 230000008901 benefit Effects 0.000 description 6
- 230000006870 function Effects 0.000 description 5
- 230000008569 process Effects 0.000 description 5
- 230000009286 beneficial effect Effects 0.000 description 4
- 230000000694 effects Effects 0.000 description 4
- 230000008859 change Effects 0.000 description 3
- 230000004048 modification Effects 0.000 description 3
- 238000012986 modification Methods 0.000 description 3
- 238000007781 pre-processing Methods 0.000 description 2
- 238000001914 filtration Methods 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 230000008520 organization Effects 0.000 description 1
- 230000000750 progressive effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/60—Protecting data
- G06F21/62—Protecting access to data via a platform, e.g. using keys or access control rules
- G06F21/6218—Protecting access to data via a platform, e.g. using keys or access control rules to a system of files or objects, e.g. local or distributed file system or database
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F21/00—Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
- G06F21/60—Protecting data
- G06F21/64—Protecting data integrity, e.g. using checksums, certificates or signatures
Definitions
- the invention belongs to the field of logs, and in particular relates to an application log coding output method, device and computer-readable storage medium.
- a Java application calls a conventional log framework such as log4j, it will input and output the original text. If the log content contains sensitive information, the sensitive information will be output to the console or log file. At this time, if it is necessary to implement coding output for sensitive information, it is generally necessary to convert the log content with sensitive information according to a fixed logic by various means before the application calls the log framework to output the log, and then use the converted coding The content is used as input to call the logging framework for output.
- the present invention provides the following solutions.
- a method for coding and outputting application logs including: using the extension mechanism of the original log recorder to load the conversion appender, using the conversion appender to load the log converter and the native appender for outputting log messages, log conversion
- the converter includes one or more log sub-converters, and uses the log converter to load the log sub-converter specified by the initialization parameter; uses the conversion appender to receive the log message sent by the native log recorder, and calls the log sub-converter specified by the initialization parameter
- the transformer performs log encoding and sends the processed log to the native appender for secure output.
- both the native log recorder and the native appender are native modules of the JAVA log framework.
- the log converter includes one or more of the following log sub-converters: a regular converter, a Json converter, a Base64 converter, and an ISO8583 converter.
- using the extension mechanism of the original log recorder to load the conversion appender also includes: the native log recorder loads the conversion appender based on the configuration file; the configuration file includes: one or more native appenders Converter class identification, log sub-converter class identification of one or more log sub-converters, conversion rules corresponding to one or more log sub-converters.
- the conversion rules corresponding to one or more log sub-converters include: regular conversion rules, which are used to replace parts of the original log content that meet regular matches according to preset replacement rules; Json conversion rules, It is used to specify the field name and replacement method of the Json object; the ISO8583 conversion rule is used to specify the field number and replacement method of the 8583 message object.
- the Json conversion rule and the ISO8583 conversion rule nest and call the regular converter or the Base64 converter during conversion.
- the native appender includes one or more of the following: a console appender, a file appender, a socket appender, and an SMTP mail appender.
- the conversion appender is compatible with any one or more of the following JAVA log frameworks: slf4j, log4j, log4j2, logback, common-logging.
- a native log recorder configured to load a transformation appender based on an extension mechanism; a transformation appender configured to Load a log converter and a native appender for outputting log messages.
- the log converter includes one or more log sub-converters; the log converter is configured to load the log sub-converter specified by the initialization parameter; the conversion appender
- the device is configured to also receive log messages sent by the native log recorder, call the log sub-converter specified by the initialization parameter to perform log encoding, and send the processed log to the native appender for safe output.
- a log coding output device including: at least one processor; and a memory connected in communication with at least one processor; wherein, the memory stores instructions that can be executed by at least one processor, and the instructions are executed by at least one processor. Executed by a processor, so that at least one processor can execute: the method of the first aspect.
- a computer-readable storage medium stores a program, and when the program is executed by a multi-core processor, the multi-core processor executes the method in the first aspect.
- a conversion appender for log coding is introduced between the native log recorder and the native appender, so that it is not necessary to modify the application It is more friendly to developers to achieve diversified log coding output, and provides one or more log sub-converters to choose from, which can further meet the diverse conversion needs.
- FIG. 1 is a schematic structural diagram of an application log coding output device according to an embodiment of the present invention
- FIG. 2 is a schematic flow diagram of an application log coding output method according to an embodiment of the present invention.
- FIG. 3 is a schematic diagram of an implementation of a coding output method for an application log according to an embodiment of the present invention.
- A/B can mean A or B; "and/or” in this article is just an association relationship describing associated objects, indicating that there can be three relationships, For example, A and/or B may mean that A exists alone, A and B exist simultaneously, and B exists alone.
- first”, “second”, etc. are used for descriptive purposes only, and should not be understood as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, a feature defined as “first”, “second”, etc. may expressly or implicitly include one or more of that feature. In the description of the embodiments of the present application, unless otherwise specified, "plurality" means two or more.
- API Application Programming Interface
- application programming interface is a predefined interface, such as a function or HTTP interface.
- Logger the native logger, is the native logging API of Java.
- slf4j Simple logging facade for Java
- slf4j Simple logging facade for Java
- Log4j (Logging for Java) is an open source Java log component used to control the destination of log output, such as console, file, etc.
- Log4j2 is an upgraded version of log4j.
- Logback is another logging component.
- Common-logging is a kind of general-purpose log, which has an open-source general-purpose log interface component, and is compatible with lightweight and does not depend on specific log implementation tools.
- JSON JavaScript Object Notation, JS Object Notation
- JSON JavaScript Object Notation, JS Object Notation
- BASE64 refers to an encoding based on 64 printable characters to represent binary data
- ISO8583 International organization for standardization 8583 message, 8583 message international standard package
- ISO8583 message refers to an international standard message format, which is widely used in bank cards.
- FIG. 1 is a schematic structural diagram of a hardware operating environment involved in the solution of the embodiment of the present invention.
- FIG. 1 is a schematic structural diagram of a hardware operating environment of a log coding output device.
- the log-based coding output device may be a terminal device such as a PC or a portable computer.
- the log coding output device may include: a processor 1001 , such as a CPU, a network interface 1004 , a user interface 1003 , a memory 1005 , and a communication bus 1002 .
- the communication bus 1002 is used to realize connection and communication between these components.
- the user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface.
- the network interface 1004 may include a standard wired interface and a wireless interface (such as a WI-FI interface).
- the memory 1005 can be a high-speed RAM memory, or a stable memory (non-volatile memory), such as a disk memory.
- the memory 1005 may also be a storage device independent of the aforementioned processor 1001 .
- the structure of the log coding output device shown in Figure 1 does not constitute a limitation to the log coding output device, and may include more or less components than those shown in the illustration, or combine certain components, or different component arrangements.
- the memory 1005 as a computer storage medium may include an operating system, a network communication module, a user interface module, and log coding output instructions (programs).
- the operating system is a program that manages and controls the hardware and software resources of the log coding output device, and supports the operation of the log coding output program and other software or programs.
- the user interface 1003 is mainly used for sending requests, data, etc.; the network interface 1004 is mainly used for connecting the background server and the background server for data communication; and the processor 1001 can be used to call Log coding output program stored in memory 1005, and perform the following operations:
- Initialization step use the extension mechanism of the original log recorder to load the conversion appender, use the conversion appender to load the log converter and the native appender for outputting log messages, and the log converter includes one or more types of log sub a converter, and using the log converter to load the log sub-converter specified by the initialization parameter;
- Operation steps use the conversion appender to receive the log message sent by the native log recorder, call the log sub-converter specified by the initialization parameter to perform log coding, and send the processed log to the native appender for safety output.
- FIG. 2 is a schematic flow diagram of a log coding output method according to an embodiment of the present application, which is used to code and output the log.
- the execution subject may be one or more electronic devices; From a program point of view, the execution subject may be a program carried on these electronic devices.
- the method provided in this embodiment may include the following steps:
- a log transformer consists of one or more log sub-transformers
- the above S201 is an initialization step, specifically, an initialization parameter is needed to perform the above initialization, and the initialization parameter specifies a log sub-converter.
- this initialization parameter can also specify a native appender.
- both the native log recorder and the native appender may be native modules of the JAVA log framework.
- the native log recorder loads the conversion appender based on the configuration file
- the configuration file includes: the appender class identifier of one or more native appenders, the log sub-converter of one or more Log sub-converter class identifier, conversion rules corresponding to one or more log sub-converters.
- the above-mentioned native appenders and log sub-converters are included in the configuration file in the form of class names, and the conversion appenders can load any one or more native appenders and log sub-converters based on the class name.
- native appenders include but are not limited to one or more of the following: console appenders, file appenders, socket appenders, SMTP mail appenders and other native appenders. Of course, other native appenders may also be included, which is not specifically limited in this application. In this way, the log can be output to the console or a file according to the requirement.
- console appender may be org.apache.log4j.ConsoleAppender or the like.
- conversion appender is compatible with any one or more of the following JAVA log frameworks: slf4j, log4j, log4j2, logback, common-logging.
- the log converter includes one or more of the following log sub-converters: regular converter, Json converter, Base64 converter, ISO8583 converter, so that various types of coding conversion can be provided.
- regular converter Json converter
- Base64 converter Json converter
- ISO8583 converter ISO8583 converter
- the conversion rules specifically include:
- the regular conversion rule which is used to replace the part of the original log content that meets the regular match according to the preset replacement rule. Examples include: ⁇ "regex ⁇ ": ⁇ " ⁇ ( ⁇ d ⁇ 6 ⁇ ) ⁇ d+( ⁇ d ⁇ 4 ⁇ )$ ⁇ ","replacement ⁇ ": ⁇ "$1 ****$2 ⁇ " ⁇ can support multiple rules to be configured at the same time.
- This regular conversion rule indicates that if the original log content received by the filter meets the regular match, it will be replaced according to the replacement rule pointed to by replacement. For example, "6228880000000008" can be converted to "622888******0008".
- the Json conversion rule is used to specify the field name and replacement method of the Json object; the conversion configuration of the Json converter needs to specify the field name and replacement method of the Json object.
- regular conversion can be nested (here also can be called by calling The implemented Base64 conversion implements the Json conversion).
- the ISO8583 conversion rule is used to specify the field number and replacement method of the 8583 message object.
- the conversion configuration of the ISO8583 converter needs to specify the field number and replacement method of the 8583 message object.
- regular conversion can be called nestedly.
- the purpose of specifying the field name of the Json object or the field name of the ISO8583 message object is to improve conversion efficiency, because the use of regular conversion can theoretically realize various coding scenarios, such as bank card strings and mobile phone number characters string, document number string, etc., but there are misjudgments that lead to excessive coding or the efficiency of multi-regular filtering of full input log content, so this application further provides sub-converters for Json objects and ISO8583 objects that are common in the daily development process .
- This S202 is also the actual operation steps of log coding output.
- FIG. 3 shows a schematic diagram of the implementation of this embodiment, where the arrows indicate the logical relationship of the application log coding device of this application, and the white blocks in the above figure
- It is Java native or third-party log components, such as JAVA applications, native loggers, console appenders, file appenders, etc.
- the gray blocks are the various components used for log encoding in this application, including conversion appenders, log converters, and various log sub-converters (regular converter, JSON converter, Base64 converter, ISO8583 converter).
- Use the extension mechanism provided by each log framework to extend and implement the conversion appender, which integrates native appenders and log converters compatible with each log framework.
- the native log recorder obtains log messages from the JAVA application.
- the native logger calls the conversion appender and passes the log message to the conversion appender.
- the conversion appender calls the log converter and passes the log content to the log converter.
- the log converter calls the log sub-converter to encode or convert sensitive information in the log content by using the log sub-converter. 5.
- the log converter passes the converted log message back to the conversion appender. 6.
- the conversion appender passes the converted log message to the native appender of the log framework for content output, thus ensuring the security of the output information.
- the native logger In the traditional JAVA application log output scheme, after the native logger obtains the log messages generated in the JAVA application, it will directly output through the console appender or file appender. In this scheme, through the native logger and The conversion appender is inserted between the native appenders, so that the log messages sent by the native logger can be coded and converted, and then the log messages after coding conversion can be output through the native appender. The whole process has no impact on the JAVA application side. feel.
- logger1/2 in the above example, only the original logger needs to be initialized, and then it can be used repeatedly in its scope, and multiple different native loggers can be declared and initialized in its scope, so that programmers can use it in the application code.
- the location of the output log is based on the content of the log to be output. Select the different native log recorders declared to complete the log coding output. In this way, there is almost no change in the programming habits, and there is no change in the log content and formal parameters to be output, and the name logger1/2 of the native logger itself is a temporary variable, which can be remembered within its scope.
- first and second are used for descriptive purposes only, and cannot be interpreted as indicating or implying relative importance or implicitly specifying the quantity of indicated technical features.
- the features defined as “first” and “second” may explicitly or implicitly include at least one of these features.
- “plurality” means at least two, such as two, three, etc., unless otherwise specifically defined.
- an embodiment of the present invention further provides a log coding output device, which is used to execute the log coding output method provided in any of the above embodiments.
- the device includes: a native log recorder configured to load a conversion appender based on an extension mechanism; a conversion appender configured to load a log converter and a native appender for outputting a log message, the log converter includes One or more log sub-transformers; the log converter is configured to load the log sub-converter specified by the initialization parameter; the conversion appender is configured to also receive log messages from the native log recorder, Call the log subconverter specified by the initialization parameter to perform log coding, and send the processed log to the native appender for safe output.
- a non-volatile computer storage medium for a log coding output method on which computer-executable instructions are stored, and the computer-executable instructions are configured to be executed when run by a processor: the above implementation The method described in the example.
- the device, device, and computer-readable storage medium provided in the embodiments of the present application correspond to the method one-to-one. Therefore, the device, device, and computer-readable storage medium also have beneficial technical effects similar to their corresponding methods.
- the beneficial technical effect of the method has been described in detail, therefore, the beneficial technical effect of the device, equipment and computer-readable storage medium will not be repeated here.
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Computer Security & Cryptography (AREA)
- Software Systems (AREA)
- General Health & Medical Sciences (AREA)
- Computer Hardware Design (AREA)
- Bioethics (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Health & Medical Sciences (AREA)
- Databases & Information Systems (AREA)
- Debugging And Monitoring (AREA)
Abstract
本发明提供了一种应用日志打码输出方法、装置、系统及计算机可读存储介质,该方法包括:利用原生日志记录器的扩展机制加载转换附加器,利用转换附加器加载日志转换器和用于输出日志消息的原生附加器,日志转换器包括一种或多种日志子转换器,以及,利用日志转换器加载初始化参数指定的日志子转换器;利用转换附加器接收原生日志记录器发来的日志消息,调用初始化参数指定的日志子转换器执行日志打码,并将经处理日志发送给原生附加器进行安全输出。利用上述方法,无需费力改造应用即可实现多样化的日志打码输出,对开发人员更友好。
Description
本申请要求于2021年08月11日提交的、申请号为202110919923.7、标题为“一种应用日志打码方法、装置及计算机可读存储介质”的中国专利申请的优先权,该中国专利申请的公开内容以引用的方式并入本文。
本发明属于日志领域,具体涉及一种应用日志打码输出方法、装置及计算机可读存储介质。
本部分旨在为权利要求书中陈述的本发明的实施方式提供背景或上下文。此处的描述不因为包括在本部分中就承认是现有技术。
Java应用调用诸如log4j的常规日志框架时均是原文输入输出,如果日志内容含有敏感信息,那么敏感信息将被输出到控制台或者日志文件中。此时,若需要实现针对敏感信息的打码输出,一般需要在应用调用日志框架来输出日志之前通过各种手段将带有敏感信息的日志内容按照固定逻辑进行转换,再用转换后的打码内容作为输入调用日志框架进行输出。
然而,这样相当于每次调用日志框架输出日志前,都需要显式的附带额外的打码预处理,应用调用日志的API会发生改变,应用需要做改造,这种方案对于开发人员的编程习惯有较大改变,并且如果由于疏忽导致某一处日志打印调用前漏加预处理,则达不到打码效果。此外,无法处理某些第三方类库内自主输出的日志。
因此,应用于诸如JAVA应用日志的日志打码输出是一个亟待解决的问题。
发明内容
针对上述现有技术中存在的问题,提出了一种应用日志打码输出方法、装置及计算机可读存储介质,利用这种方法、装置及计算机可读存储介质,能够解决上述问题。
本发明提供了以下方案。
第一方面,提供一种应用日志打码输出方法,包括:利用原生日志记录器的扩展机制加载转换附加器,利用转换附加器加载日志转换器和用于输出日志消息的原生附加器,日志转 换器包括一种或多种日志子转换器,以及,利用日志转换器加载初始化参数指定的日志子转换器;利用转换附加器接收原生日志记录器发来的日志消息,调用初始化参数指定的日志子转换器执行日志打码,并将经处理日志发送给原生附加器进行安全输出。
在一种实施方式中,原生日志记录器和原生附加器均是JAVA日志框架的原生模块。
在一种实施方式中,日志转换器包括以下中的一种或多种日志子转换器:正则转换器、Json转换器、Base64转换器、ISO8583转换器。
在一种实施方式中,利用原生日志记录器的扩展机制加载转换附加器,还包括:原生日志记录器基于配置文件而加载转换附加器;配置文件包括:一种或多种原生附加器的附加器类标识、一种或多种日志子转换器的日志子转换器类标识、对应于一种或多种日志子转换器的转换规则。
在一种实施方式中,对应于一种或多种日志子转换器的转换规则包括:正则转换规则,用于原始日志内容中符合正则匹配的部分按照预设替换规则进行替换;Json转换规则,用于指定Json对象的字段名和替换方法;ISO8583转换规则,用于指定8583报文对象的域编号和替换方法。
在一种实施方式中,Json转换规则和ISO8583转换规则在转换时嵌套调用正则转换器或Base64转换器。
在一种实施方式中,原生附加器包括以下中的一种或多种:控制台附加器、文件附加器、套接字附加器、SMTP邮件附加器。
在一种实施方式中,转换附加器兼容以下任意一种或多种JAVA日志框架:slf4j、log4j、log4j2、logback、common-logging。
在一种实施方式中,被配置为用于执行如第一方面的方法,且包括:原生日志记录器,被配置为用于基于扩展机制加载转换附加器;转换附加器,被配置为用于加载日志转换器和用于输出日志消息的原生附加器,日志转换器包括一种或多种日志子转换器;日志转换器,被配置为用于加载初始化参数指定的日志子转换器;转换附加器,被配置为还用于接收原生日志记录器发来的日志消息,调用初始化参数指定的日志子转换器执行日志打码,并将经处理日志发送给原生附加器进行安全输出。
第三方面,提供一种日志打码输出装置,包括:至少一个处理器;以及,与至少一个处理器通信连接的存储器;其中,存储器存储有可被至少一个处理器执行的指令,指令被至少一个处理器执行,以使至少一个处理器能够执行:如第一方面的方法。
第四方面,提供一种计算机可读存储介质,计算机可读存储介质存储有程序,当程序被多核处理器执行时,使得多核处理器执行如第一方面的方法。
本申请实施例采用的上述至少一个技术方案能够达到以下有益效果:本实施例中在原生日志记录器和原生附加器之间引入用于日志打码的转换附加器,如此无需费力改造应用即可实现多样化的日志打码输出,对于开发者更友好,并且提供一种或多种日志子转换器供选择,可以进一步适应多样化转换需求。
应当理解,上述说明仅是本发明技术方案的概述,以便能够更清楚地了解本发明的技术手段,从而可依照说明书的内容予以实施。为了让本发明的上述和其它目的、特征和优点能够更明显易懂,以下特举例说明本发明的具体实施方式。
通过阅读下文的示例性实施例的详细描述,本领域普通技术人员将明白本文的优点和益处以及其他优点和益处。附图仅用于示出示例性实施例的目的,而并不认为是对本发明的限制。而且在整个附图中,用相同的标号表示相同的部件。在附图中:
图1为根据本发明一实施例的应用日志打码输出装置的结构示意图;
图2为根据本发明一实施例的应用日志打码输出方法的流程示意图;
图3为根据本发明一实施例的应用日志打码输出方法的实现示意图。
在附图中,相同或对应的标号表示相同或对应的部分。
下面将参照附图更详细地描述本公开的示例性实施例。虽然附图中显示了本公开的示例性实施例,然而应当理解,可以以各种形式实现本公开而不应被这里阐述的实施例所限制。相反,提供这些实施例是为了能够更透彻地理解本公开,并且能够将本公开的范围完整的传达给本领域的技术人员。
在本申请实施例的描述中,应理解,诸如“包括”或“具有”等术语旨在指示本说明书中所公开的特征、数字、步骤、行为、部件、部分或其组合的存在,并且不旨在排除一个或多个其他特征、数字、步骤、行为、部件、部分或其组合存在的可能性。
除非另有说明,“/”表示或的意思,例如,A/B可以表示A或B;本文中的“和/或”仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。
术语“第一”、“第二”等仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”等的特征可以明示或者 隐含地包括一个或者更多个该特征。在本申请实施例的描述中,除非另有说明,“多个”的含义是两个或两个以上。
本申请中的所有代码都是示例性的,本领域技术人员根据所使用的编程语言,具体的需求和个人习惯等因素会在不脱离本申请的思想的条件下想到各种变型。
为清楚阐述本申请实施例,首先将介绍一些后续实施例中可能会出现的概念。
概念描述
API(Application Programming Interface,应用程序接口),是预先定义的接口,如函数或HTTP接口。
Logger,原生日志记录器,是Java原生的日志记录API。
slf4j(Simple logging facade for Java),是一种简单Java日志外观,用于为日志API提供一个简单统一的接口,使用户能够在部署的时候配置日志外观的实现。
Log4j(Logging for Java),是一种开源的Java日志组件,用于控制日志输出的目的地,如控制台、文件等,Log4j2是log4j升级版本。
Logback,是另一种日志组件。
Common-logging,是一种通用日志,其具有开源的通用日志接口组件,且兼容轻量级和不依赖于具体的日志实现工具。
JSON(JavaScript Object Notation,JS对象简谱),是一种轻量级数据交互格式。
BASE64,是指一种基于64个可打印字符来表示二进制数据的编码
ISO8583(International organization for standardization 8583 message,8583报文国际标准包),是指一种国际标准的报文格式,广泛应用于银行卡。
另外还需要说明的是,在不冲突的情况下,本发明中的实施例及实施例中的特征可以相互组合。下面将参考附图并结合实施例来详细说明本发明。
如图1所示,图1是本发明实施例方案涉及的硬件运行环境的结构示意图。
需要说明的是,图1即可为日志打码输出设备的硬件运行环境的结构示意图。本发明实施例基于日志打码输出设备可以是PC,便携计算机等终端设备。
如图1所示,该日志打码输出设备可以包括:处理器1001,例如CPU,网络接口1004,用户接口1003,存储器1005,通信总线1002。其中,通信总线1002用于实现这些组件之间的连接通信。用户接口1003可以包括显示屏(Display)、输入单元比如键盘(Keyboard),可选用户接口1003还可以包括标准的有线接口、无线接口。网络接口1004可选的可以包括标准的有线接口、无线接口(如WI-FI接口)。存储器1005可以是高速RAM存储器,也可 以是稳定的存储器(non-volatile memory),例如磁盘存储器。存储器1005可选的还可以是独立于前述处理器1001的存储装置。
本领域技术人员可以理解,图1中示出的日志打码输出设备结构并不构成对日志打码输出设备的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。
如图1所示,作为一种计算机存储介质的存储器1005中可以包括操作系统、网络通信模块、用户接口模块以及日志打码输出指令(程序)。其中,操作系统是管理和控制日志打码输出设备硬件和软件资源的程序,支持日志打码输出程序以及其它软件或程序的运行。
在图1所示的日志打码输出设备中,用户接口1003主要用于发送的请求、数据等;网络接口1004主要用于连接后台服务器与后台服务器进行数据通信;而处理器1001可以用于调用存储器1005中存储的日志打码输出程序,并执行以下操作:
初始化步骤:利用原生日志记录器的扩展机制加载转换附加器,利用所述转换附加器加载日志转换器和用于输出日志消息的原生附加器,所述日志转换器包括一种或多种日志子转换器,以及,利用所述日志转换器加载初始化参数指定的所述日志子转换器;
运行步骤:利用所述转换附加器接收所述原生日志记录器发来的日志消息,调用所述初始化参数指定的所述日志子转换器执行日志打码,并将经处理日志发送给所述原生附加器进行安全输出。
通过在原生日志记录器和原生附加器之间引入转换附加器,如此无需费力改造应用即可实现多样化的日志打码输出。此外,由于可以从业务逻辑中将日志转换逻辑剥离出来,便于维护业务代码。并且提供一种或多种日志子转换器供选择,可以进一步适应多样化转换需求。
图2为根据本申请一实施例的日志打码输出方法的流程示意图,用于对日志进行打码输出,在该流程中,从设备角度而言,执行主体可以是一个或者多个电子设备;从程序角度而言,执行主体相应地可以是搭载于这些电子设备上的程序。
如图2所示,本实施例提供的方法可以包括以下步骤:
S201、利用原生日志记录器的扩展机制加载转换附加器,利用转换附加器加载日志转换器和用于输出日志消息的原生附加器,利用日志转换器加载初始化参数指定的日志子转换器;其中,日志转换器包括一种或多种日志子转换器,
上述S201为初始化步骤,具体来说,需要初始化参数来执行上述初始化,该初始化参数指定日志子转换器。可选地,该初始化参数还可以指定原生附加器。
一个示例中,以正则转换器为例详细说明,原生日志记录器初始化为Logger.getLogger("正则转换器标识"),这里Logger是Java原生日志记录器,原生日志记录器对应配置的appender-ref ref="正则转换器名"指定日志子转换器。
可选地,可以声明或初始化多个不同的原生日志记录器,比如Logger1、Logger2,进一步将不同的原生日志记录器对应不同的日志子转换器,比如对应于分别对应于正则转换器和BASE64转换器。以便程序员在应用代码拟输出日志的位置根据待输出日志内容具体选择所声明的不同原生日志记录器来完成日志打码输出。
在一实施例中,原生日志记录器和原生附加器可以均是JAVA日志框架的原生模块。
在一实施例中,S201中,原生日志记录器基于配置文件而加载转换附加器,配置文件包括:一种或多种原生附加器的附加器类标识、一种或多种日志子转换器的日志子转换器类标识、对应于一种或多种日志子转换器的转换规则。上述原生附加器和日志子转换器以类名的形式包含在配置文件中,转换附加器可以基于类名加载需要的任意一种或多种原生附加器和日志子转换器。
在一实施例中,原生附加器包括但不限于以下中的一种或多种:控制台附加器、文件附加器、套接字附加器、SMTP邮件附加器等多种原生附加器。当然还可以包括其他的原生附加器,本申请对此不作具体限制。从而可以按照需求实现将日志输出至控制台或者文件中。
一个示例中,上述控制台附加器可以是org.apache.log4j.ConsoleAppender等。在一实施例中,转换附加器兼容以下任意一种或多种JAVA日志框架:slf4j、log4j、log4j2、logback、common-logging。
在一实施例中,日志转换器包括以下中的一种或多种日志子转换器:正则转换器、Json转换器、Base64转换器、ISO8583转换器,从而可以提供多种类型的打码转换。当然还可以包括其他的日志子转换器,本申请对此不作具体限制。
进一步地,除Base64转换器是直接将日志内容进行Base64编码外,其他子转换器还依赖配置文件中的转换规则进行转换,转换规则具体包括:
1、正则转换规则,其用于原始日志内容中符合正则匹配的部分按照预设替换规则进行替换。示例包括:{\"regex\":\"^(\\\\d{6})\\\\d+(\\\\d{4})$\","replacement\":\"$1****$2\"},可以支持多个规则同时配置,该正则转换规则表示过滤所收到原始日志内容中符合正则匹配则按照replacement所指向的替换规则进行替换。比如可以将“6228880000000008”转换为“622888******0008”。
2、Json转换规则,用于指定Json对象的字段名和替换方法;Json转换器的转换配置则需要指定Json对象的字段名和替换方法,具体实施中可以嵌套调用正则转换(此处也可以通过调用所实现的Base64转换而实现该Json转换)。
3、ISO8583转换规则,用于指定8583报文对象的域编号和替换方法。ISO8583转换器的转换配置则需要指定8583报文对象的域编号和替换方法,具体实施中可以嵌套调用正则转换。
本实施例中,通过指定Json对象字段名或者ISO8583报文对象的字段名是为提高转换效率,因为采用正则转换理论上可以实现对各种打码场景,比如针对银行卡字符串、手机号字符串、证件号字符串等,但存在误判导致过度打码或者全输入日志内容多正则过滤的效率问题,故本申请进一步提供了针对日常开发过程中常见的Json对象和ISO8583对象的子转换器。
S202、利用转换附加器接收原生日志记录器发来的日志消息,调用初始化参数指定的日志子转换器执行日志打码,并将经处理日志发送给原生附加器进行安全输出。
该S202也即日志打码输出的实际运行步骤,一个示例中,参考图3,示出了本实施例的实现示意图,其中箭头表示本申请的应用日志打码装置的逻辑关系,上图白色块是Java原生或者第三方日志组件,比如JAVA应用、原生日志记录器、控制台附加器、文件附加器等。灰色块部分是本申请中用于日志打码的各个元件,包括转换附加器、日志转换器、各个日志子转换器(正则转换器、JSON转换器、Base64转换器、ISO8583转换器)。利用各日志框架提供的扩展机制,扩展实现转换附加器,该转换附加器内部集成兼容各日志框架的原生附加器和日志转换器。其中,1、原生日志记录器从JAVA应用中获得日志消息。2、原生日志记录器调用转换附加器,并将日志消息传递给该转换附加器。3、转换附加器调用日志转换器,并将日志内容传递给日志转换器。4、日志转换器调用日志子转换器,以利用日志子转换器将日志内容中的敏感信息打码或转换。5、日志转换器将打码转换后的日志消息传递回转换附加器。6、转换附加器将转换后的日志消息传递给日志框架的原生附加器进行内容输出,从而保证输出信息安全。
在传统JAVA应用日志输出方案中,原生日志记录器在获得JAVA应用中生成的日志消息之后,会直接通过控制台附加器或者文件附加器输出,而在本方案中,通过在原生日志记录器和原生附加器之间插入转换附加器等,从而可以对原生日志记录器发来的日志消息进行打码转换,再将打码转换之后的日志消息通过原生附加器输出,整个过程对JAVA应用端无感。
以下结合应用实例的伪代码对本实施例提供的技术方案进行详细说明:
执行本申请实施例的示例性程序后的输出为:
>INFO Main-622888******0008
>INFO Main-aGVsbG8=
换言之,如上例中logger1/2,只需要初始化原生日志记录器,即可在其作用域内重复试用,而且其作用域内可声明并初始化多个不同的原生日志记录器,以便程序员在应用代码拟输出日志的位置根据待输出日志内容具体选择所声明的不同原生日志记录器来完成日志打码输出。如此,对于编程习惯几乎没有变化,拟输出的日志内容、形参等均无任何变化,而原生日志记录器的名称logger1/2本身就是临时变量,其作用域内记住即可。
在本说明书的描述中,参考术语“一些可能的实施方式”、“一些实施例”、“示例”、“具体示例”、或“一些示例”等的描述意指结合该实施例或示例描述的具体特征、结构、材料或者特点包含于本发明的至少一个实施例或示例中。在本说明书中,对上述术语的示意性表述不必须针对的是相同的实施例或示例。而且,描述的具体特征、结构、材料或者特点可以在任一个或多个实施例或示例中以合适的方式结合。此外,在不相互矛盾的情况下,本领域的技术人员可以将本说明书中描述的不同实施例或示例以及不同实施例或示例的特征进行结合和组合。
此外,术语“第一”、“第二”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐含地包括至少一个该特征。在本发明的描述中,“多个”的含义是至少两个,例如两个,三个等,除非另有明确具体的限定。
流程图中或在此以其他方式描述的任何过程或方法描述可以被理解为,表示包括一个或更多个用于实现特定逻辑功能或过程的步骤的可执行指令的代码的模块、片段或部分,并且本发明的优选实施方式的范围包括另外的实现,其中可以不按所示出或讨论的顺序,包括根据所涉及的功能按基本同时的方式或按相反的顺序,来执行功能,这应被本发明的实施例所属技术领域的技术人员所理解。
关于本申请实施例的方法流程图,将某些操作描述为以一定顺序执行的不同的步骤。这样的流程图属于说明性的而非限制性的。可以将在本文中所描述的某些步骤分组在一起并且在单个操作中执行、可以将某些步骤分割成多个子步骤、并且可以以不同于在本文中所示出的顺序来执行某些步骤。可以由任何电路结构和/或有形机制(例如,由在计算机设备上运行的软件、硬件(例如,处理器或芯片实现的逻辑功能)等、和/或其任何组合)以任何方式来实现在流程图中所示出的各个步骤。
基于相同的技术构思,本发明实施例还提供一种日志打码输出装置,用于执行上述任一实施例所提供的日志打码输出方法。
该装置包括:原生日志记录器,被配置为用于基于扩展机制加载转换附加器;转换附加器,被配置为用于加载日志转换器和用于输出日志消息的原生附加器,日志转换器包括一种或多种日志子转换器;日志转换器,被配置为用于加载初始化参数指定的日志子转换器;转换附加器,被配置为还用于接收原生日志记录器发来的日志消息,调用初始化参数指定的日志子转换器执行日志打码,并将经处理日志发送给原生附加器进行安全输出。
根据本申请的一些实施例,提供了日志打码输出方法的非易失性计算机存储介质,其上存储有计算机可执行指令,该计算机可执行指令设置为在由处理器运行时执行:上述实施例所述的方法。
本申请中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于装置、设备和计算机可读存储介质实施例而言,由于其基本相似于方法实施例,所以其描述进行了简化,相关之处可参见方法实施例的部分说明即可。
本申请实施例提供的装置、设备和计算机可读存储介质与方法是一一对应的,因此,装置、设备和计算机可读存储介质也具有与其对应的方法类似的有益技术效果,由于上面已经对方法的有益技术效果进行了详细说明,因此,这里不再赘述装置、设备和计算机可读存储介质的有益技术效果。
虽然已经参考若干具体实施方式描述了本发明的精神和原理,但是应该理解,本发明并不限于所公开的具体实施方式,对各方面的划分也不意味着这些方面中的特征不能组合以进行受益,这种划分仅是为了表述的方便。本发明旨在涵盖所附权利要求的精神和范围内所包括的各种修改和等同布置。
Claims (11)
- 一种应用日志打码输出方法,其特征在于,包括:利用原生日志记录器的扩展机制加载转换附加器,利用所述转换附加器加载日志转换器和用于输出日志消息的原生附加器,所述日志转换器包括一种或多种日志子转换器,以及,利用所述日志转换器加载初始化参数指定的所述日志子转换器;利用所述转换附加器接收所述原生日志记录器发来的日志消息,调用所述初始化参数指定的所述日志子转换器执行日志打码,并将经处理日志发送给所述原生附加器进行安全输出。
- 根据权利要求1所述的方法,其特征在于,所述原生日志记录器和所述原生附加器均是JAVA日志框架的原生模块。
- 根据权利要求1或2所述的方法,其特征在于,所述日志转换器包括以下中的一种或多种日志子转换器:正则转换器、Json转换器、Base64转换器、ISO8583转换器。
- 根据权利要求1-3中任一项所述的方法,其特征在于,利用原生日志记录器的扩展机制加载转换附加器,还包括:所述原生日志记录器基于配置文件而加载所述转换附加器;所述配置文件包括:一种或多种原生附加器的附加器类标识、一种或多种日志子转换器的日志子转换器类标识、对应于所述一种或多种日志子转换器的转换规则。
- 根据权利要求4所述的方法,其特征在于,对应于所述一种或多种日志子转换器的转换规则包括:正则转换规则,用于原始日志内容中符合正则匹配的部分按照预设替换规则进行替换;Json转换规则,用于指定Json对象的字段名和替换方法;ISO8583转换规则,用于指定8583报文对象的域编号和替换方法。
- 根据权利要求5所述的方法,其特征在于,所述Json转换规则和所述ISO8583转换规则在转换时嵌套调用所述正则转换器或所述Base64转换器。
- 根据权利要求1-6中任一项所述的方法,其特征在于,所述原生附加器包括以下中的一种或多种:控制台附加器、文件附加器、套接字附加器、SMTP邮件附加器。
- 根据权利要求1-7中任一项所述的方法,其特征在于,所述转换附加器兼容以下任意一种或多种JAVA日志框架:slf4j、log4j、log4j2、logback、common-logging。
- 一种日志打码输出装置,其特征在于,被配置为用于执行如权利要求1-8中任意一项所述的方法,且包括:原生日志记录器,被配置为用于基于扩展机制加载转换附加器;所述转换附加器,被配置为用于加载日志转换器和用于输出日志消息的原生附加器,所述日志转换器包括一种或多种日志子转换器;所述日志转换器,被配置为用于加载初始化参数指定的所述日志子转换器;所述转换附加器,被配置为还用于接收所述原生日志记录器发来的日志消息,调用所述初始化参数指定的所述日志子转换器执行日志打码,并将经处理日志发送给所述原生附加器进行安全输出。
- 一种日志打码输出装置,其特征在于,包括:至少一个处理器;以及,与至少一个处理器通信连接的存储器;其中,存储器存储有可被至少一个处理器执行的指令,指令被至少一个处理器执行,以使至少一个处理器能够执行:如权利要求1-8中任一项所述的方法。
- 一种计算机可读存储介质,所述计算机可读存储介质存储有程序,当所述程序被多核处理器执行时,使得所述多核处理器执行如权利要求1-8中任一项所述的方法。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110919923.7A CN113704820A (zh) | 2021-08-11 | 2021-08-11 | 一种应用日志打码方法、装置及计算机可读存储介质 |
CN202110919923.7 | 2021-08-11 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2023015853A1 true WO2023015853A1 (zh) | 2023-02-16 |
Family
ID=78652554
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2022/074661 WO2023015853A1 (zh) | 2021-08-11 | 2022-01-28 | 一种应用日志打码方法、装置及计算机可读存储介质 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN113704820A (zh) |
WO (1) | WO2023015853A1 (zh) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116991816A (zh) * | 2023-09-28 | 2023-11-03 | 中化现代农业有限公司 | 日志输出方法、装置、电子设备和存储介质 |
Families Citing this family (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113704820A (zh) * | 2021-08-11 | 2021-11-26 | 中国银联股份有限公司 | 一种应用日志打码方法、装置及计算机可读存储介质 |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111897497A (zh) * | 2020-07-28 | 2020-11-06 | 深圳忆联信息系统有限公司 | Ssd内部日志的加解码方法、装置、计算机设备及存储介质 |
CN112306431A (zh) * | 2020-11-03 | 2021-02-02 | 平安普惠企业管理有限公司 | 日志信息打印方法、装置、设备及存储介质 |
CN112307512A (zh) * | 2020-11-11 | 2021-02-02 | 银清科技有限公司 | 一种日志脱敏方法、装置及存储介质 |
CN113704820A (zh) * | 2021-08-11 | 2021-11-26 | 中国银联股份有限公司 | 一种应用日志打码方法、装置及计算机可读存储介质 |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110727646B (zh) * | 2019-10-10 | 2021-05-04 | 京东数字科技控股有限公司 | 系统日志的格式转换方法、装置、电子设备及计算机介质 |
CN111651784A (zh) * | 2020-04-28 | 2020-09-11 | 中国平安财产保险股份有限公司 | 日志脱敏方法、装置、设备及计算机可读存储介质 |
-
2021
- 2021-08-11 CN CN202110919923.7A patent/CN113704820A/zh active Pending
-
2022
- 2022-01-28 WO PCT/CN2022/074661 patent/WO2023015853A1/zh active Application Filing
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111897497A (zh) * | 2020-07-28 | 2020-11-06 | 深圳忆联信息系统有限公司 | Ssd内部日志的加解码方法、装置、计算机设备及存储介质 |
CN112306431A (zh) * | 2020-11-03 | 2021-02-02 | 平安普惠企业管理有限公司 | 日志信息打印方法、装置、设备及存储介质 |
CN112307512A (zh) * | 2020-11-11 | 2021-02-02 | 银清科技有限公司 | 一种日志脱敏方法、装置及存储介质 |
CN113704820A (zh) * | 2021-08-11 | 2021-11-26 | 中国银联股份有限公司 | 一种应用日志打码方法、装置及计算机可读存储介质 |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN116991816A (zh) * | 2023-09-28 | 2023-11-03 | 中化现代农业有限公司 | 日志输出方法、装置、电子设备和存储介质 |
CN116991816B (zh) * | 2023-09-28 | 2024-01-23 | 中化现代农业有限公司 | 日志输出方法、装置、电子设备和存储介质 |
Also Published As
Publication number | Publication date |
---|---|
CN113704820A (zh) | 2021-11-26 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2023015853A1 (zh) | 一种应用日志打码方法、装置及计算机可读存储介质 | |
CN108255615B (zh) | 跨语言调用方法、服务器及存储介质 | |
US9146732B2 (en) | Systems and methods for executing an application on a mobile device | |
JP5063899B2 (ja) | サービスおよびクライアント・ランタイムを生成、交換、構成するための抽象的な記述の利用 | |
US10042905B2 (en) | Information processing apparatus, information processing system, and data conversion method | |
US7254786B2 (en) | System for transmitting and displaying icon resources group associated with remote application to a local computing system to facilitate virtualization of the remote application | |
CA2514832C (en) | System and method for compression of wireless applications expressed in a structured definition language | |
WO2018210096A1 (zh) | 一种基于规则引擎的规则配置方法、终端、设备以及存储介质 | |
CN101123616A (zh) | 一种服务器管理的方法及一种服务器管理系统 | |
CN112507005B (zh) | 一种处理报文的方法和装置 | |
US11675744B2 (en) | Performing a code conversion in a smaller target encoding space | |
CN113360807B (zh) | 混合模式移动应用的页面显示方法、装置及相关设备 | |
CN107632875B (zh) | 电商接口集成方法、系统、计算机设备、可读存储介质 | |
CN113971110A (zh) | 接口测试方法、装置、设备与计算机可读存储介质 | |
CN111061464A (zh) | 解析代码生成方法、装置、设备及存储介质 | |
CN113296987B (zh) | 调用模块的接口调用方法、装置、计算机设备及存储介质 | |
KR101071786B1 (ko) | 모바일 표준 템플릿 데이터를 제공하는 서버 및 시스템 | |
CN113504909B (zh) | 工业app异构组件数据交换方法及相关设备 | |
CN113779122B (zh) | 导出数据的方法和装置 | |
JP2011070644A (ja) | ネットワークリソースのマッシュアップ方法および装置 | |
US20230214577A1 (en) | Character string transmission method and device, computer, and readable storage medium | |
JP7171256B2 (ja) | 通信システム、制御方法及びプログラム | |
JP7073813B2 (ja) | 制御プログラム、制御方法および情報処理装置 | |
Sefid-Dashti et al. | Toward extending apache thrift open source to alleviate SOAP service consumption | |
CN117112074B (zh) | 将http应用自动转换成无服务器函数的方法、系统和介质 |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 22854858 Country of ref document: EP Kind code of ref document: A1 |
|
WWE | Wipo information: entry into national phase |
Ref document number: 2401000379 Country of ref document: TH |
|
NENP | Non-entry into the national phase |
Ref country code: DE |