logback config FileName 이 기본 파일 logback.xml이 아닌 경우, logback config 사용하는 방법.

1) LoggerContext 를 reset하고, 

2) System.setProperty에 logback.configurationFile 값을 설정 후,

3) ContextInitializer.autoConfig() 를 이용해서, logback config 를 다시 설정하도록 한다.

 

1. Resoruce (class load) 에서  재설정.

package com.tistory.lunadaddy.test.logbackconfigloader;

import ch.qos.logback.classic.util.ContextInitializer;
import ch.qos.logback.classic.LoggerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

import static java.util.concurrent.TimeUnit.SECONDS;

public class Main {

	private static final Logger logger = LoggerFactory.getLogger(Main.class);

	public static void main(String[] args) throws InterruptedException {
		String profile = System.getProperty("app.profile", "dev"); // 기본값은 "dev"로 설정
		loadLogbackConfig(profile);

		// 로그 테스트
		logger.info("Application started with profile: {}", profile);
		String checkProcess = "sample.jar";
		while (true) {

			boolean canExecute = checkRunningJarProcesses(checkProcess); // 해당 jar가 수행중일 때만 로직을 처리하도록 함.
			if(canExecute) {
				// do something...
				logger.info("do something...");
			} else {
				logger.info("skip");
			}
			
			SECONDS.sleep(2);
		}
	}
	
	private static boolean checkRunningJarProcesses(String checkProcess) {
        boolean jarProcessFound = false;
        if(checkProcess == null) {
        	return jarProcessFound;
        }        	
        
        checkProcess = checkProcess.trim();
        
    	// 환경설정. 1) JAVA_HOME 정의하고, 2) path에 %JAVA_HOME%\bin 추가할 것.  
    	String command = "jps";
        String line;
        Process process = null;
        try {
            process = new ProcessBuilder(command).start();
            logger.debug("Checking for running JAR processes...");
            try(BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
                while ((line = reader.readLine()) != null) {
                    // "java -jar"가 포함된 프로세스를 찾음
                	String[] columns = line.split(" "); // 1: pid, 2: process
                    if (columns.length > 1 && checkProcess.equalsIgnoreCase(columns[1])) {
                    	logger.debug("Found JAR process: " + line);
                        jarProcessFound = true;
                    }
                }            
            }        	
            // int returnCode = process.waitFor();
            // logger.debug("returnCode: {}", returnCode);
        } catch (IOException e) {
        	logger.error(e.toString());
	    } finally {
	    	if(process != null) {
	            process.destroy();
	    	}
	    }
		
		return jarProcessFound;
	}

	private static void loadLogbackConfig(String profile) {
		String logbackConfigFile = String.format("logback-%s.xml", profile);
		try {
			System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, logbackConfigFile);
			LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
			context.reset();

			ContextInitializer ci = new ContextInitializer(context);
			ci.autoConfig();
		} catch (Exception e) {
			e.printStackTrace();
			System.err.println("Failed to load logback configuration file: " + logbackConfigFile);
		}
	}
}

 

 

2. 외부파일에서 재설정

import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.util.StatusPrinter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class LogbackConfigLoader {

    private static final Logger logger = LoggerFactory.getLogger(LogbackConfigLoader.class);

    public static void main(String[] args) {
        String profile = System.getProperty("app.profile", "dev"); // 기본값은 "dev"로 설정
        loadLogbackConfig(profile);

        // 로그 테스트
        logger.info("Application started with profile: {}", profile);
    }

    private static void loadLogbackConfig(String profile) {
        String logbackConfigFile = String.format("logback-%s.xml", profile);
        LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
        try {
            File file = new File(logbackConfigFile);
            if (file.exists()) {
                JoranConfigurator configurator = new JoranConfigurator();
                configurator.setContext(context);
                context.reset();
                configurator.doConfigure(file);
                StatusPrinter.printInCaseOfErrorsOrWarnings(context);
            } else {
                logger.error("Logback configuration file {} does not exist.", logbackConfigFile);
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("Failed to load logback configuration file: " + logbackConfigFile);
        }
    }
}

 

 

3. pom.xml

shade에서 finalName에서 version 제외한 artifactId.jar 로 파일명을 재설정한다.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.tistory.lunadaddy.test</groupId>
  <artifactId>logback-config-loader</artifactId>
  <version>1.0.0</version>
  <packaging>jar</packaging>
  <description>Simple standalone Java Applications</description>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>


  <dependencies>
        <!-- SLF4J, logback -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.25</version>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>
  </dependencies>

  <build>
    <defaultGoal>install</defaultGoal>

    <plugins>
      <!-- Compiler plugin enforces Java 1.7 compatibility and activates annotation processors -->
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.1</version>
        <configuration>
          <source>11</source>
          <target>11</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <finalName>${project.artifactId}</finalName>
              <createDependencyReducedPom>false</createDependencyReducedPom>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                  <mainClass>com.tistory.lunadaddy.test.logbackconfigloader.Main</mainClass>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

 

4. logback-dev.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="30 seconds">
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <Pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %-5level %logger{36} - %msg%n</Pattern>
        </encoder>
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>logs/logback.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>logs/logback-%d{yyyy-MM-dd}.log</fileNamePattern>
            <maxHistory>30</maxHistory>
        </rollingPolicy>

        <encoder>
            <Pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] %-5level %logger{36} - %msg%n</Pattern>
        </encoder>
    </appender>

    <logger name="org.springframework" level="info"/>
    <logger name="kr.or.connect" level="debug"/>

    <root level="debug">
        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>
    </root>
