package com.eactive.eai.transformer.message.logger;

import com.eactive.eai.common.util.Logger;
import com.eactive.eai.transformer.message.BytesMessage;
import com.eactive.eai.transformer.message.InvalidDataTypeException;
import com.eactive.eai.transformer.util.IConv;


public class BytesMessageLogger implements MessageLogger {
    private static Logger logger = Logger.getLogger("transformer");
    private BytesMessage message;

    public BytesMessageLogger(BytesMessage message) {
        this.message = message;
    }

    public void doLog() {
        if(logger.isDebugEnabled()) logger.debug(this.getClass().getName() +
            "> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        if(logger.isDebugEnabled()) logger.debug(this.getClass().getName() +
            "> 현재 기본 구현된 메시지 로거를 사용하고 계십니다.");
        if(logger.isDebugEnabled()) logger.debug(getLogMessage());
    }

    public String getLogMessage() {
        byte[] buff = null;

        try {
            buff = (byte[]) this.message.getData();

            return new String(buff);
        } catch (InvalidDataTypeException e) {
            throw new RuntimeException(
                "BytesMessageLogger] Cannot make LogMessage. - " +
                e.getMessage());
        }
    }

    /**
     * 로그 메시지 생성
     */
    public String getLogMessage(boolean ebcdic) {
        byte[] buff = null;

        try {
            buff = (byte[]) this.message.getData();

            return IConv.ebcdicToASCII(buff);
        } catch (InvalidDataTypeException e) {
            throw new RuntimeException(
                "BytesMessageLogger] Cannot make LogMessage. - " +
                e.getMessage());
        }
    }
}
