log4j регистрирует только сторонние сообщения и игнорирует мои - PullRequest
0 голосов
/ 13 декабря 2018

Я пытаюсь настроить пользовательское ведение журнала через log4j версии 1.2.17 в моем приложении springMVC, но по какой-то причине оно отображает только сторонние журналы (например, hibernate, spring и т. Д.) И полностью игнорирует мое.

Мой файл конфигурации 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 () отсутствует.

Спасибо за любые уведомления.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...