<<The Mithical Man-Month>> Reading Notes for English Learning

本文探讨了软件设计的重要性和重用的挑战。强调了概念完整性对于产品质量的核心作用,并提出组织应同等重视优秀设计师与管理者。文章还讨论了推理引擎技术的发展及其广泛应用,以及实现软件重用所需的良好设计与文档编制。

1. The software must be conformed to its new vehicles of opportunity.


2. Inference engine technology is developed in an application-independant way, and  then applied to many uses. One can justify much     more effort on the inference engines.Indeed, that technology  is well advanced.


3. That is, the system should be made to run, even though it does nothing useful  except call the proper set of dummy subprograms.

    Then bit by bit fleshed out, witch the subprograms in turn being developed into actions or calls to empty stubs in the level below.


4. My first proposal is that each software orgnization must determine and proclaim that great designers are as imortant to its success       as great managers are, and that they can be expected be similarly nurtured and rewarded.


5. Reuse is something that is far easier to say than to do. Ding it requires both good design and very good documentation. Even when     we see good design, which is still infrequently, we won't see the components reused without good documentation.


6. Conceptual integrity is central to product quality.

<think>我们正在解决如何升级SLF4J和Log4j依赖以修复Log4j 1.x的安全漏洞。用户明确提到要升级`slf4j-api`和`slf4j-log4j12`依赖,但注意`slf4j-log4j12`绑定的是Log4j 1.x,而Log4j 1.x有已知的安全漏洞(如CVE-2019-17571)。因此,正确的做法是迁移到Log4j 2.x或Logback。 根据用户需求,我们有两个选择: 1. 升级到Log4j 2.x:使用`log4j-slf4j-impl`代替`slf4j-log4j12`。 2. 迁移到Logback:使用`logback-classic`代替`slf4j-log4j12`。 由于用户要求修复Log4j 1.x的安全漏洞,我们推荐迁移到Log4j 2.x,因为它是Log4j的升级版,且修复了安全漏洞。同时,用户可能希望继续使用Log4j。 步骤: 1. 移除`slf4j-log4j12`依赖(因为它是绑定Log4j 1.x的)。 2. 添加Log4j 2.x的依赖,包括`log4j-api`和`log4j-core`。 3. 添加SLF4J到Log4j 2.x的桥接器:`log4j-slf4j-impl`。 4. 升级`slf4j-api`到最新版本(与Log4j 2.x兼容的版本)。 注意:确保所有依赖版本兼容。当前推荐版本(2023年): - SLF4J API: 1.7.36(稳定版本) - Log4j 2.x: 2.23.1(修复了多个安全漏洞) 另外,Log4j 2.x需要单独的配置文件(如log4j2.xml),因此需要将原有的log4j.properties转换为log4j2.xml格式。 下面以Maven和Gradle为例说明升级步骤。 如果用户使用的是Maven: 1. 移除`slf4j-log4j12`: ```xml <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.36</version> <!-- 如果有,则移除 --> <scope>provided</scope> <!-- 或者直接删除整个依赖 --> </dependency> ``` 注意:直接删除该依赖。 2. 添加Log4j 2.x和SLF4J桥接: ```xml <dependencies> <!-- SLF4J API --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.36</version> </dependency> <!-- Log4j 2.x SLF4J Binding --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j-impl</artifactId> <version>2.23.1</version> </dependency> <!-- Log4j 2.x Core --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.23.1</version> </dependency> </dependencies> ``` 3. 排除项目中其他日志依赖(如Spring Boot的默认日志): ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> <!-- 然后添加spring-boot-starter-log4j2(如果需要) --> ``` 如果用户使用Gradle: 1. 移除`slf4j-log4j12`依赖: ```gradle configurations.all { exclude group: 'org.slf4j', module: 'slf4j-log4j12' } ``` 2. 添加依赖: ```gradle dependencies { implementation 'org.slf4j:slf4j-api:1.7.36' implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.23.1' implementation 'org.apache.logging.log4j:log4j-core:2.23.1' } ``` 3. 排除其他日志框架: ```gradle configurations { all { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' } } ``` 4. 如果使用Spring Boot,可以添加: ```gradle implementation 'org.springframework.boot:spring-boot-starter-log4j2' ``` 注意:升级后需要将原有的log4j.properties配置文件转换为log4j2.xml格式。Log4j 2.x支持自动转换,但建议手动检查配置。 配置文件示例(log4j2.xml): ```xml <?xml version="1.0" encoding="UTF-8"?> <Configuration status="WARN"> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> </Console> </Appenders> <Loggers> <Root level="info"> <AppenderRef ref="Console"/> </Root> </Loggers> </Configuration> ``` 最后,运行测试确保日志输出正常。 安全提示:Log4j 2.x在2.15.0及以上版本修复了CVE-2021-44228(Log4Shell)等漏洞,因此我们推荐使用2.23.1(当前最新稳定版本)。 如果用户坚持使用Log4j 1.x(不推荐),可以尝试使用`log4j-over-slf4j`桥接,将Log4j 1.x的调用重定向到SLF4J,然后由SLF4J路由到其他安全的日志实现(如Logback或Log4j 2.x)。但这样需要完全移除Log4j 1.x依赖,并添加桥接器。但用户要求升级依赖修复漏洞,所以推荐直接迁移到Log4j 2.x。 因此,总结如下: - 移除`slf4j-log4j12`(Log4j 1.x绑定) - 添加`log4j-slf4j-impl`(Log4j 2.x绑定) - 添加`log4j-core`和`log4j-api` - 升级`slf4j-api`到最新稳定版本 - 转换配置文件 相关问题: 1. 如何将Log4j 1.x的配置文件转换为Log4j 2.x格式? 2. 在Spring Boot中如何配置Log4j 2.x? 3. 使用Log4j 2.x有哪些性能优势?</think>### 升级 SLF4J 和 Log4j 依赖修复安全漏洞指南 要修复 Log4j 1.x 的安全漏洞(如 CVE-2019-17571),需执行以下关键步骤: --- ### 1. **移除不安全的依赖** 在构建配置中**完全移除** `slf4j-log4j12` 依赖(它是 Log4j 1.x 的绑定器): ```xml <!-- 移除此危险依赖 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <!-- 安全漏洞来源 --> <version>1.7.30</version> <scope>provided</scope> <!-- 直接删除整个依赖项 --> </dependency> ``` --- ### 2. **升级到安全替代方案** #### 方案 A:迁移到 Log4j 2.x(推荐) ```xml <dependencies> <!-- SLF4J API 升级 --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>2.0.13</version> <!-- 最新稳定版 --> </dependency> <!-- Log4j 2.x 绑定 --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-slf4j2-impl</artifactId> <!-- 安全绑定器 --> <version>2.23.1</version> <!-- 修复漏洞的版本 --> </dependency> <!-- Log4j 2.x 核心 --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.23.1</version> </dependency> </dependencies> ``` #### 方案 B:迁移到 Logback(备选) ```xml <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <!-- 直接实现 SLF4J --> <version>1.5.6</version> <!-- 无 Log4j 依赖 --> </dependency> ``` --- ### 3. **关键配置调整** #### 排除冲突依赖(Spring Boot 项目) ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-logging</artifactId> </exclusion> </exclusions> </dependency> ``` #### 添加 Log4j 2.x 支持(Spring Boot) ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j2</artifactId> </dependency> ``` --- ### 4. **配置文件升级** 将 `log4j.properties` 转换为 `log4j2.xml`: ```xml <?xml version="1.0" encoding="UTF-8"?> <Configuration status="WARN"> <Appenders> <Console name="Console" target="SYSTEM_OUT"> <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> </Console> </Appenders> <Loggers> <Root level="info"> <AppenderRef ref="Console"/> </Root> </Loggers> </Configuration> ``` --- ### 5. **验证升级结果** 检查依赖树确保无残留: ```bash # Maven mvn dependency:tree -Dincludes=org.apache.logging,org.slf4j # Gradle gradle dependencies | grep -E 'log4j|slf4j' ``` 输出应包含: ``` org.slf4j:slf4j-api:2.0.13 org.apache.logging.log4j:log4j-slf4j2-impl:2.23.1 ``` 且**无** `log4j:log4j` 或 `slf4j-log4j12`[^1]。 --- ### 安全加固建议 1. **启用日志消毒**: ```java System.setProperty("log4j2.formatMsgNoLookups", "true"); ``` 2. **定期扫描依赖**: ```bash mvn org.owasp:dependency-check-maven:check ``` 3. **使用漏洞扫描工具**: ```bash java -jar log4j2-scan.jar --scan-log4j1 /path/to/app ``` > **注意**:Log4j 1.x 已于 2015 年终止支持,强烈建议迁移到 Log4j 2.x 或 Logback[^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值