Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/#75 Logbat Java SDK 프로젝트 세팅 및 테스트 #78

Merged
merged 7 commits into from
Aug 18, 2024
Merged

Conversation

miiiinju1
Copy link
Member

@miiiinju1 miiiinju1 commented Aug 17, 2024

🚀 작업 내용

  • Logbat Java SDK 프로젝트 세팅
  • 간단한 LogbatAppender 구현하여 jar 테스트

테스트

image
  • 타 프로젝트에서 의존성을 추가하여 작동하는 것을 확인했습니다.
image

Appender는 다음과 같이 등록했습니다.

logback.xml

<configuration>
  <appender name="LOGBAT" class="info.logbat.logback.LogbatAppender"/>
  <root level="debug">
    <appender-ref ref="LOGBAT"/>
  </root>
</configuration>

Appender 부연 설명

Logger log = LoggerFactory.getLogger(Main.class);
logger.info("Hello");

위처럼 로그를 호출 했을 때

log.info() 메서드를 호출하게 되고

Logger의 classic 구현체에서

public void info(String msg) {
    filterAndLog_0_Or3Plus(FQCN, null, Level.INFO, msg, null, null);
}

가 호출됩니다.

이후 메서드에서

buildLoggingEventAndAppend(localFQCN, marker, level, msg, params, t);

라는 로깅 이벤트 생성 메서드가 호출되게되고

private void buildLoggingEventAndAppend(final String localFQCN, final Marker marker, final Level level,
    final String msg, final Object[] params, final Throwable t) {
    LoggingEvent le = new LoggingEvent(localFQCN, this, level, msg, t, params);
    le.addMarker(marker);
    callAppenders(le);
}

위 코드에서 callAppender를 호출하게 됩니다.

public void callAppenders(ILoggingEvent event) {
    int writes = 0;
    for (Logger l = this; l != null; l = l.parent) {
        writes += l.appendLoopOnAppenders(event);
        if (!l.additive) {
            break;
        }
    }
    // No appenders in hierarchy
    if (writes == 0) {
        loggerContext.noAppenderDefinedWarning(this);
    }
}

위 메서드들에서 등록된 현재 Logger부터 부모 Logger들을 (부모 Logger에 관한 부분은 이후에 내용 추가하겠습니다.) 순회하며 모두 appendLoopOnAppenders를 호출하게 되는데

public int appendLoopOnAppenders(E e) {
    int size = 0;
    final Appender<E>[] appenderArray = appenderList.asTypedArray();
    final int len = appenderArray.length;
    for (int i = 0; i < len; i++) {
        appenderArray[i].doAppend(e);
        size++;
    }
    return size;
}

위의 doAppend메서드가 호출되면 구현해둔 AppenderBase 구현체인 LogbatAppenderdoAppend 메서드(부모 메서드)가 호출되고

image 최종적으로 `LogbatAppender`의 `append`메서드가 호출되게 됩니다.

추가: LogbatAppender는 logback.xml에서 설명해두면 ContextInitializer에 의해 초기화되어 LoggerContext에 생성되고, 이후 LoggerFacotry에서 getLogeer로 가져올 때는 초기화된 LogbatAppender의 인스턴스가 포함됩니다.

📸 이슈 번호

👀 Focus Commits [Optional]

✍ 궁금한 점

  • 중점적으로 봐줄 내용
  • 변수명 괜찮나요
  • 로직이 좀 더럽나요
  • 가독성이 좀 그런가요?

@miiiinju1 miiiinju1 added the ⭐️ Feat 새로운 기능이나 요청 label Aug 17, 2024
@miiiinju1 miiiinju1 self-assigned this Aug 17, 2024
Copy link

github-actions bot commented Aug 17, 2024

Risk Level 2 - /home/runner/work/Team5-Guys/Team5-Guys/sdk/java/logbat-sdk/src/main/java/info/logbat/logback/LogbatAppender.java

  1. Consider using a logging framework instead of System.out.println for better performance and flexibility. For example, use Logback's own logging methods:
    Logger logger = LoggerFactory.getLogger(LogbatAppender.class);
    logger.info(\"Logbat Appender: {}\", logMessage);
  2. Ensure that the log level is appropriate for the context to avoid performance issues in production environments.

🔍📜⚙️


Powered by Code Review GPT

타 프로젝트의 application.yml이 포함되어 제거했습니다.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이게 왜 낀거지!!!!!

@miiiinju1 miiiinju1 linked an issue Aug 17, 2024 that may be closed by this pull request
1 task
Comment on lines 14 to 15
implementation 'ch.qos.logback:logback-classic:1.3.8'
implementation 'org.slf4j:slf4j-api:2.0.7'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logback에 slf4j의존이 포함되있을걸요?!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 뺀다는 걸 깜빡했네요!! 감사합니당

Comment on lines +8 to +12
@Override
protected void append(ILoggingEvent eventObject) {
String logMessage = eventObject.getFormattedMessage();
System.out.println("Logbat Appender: " + logMessage);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어떤 부분을 오버라이딩한건지 작성해주시면 감사하겠습니당 :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR에 설명 추가했습니다!

Copy link
Member

@tidavid1 tidavid1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Copy link
Member

@LuizyHub LuizyHub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 프로젝트 세팅부 잘 확인했습니다!

@miiiinju1 miiiinju1 merged commit b4d9d86 into dev Aug 18, 2024
1 check passed
@tidavid1 tidavid1 deleted the feat/#75 branch August 18, 2024 05:37
LuizyHub pushed a commit that referenced this pull request Aug 19, 2024
* init: logbat-sdk 프로젝트 세팅

* chore: main 클래스 제거

* feat: logback 및 SLF4J 의존성 추가 및 JAR 매니페스트 설정 추가

* feat: System out LogbatAppender 추가

* chore: gitignore에 DS_Store 추가

* �chore: application.yml 제거

타 프로젝트의 application.yml이 포함되어 제거했습니다.

* chore: build.gradle에서 slf4j-api 의존성 제거
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐️ Feat 새로운 기능이나 요청
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[💡 FEAT] Logbat Java SDK 프로젝트 세팅
3 participants