<commit_before>/*
 *  Project:    moba-server
 *
 *  Copyright (C) 2016 <NAME> <<EMAIL>>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program. If not, see <http://www.gnu.org/licenses/agpl.txt>.
 *
 */

package utilities;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import datatypes.objects.NoticeData;
import messages.Message;
import messages.MessageType;

public class MessageLogger {
    protected static final String ANSI_RESET  = "\u001B[0m";
    protected static final String ANSI_BLACK  = "\u001B[30m";
    protected static final String ANSI_RED    = "\u001B[31m";
    protected static final String ANSI_GREEN  = "\u001B[32m";
    protected static final String ANSI_YELLOW = "\u001B[33m";
    protected static final String ANSI_BLUE   = "\u001B[34m";
    protected static final String ANSI_PURPLE = "\u001B[35m";
    protected static final String ANSI_CYAN   = "\u001B[36m";
    protected static final String ANSI_WHITE  = "\u001B[37m";

    public static void in(Message msg) {
        MessageLogger.print(msg, true);
    }

    public static void out(Message msg) {
        MessageLogger.print(msg, false);
    }

    protected static void print(Message msg, boolean in) {
        if(msg == null) {
            return;
        }

        if(msg.getMsgType() == MessageType.GUI_SYSTEM_NOTICE) {
            MessageLogger.msg(msg);
            return;
        }

        StringBuilder sb = new StringBuilder();
        sb.append(ANSI_BLUE);
        SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SSSS ");
        sb.append(df.format(new Date()));
        if(in) {
            sb.append("--> ");
        } else {
            sb.append("<-- ");
        }
        sb.append(msg.getMsgType().getMessageGroup().toString());
        sb.append(":");
        sb.append(msg.getMsgType().toString());
        sb.append(" [");
        sb.append(msg.getMsgType().getMessageClass().toString());
        sb.append("] EP-");
        if(msg.getEndpoint() == null) {
            sb.append("0: NULL");
        } else {
            sb.append(msg.getEndpoint().toString());
        }
        sb.append(MessageLogger.ANSI_RESET);
        System.out.println(sb);
    }

    protected static void msg(Message msg) {
        Object o = msg.getData();<commit_msg>method renamed<commit_after>/*
 *  Project:    moba-server
 *
 *  Copyright (C) 2016 <NAME> <<EMAIL>>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU Affero General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program. If not, see <http://www.gnu.org/licenses/agpl.txt>.
 *
 */

package utilities;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import datatypes.objects.NoticeData;
import messages.Message;
import messages.MessageType;

public class MessageLogger {
    protected static final String ANSI_RESET  = "\u001B[0m";
    protected static final String ANSI_BLACK  = "\u001B[30m";
    protected static final String ANSI_RED    = "\u001B[31m";
    protected static final String ANSI_GREEN  = "\u001B[32m";
    protected static final String ANSI_YELLOW = "\u001B[33m";
    protected static final String ANSI_BLUE   = "\u001B[34m";
    protected static final String ANSI_PURPLE = "\u001B[35m";
    protected static final String ANSI_CYAN   = "\u001B[36m";
    protected static final String ANSI_WHITE  = "\u001B[37m";

    public static void in(Message msg) {
        MessageLogger.print(msg, true);
    }

    public static void out(Message msg) {
        MessageLogger.print(msg, false);
    }

    protected static void print(Message msg, boolean in) {
        if(msg == null) {
            return;
        }

        if(msg.getMsgType() == MessageType.GUI_SYSTEM_NOTICE) {
            MessageLogger.printSystemNotice(msg);
            return;
        }

        StringBuilder sb = new StringBuilder();
        sb.append(ANSI_BLUE);
        SimpleDateFormat df = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SSSS ");
        sb.append(df.format(new Date()));
        if(in) {
            sb.append("--> ");
        } else {
            sb.append("<-- ");
        }
        sb.append(msg.getMsgType().getMessageGroup().toString());
        sb.append(":");
        sb.append(msg.getMsgType().toString());
        sb.append(" [");
        sb.append(msg.getMsgType().getMessageClass().toString());
        sb.append("] EP-");
        if(msg.getEndpoint() == null) {
            sb.append("0: NULL");
        } else {
            sb.append(msg.getEndpoint().toString());
        }
        sb.append(MessageLogger.ANSI_RESET);
        System.out.println(sb);
    }

    protected static void printSystemNotice(Message msg) {
        Object o = msg.getData();
{'fraction_non_alphanumeric': 0.11436397877075843, 'fraction_numerical': 0.01712035610340695, 'mean_word_length': 2.7068527918781724, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6119454', 'n_tokens_mistral': 1776, 'n_tokens_neox': 1701, 'n_words': 500}