</configuration>

 

 

end.

 

0000. python 사이트

 - https://www.pythonguis.com/

 - https://doc.qt.io/qtforpython-6/index.html

 

1000. pip.ini 로드 위치 확인

pip config -v list

 

 

2000. SSL 인증서 Error

https://yooloo.tistory.com/22

 

pip package install SSL 인증서 Error 해결 (error: [SSL: CERTIFICATE_VERIFY_FAILED])

1. 증상 및 원인 pip를 이용하여 원하는 패키지를 설치하려고 하면, 아래와 같은 에러가 발생할 수 있다. 주로 인트라넷을 사용하는 경우 아래와 같은 문제가 많이 발생한다. 아래와 같은 에러가

yooloo.tistory.com

 

 

 

'Programming Language > Python' 카테고리의 다른 글

python DB 연결  (0) 2024.04.29
dataframe 출력 사이즈 설정  (0) 2022.05.31
Python 모듈 실행시 ModuleNotFoundError 처리  (0) 2022.03.25
[Python] pandas - DataFrame Text 출력  (0) 2022.03.19
[Python] 클래스  (0) 2022.03.14

 

 

 1. library oracledb 사용

 - thin / thick 모드 지원 (thick 경우 oracle client 설치 필요)

 

 

https://python-oracledb.readthedocs.io/en/latest/user_guide/appendix_a.html#

 

25. Appendix A: Oracle Database Features Supported by python-oracledb — python-oracledb 2.2.0b1 documentation

© Copyright 2016, 2024, Oracle and/or its affiliates. All rights reserved. Portions Copyright © 2007-2015, Anthony Tuininga. All rights reserved. Portions Copyright © 2001-2007, Computronix (Canada) Ltd., Edmonton, Alberta, Canada. All rights reserved.

python-oracledb.readthedocs.io

 

'Programming Language > Python' 카테고리의 다른 글

python 문제 해결 목록  (0) 2024.04.29
dataframe 출력 사이즈 설정  (0) 2022.05.31
Python 모듈 실행시 ModuleNotFoundError 처리  (0) 2022.03.25
[Python] pandas - DataFrame Text 출력  (0) 2022.03.19
[Python] 클래스  (0) 2022.03.14

SwiftUI 참조 사이트

 

## A. Swift

1. Swift 영어

  - https://docs.swift.org/swift-book/documentation/the-swift-programming-language/

  - https://www.swift.org/documentation/

  - Getting Started : https://www.swift.org/getting-started/ 

  -  Swift 표준 라이브러리 : https://developer.apple.com/documentation/swift/swift-standard-library

  -  Xcode > Windows > Developer Documentation (shift + command + O)

2. Swift 한글: https://bbiguduk.gitbook.io/swift/

 

## B. SwiftUI

 

1. SwiftUI Recipes : https://swiftuirecipes.com/
- 다양한 코드 샘플

 

2. apple 에서 제공하는 다양한 케이스의 샘플앱

https://developer.apple.com/tutorials/sample-apps/

 

3. SwiftUI Recipe - On Line Cookbook: https://swiftuirecipes.com/companion
- 목록형식으로 다양한 케이스를 검색해서 코드 예제를 볼 수 있음.
- SwiftUI Recipes App - appstore : https://apps.apple.com/kr/app/swiftui-recipes/id1579235956?mt=12

 

## D. App Design

1. Adobe XD - 유료/구독제

  - Flutter 겨우, 소스 생성 plug-in 지원

2. Sketch - 유료/구독제

3. pencil - (mac전용) 무료  https://pencil.evolus.vn/

  - built-in shape, clip art 제공, link 기능.

 

end.

+ Recent posts