log4j仅记录第三方消息,而忽略我的消息

时间:2018-12-13 17:26:02

标签: spring-mvc log4j

我正在尝试在springMVC应用程序中通过log4j 1.2.17版配置自定义日志记录,但是由于某种原因,它仅显示第三方日志(如休眠,春季等),而完全忽略了我。

我的log4j.properties配置文件:

# Root logger option
log4j.rootLogger=DEBUG, stdout, file

# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\tools\\log4j-application.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.default.file.threshold=INFO
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

以及我对记录器的使用

@Service
public class CustomUserDetailService implements UserDetailsService {
    private static final Logger logger = LoggerFactory.getLogger(CustomUserDetailService.class);

    @Autowired
    private UserRepository userRepository;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();

        UserEntity user = userRepository.findByUsername(username);
        if(user == null){
            throw new IllegalArgumentException("User was not found");
        }
        logger.info("Show something");
        logger.error("at least Hello World");
        logger.warn("Why not?");

        return new User(user.getUsername(), user.getPassword(), AuthorityUtils.createAuthorityList(user.getRole()));

    }
}

我的log.file片段

...
2018-12-13 18:15:13 DEBUG QueryTranslatorImpl:274 - --- SQL AST ---
 \-[SELECT] QueryNode: 'SELECT'  querySpaces (user)
    +-[SELECT_CLAUSE] SelectClause: '{select clause}'
    |  +-[ALIAS_REF] IdentNode: 'userentity0_.ID as ID1_0_' {alias=generatedAlias0, className=learn.entity.UserEntity, tableAlias=userentity0_}
    |  \-[SQL_TOKEN] SqlFragment: 'userentity0_.PASSWORD as PASSWORD2_0_, userentity0_.ROLE as ROLE3_0_, userentity0_.USERNAME as USERNAME4_0_'
    +-[FROM] FromClause: 'from' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[generatedAlias0], fromElementByTableAlias=[userentity0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
    |  \-[FROM_FRAGMENT] FromElement: 'user userentity0_' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=generatedAlias0,role=null,tableName=user,tableAlias=userentity0_,origin=null,columns={,className=learn.entity.UserEntity}}
    \-[WHERE] SqlNode: 'where'
       \-[EQ] BinaryLogicOperatorNode: '='
          +-[DOT] DotNode: 'userentity0_.USERNAME' {propertyName=username,dereferenceType=PRIMITIVE,getPropertyPath=username,path=generatedAlias0.username,tableAlias=userentity0_,className=learn.entity.UserEntity,classAlias=generatedAlias0}
          |  +-[ALIAS_REF] IdentNode: 'userentity0_.ID' {alias=generatedAlias0, className=learn.entity.UserEntity, tableAlias=userentity0_}
          |  \-[IDENT] IdentNode: 'username' {originalText=username}
          \-[NAMED_PARAM] ParameterNode: '?' {name=param0, expectedType=org.hibernate.type.StringType@1ae88704}

2018-12-13 18:15:13 DEBUG ErrorTracker:97 - throwQueryException() : no errors
2018-12-13 18:15:13 DEBUG QueryTranslatorImpl:253 - HQL: select generatedAlias0 from learn.entity.UserEntity as generatedAlias0 where generatedAlias0.username=:param0
2018-12-13 18:15:13 DEBUG QueryTranslatorImpl:254 - SQL: select userentity0_.ID as ID1_0_, userentity0_.PASSWORD as PASSWORD2_0_, userentity0_.ROLE as ROLE3_0_, userentity0_.USERNAME as USERNAME4_0_ from user userentity0_ where userentity0_.USERNAME=?
2018-12-13 18:15:13 DEBUG ErrorTracker:97 - throwQueryException() : no errors
2018-12-13 18:15:13 DEBUG SQL:94 - select userentity0_.ID as ID1_0_, userentity0_.PASSWORD as PASSWORD2_0_, userentity0_.ROLE as ROLE3_0_, userentity0_.USERNAME as USERNAME4_0_ from user userentity0_ where userentity0_.USERNAME=?
2018-12-13 18:15:13 DEBUG Loader:384 - Result set row: 0
2018-12-13 18:15:13 DEBUG Loader:1532 - Result row: EntityKey[learn.entity.UserEntity#1]
2018-12-13 18:15:13 DEBUG TwoPhaseLoad:145 - Resolving associations for [learn.entity.UserEntity#1]
2018-12-13 18:15:13 DEBUG TwoPhaseLoad:290 - Done materializing entity [learn.entity.UserEntity#1]
2018-12-13 18:15:19 DEBUG CriteriaQueryImpl:307 - Rendered criteria query -> select generatedAlias0 from UserEntity as generatedAlias0 where generatedAlias0.username=:param0
2018-12-13 18:15:19 DEBUG SQL:94 - select userentity0_.ID as ID1_0_, userentity0_.PASSWORD as PASSWORD2_0_, userentity0_.ROLE as ROLE3_0_, userentity0_.USERNAME as USERNAME4_0_ from user userentity0_ where userentity0_.USERNAME=?
2018-12-13 18:15:19 DEBUG Loader:384 - Result set row: 0
2018-12-13 18:15:19 DEBUG Loader:1532 - Result row: EntityKey[learn.entity.UserEntity#1]
2018-12-13 18:15:19 DEBUG TwoPhaseLoad:145 - Resolving associations for [learn.entity.UserEntity#1]
2018-12-13 18:15:19 DEBUG TwoPhaseLoad:290 - Done materializing entity [learn.entity.UserEntity#1]

它包含所有其他信息,仅缺少logger.info()。

谢谢您的通知。

0 个答案:

没有答案