Skip to content

Commit

Permalink
feat(distribution): broker in docker will print log into console (#817)
Browse files Browse the repository at this point in the history
Signed-off-by: SSpirits <[email protected]>
  • Loading branch information
ShadowySpirits authored Dec 11, 2023
1 parent 0716d7f commit 1065f55
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 22 deletions.
7 changes: 6 additions & 1 deletion distribution/bin/run-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,18 @@ choose_gc_options()

choose_gc_log_directory
choose_gc_options

if [ -z "$LOG4J_CONF" ] ; then
LOG4J_CONF="${BASE_DIR}/conf/log4j2.xml"
fi

JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow"
JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages"
JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=*:9555,server=y,suspend=n"
JAVA_OPT="${JAVA_OPT} -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=${GC_LOG_DIR}/oomheapdump.hprof"
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"
# https://logging.apache.org/log4j/2.x/manual/configuration.html#automatic-configuration
JAVA_OPT="${JAVA_OPT} -Dlog4j.configurationFile=file:${BASE_DIR}/conf/log4j2.xml"
JAVA_OPT="${JAVA_OPT} -Dlog4j.configurationFile=file:${LOG4J_CONF}"

"$JAVA" ${JAVA_OPT} $@
55 changes: 55 additions & 0 deletions distribution/conf/log4j2_console.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<Configuration shutdownHook="disable">
<Properties>
<Property name="LOG_DIR">${sys:user.home}${sys:file.separator}logs${sys:file.separator}rocketmqlogs</Property>
</Properties>

<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}{GMT+8} %-5p %m%n"/>
</Console>

<RollingFile name="mybatisAppender" fileName="${LOG_DIR}/mybatis.log" filePattern="${LOG_DIR}/mybatis.%i.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}{GMT+8} %-5p %m%n"/>
<SizeBasedTriggeringPolicy size="100MB"/>
<DefaultRolloverStrategy max="2"/>
</RollingFile>

<RollingFile name="streamWatermarkAppender" fileName="${LOG_DIR}/stream_watermark.log"
filePattern="${LOG_DIR}/stream_watermark.%i.log">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS}{GMT+8} %-5p %m%n"/>
<SizeBasedTriggeringPolicy size="100MB"/>
<DefaultRolloverStrategy max="10"/>
</RollingFile>
</Appenders>

<Loggers>
<Root level="info">
<AppenderRef ref="STDOUT"/>
</Root>

<Logger name="com.automq.rocketmq.metadata.mapper" level="debug" additivity="false">
<AppenderRef ref="mybatisAppender"/>
</Logger>
<Logger name="com.automq.stream.utils.threads" level="info" additivity="false">
<AppenderRef ref="streamWatermarkAppender"/>
</Logger>
</Loggers>
</Configuration>
2 changes: 2 additions & 0 deletions distribution/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ services:
- ROCKETMQ_NODE_NAME=broker-1
- ROCKETMQ_NODE_BIND_ADDRESS=0.0.0.0:8081
- ROCKETMQ_NODE_ADVERTISE_ADDRESS=${EXTERNAL_IP}:8081
- LOG4J_CONF=/root/automq-for-rocketmq/conf/log4j2_console.xml
ports:
- "8081:8081"
- "8082:8082"
Expand All @@ -71,6 +72,7 @@ services:
- ROCKETMQ_NODE_NAME=broker-2
- ROCKETMQ_NODE_BIND_ADDRESS=0.0.0.0:8181
- ROCKETMQ_NODE_ADVERTISE_ADDRESS=${EXTERNAL_IP}:8181
- LOG4J_CONF=/root/automq-for-rocketmq/conf/log4j2_console.xml
ports:
- "8181:8181"
- "8182:8182"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@
import io.netty.buffer.Unpooled;
import io.netty.util.HashedWheelTimer;
import io.netty.util.Timeout;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -62,25 +80,6 @@
import software.amazon.awssdk.services.s3.model.UploadPartRequest;
import software.amazon.awssdk.services.s3.model.UploadPartResponse;

import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static com.automq.stream.utils.FutureUtil.cause;

public class DefaultS3Operator implements S3Operator {
Expand Down Expand Up @@ -566,8 +565,8 @@ private void checkConfig() {

private void checkAvailable() {
byte[] content = new Date().toString().getBytes(StandardCharsets.UTF_8);
String path = String.format("check_available/%d", System.currentTimeMillis());
String multipartPath = String.format("check_available_multipart/%d", System.currentTimeMillis());
String path = String.format("check_available/%d", System.nanoTime());
String multipartPath = String.format("check_available_multipart/%d", System.nanoTime());
try {
// Simple write/read/delete
this.write(path, Unpooled.wrappedBuffer(content)).get(30, TimeUnit.SECONDS);
Expand Down

0 comments on commit 1065f55

Please sign in to comment.