Log Management: log4j, Rotation, Audit Logs and Central Collection

Big Data and Hadoop Administrator 13 min min read Updated: Nov 17, 2026 Intermediate
Log Management: log4j, Rotation, Audit Logs and Central Collection
Intermediate Topic 3 of 4

Where Logs Are

LogTypical locationUse
Daemon logs$HADOOP_LOG_DIR/hadoop-<user>-<daemon>-<host>.logErrors of NameNode, DataNode, RM, NM
.out filesSame directory, *.outStdout and JVM crashes, ulimit output
HDFS audit loghdfs-audit.logWho accessed which path
Container logs (running)NodeManager yarn.nodemanager.log-dirsTask output
Container logs (after)HDFS /app-logs (aggregation)yarn logs -applicationId
GC logsConfigured with JVM flagsPauses and heap behaviour
Service logs of Hive, HBase, KafkaTheir own log dirsService errors

Reading Daemon Logs Quickly

bash tail -f /var/log/hadoop/hadoop-hdfs-namenode-$(hostname).log grep -E "ERROR|FATAL" /var/log/hadoop/hadoop-hdfs-namenode-*.log | tail -50 grep -c "Slow BlockReceiver" /var/log/hadoop/hadoop-hdfs-datanode-*.log journalctl -u hadoop-datanode --since "1 hour ago"
LevelWhen
FATALDaemon is stopping
ERROROperation failed
WARNSomething unusual (look at patterns)
INFONormal events
DEBUG / TRACEShort-term troubleshooting only

Changing Log Level Without Restart

bash hadoop daemonlog -getlevel nn1.example.com:9870 org.apache.hadoop.hdfs.server.namenode.FSNamesystem hadoop daemonlog -setlevel nn1.example.com:9870 org.apache.hadoop.hdfs.server.blockmanagement.BlockManager DEBUG # ... reproduce the issue ... hadoop daemonlog -setlevel nn1.example.com:9870 org.apache.hadoop.hdfs.server.blockmanagement.BlockManager INFO
Debug logs are noisy: Turn DEBUG on for one class only and for a short time. A busy NameNode can write gigabytes in minutes and fill the disk.

log4j2 Configuration

ini # etc/hadoop/log4j.properties (Hadoop 3.4 and later use log4j2 style files; check your release) hadoop.log.dir=/var/log/hadoop hadoop.log.file=hadoop.log # daily rolling + size cap for daemons log4j.appender.RFA=org.apache.log4j.RollingFileAppender log4j.appender.RFA.File=${hadoop.log.dir}/${hadoop.log.file} log4j.appender.RFA.MaxFileSize=256MB log4j.appender.RFA.MaxBackupIndex=20 log4j.appender.RFA.layout=org.apache.log4j.PatternLayout log4j.appender.RFA.layout.ConversionPattern=%d{ISO8601} %p %c{2}: %m%n # HDFS audit log4j.logger.org.apache.hadoop.hdfs.server.namenode.FSNamesystem.audit=INFO,RFAAUDIT log4j.appender.RFAAUDIT=org.apache.log4j.RollingFileAppender log4j.appender.RFAAUDIT.File=${hadoop.log.dir}/hdfs-audit.log log4j.appender.RFAAUDIT.MaxFileSize=512MB log4j.appender.RFAAUDIT.MaxBackupIndex=50
Version note: Hadoop moved from log4j 1 to log4j 2 in recent releases, so the file syntax differs. Start from the default file shipped with your version and change the sizes and levels.

HDFS Audit Log

text 2026-11-16 10:05:11,204 INFO FSNamesystem.audit: allowed=true ugi=alice (auth:KERBEROS) ip=/10.0.2.15 cmd=delete src=/data/finance/old dst=null perm=null proto=rpc
bash # who deleted something today grep "cmd=delete" /var/log/hadoop/hdfs-audit.log | grep "src=/data/finance" | awk '{print $1,$2,$7,$9,$10}' # top users by operations grep -o "ugi=[^ ]*" /var/log/hadoop/hdfs-audit.log | sort | uniq -c | sort -rn | head

Retention and Disk Safety

bash # /etc/logrotate.d/hadoop (for logs not rotated by log4j) /var/log/hadoop/*.out { daily rotate 14 compress missingok copytruncate } # alert when /var/log passes 80% usage; keep logs on a separate partition so they cannot fill the OS disk

Central Log Collection

text Nodes: Filebeat / Fluent Bit / Promtail -> OpenSearch (ELK) or Grafana Loki -> search, dashboards, alerts Keep: audit logs 1 year or per policy, daemon logs 30 to 90 days, debug output a few days
yaml # filebeat.yml (excerpt) filebeat.inputs: - type: filestream id: hadoop-daemons paths: ["/var/log/hadoop/*.log"] fields: { cluster: prod, role: "${HADOOP_ROLE}" } parsers: - multiline: { type: pattern, pattern: '^\d{4}-\d{2}-\d{2}', negate: true, match: after } output.elasticsearch: hosts: ["https://opensearch1:9200"]
Search by pattern: Useful central searches: Exception count per hour, WARN ... Slow messages, SafeMode, Failed to place enough replicas, GC pause, Too many open files. Turn the best ones into alerts.

Conclusion

Know the log files, set sensible rotation and a separate log partition, change levels at runtime only briefly, use the HDFS audit log for who-did-what, and ship logs centrally for search and alerts.

Quick Summary: daemonlog for level; log4j rotation; audit log; central shipping.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators