Unverified Commit c8dca863 authored by Kristof Szabados's avatar Kristof Szabados Committed by GitHub

Merge pull request #379 from GergoUjhelyi/master

open and close file methods skeletons
parents a4d594cc e3f92501
......@@ -19,4 +19,7 @@ public interface ILoggerPlugin {
boolean set_file_size(final int p_size);
boolean set_file_number(final int p_number);
boolean set_disk_full_action(final TtcnLogger.disk_full_action_t p_disk_full_action);
void open_file(final boolean is_first);
void close_file();
boolean is_configured = false;
}
......@@ -51,6 +51,7 @@ import org.eclipse.titan.runtime.core.TitanLoggerApi.TimerType;
import org.eclipse.titan.runtime.core.TitanLoggerApi.VerdictOp_choice;
import org.eclipse.titan.runtime.core.TitanVerdictType.VerdictTypeEnum;
import org.eclipse.titan.runtime.core.TtcnLogger.Severity;
import org.eclipse.titan.runtime.core.TtcnLogger.disk_full_action_type_t;
import org.eclipse.titan.runtime.core.TtcnLogger.log_event_types_t;
import org.eclipse.titan.runtime.core.TtcnLogger.source_info_format_t;
......@@ -122,6 +123,40 @@ public class LegacyLogger implements ILoggerPlugin {
disk_full_action_ = p_disk_full_action;
return true;
}
public void open_file(boolean is_first) {
if (is_first) {
chk_logfile_data();
if (skeleton_given_) {
set_file_name(TTCN_Runtime.is_single() ? (logfile_number_ == 1 ? "%e.%s" : "%e-part%i.%s") : (logfile_number_ == 1 ? "%e.%h-%r.%s" : "%e.%h-%r-part%i.%s"), false);
}
}
current_filename_ = "";
//FIXME: implement
}
public void close_file() {
//FIXME: implement
}
private void chk_logfile_data() {
if (logfile_size_ == 0 && logfile_number_ != 1) {
TtcnError.TtcnWarning(MessageFormat.format("Invalid combination of LogFileSize (= {0}) and LogFileNumber (= {1}). LogFileNumber was reset to 1.", logfile_size_,logfile_number_));
logfile_number_ = 1;
}
if (logfile_size_ > 0 && logfile_number_ == 1) {
TtcnError.TtcnWarning(MessageFormat.format("Invalid combination of LogFileSize (= {0}) and LogFileNumber (= {1}). LogFileSize was reset to 0.", logfile_size_, logfile_number_));
logfile_size_ = 0;
}
if (logfile_number_ == 1 && disk_full_action_.type == disk_full_action_type_t.DISKFULL_DELETE) {
TtcnError.TtcnWarning("Invalid combination of LogFileNumber (= 1) and DiskFullAction (= Delete). DiskFullAction was reset to Error.");
disk_full_action_.type = disk_full_action_type_t.DISKFULL_ERROR;
}
if (logfile_number_ == 1 && append_file_) {
TtcnError.TtcnWarning(MessageFormat.format("Invalid combination of LogFileNumber (= {0}) and AppendFile (= Yes). AppendFile was reset to No.", logfile_number_));
append_file_ = false;
}
}
/**
* The log_console function from the legacy logger.
......
......@@ -8,6 +8,7 @@
package org.eclipse.titan.runtime.core;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Stack;
import java.util.concurrent.LinkedBlockingQueue;
......@@ -85,6 +86,14 @@ public class LoggerPluginManager {
event_destination_t event_destination;
//etc...
}
private static class LogEntry {
TitanLoggerApi.TitanLogEvent event_;
public LogEntry(TitanLoggerApi.TitanLogEvent event) {
event_ = event;
}
}
private static ThreadLocal<log_event_struct> current_event = new ThreadLocal<LoggerPluginManager.log_event_struct>();
private static ThreadLocal<Stack<log_event_struct>> events = new ThreadLocal<Stack<log_event_struct>>() {
......@@ -95,6 +104,8 @@ public class LoggerPluginManager {
};
private ArrayList<ILoggerPlugin> plugins_ = new ArrayList<ILoggerPlugin>();
private LinkedList<LogEntry> entry_list_ = new LinkedList<LogEntry>();
public LoggerPluginManager() {
plugins_.add(new LegacyLogger());
......@@ -236,10 +247,42 @@ public class LoggerPluginManager {
}
public void open_file() {
//FIXME: implement
ThreadLocal<Boolean> is_first = new ThreadLocal<Boolean>() {
@Override
protected Boolean initialValue() {
return new Boolean(true);
}
};
boolean free_entry_list = false;
if (plugins_.isEmpty()) {
//FIXME: assert(this->n_plugins_ > 0)
return;
}
for (int i = 0; i < plugins_.size(); i++) {
plugins_.get(i).open_file(is_first.get().booleanValue());
if (plugins_.get(i).is_configured) {
free_entry_list = true;
for (LogEntry entry : entry_list_) {
if (entry.event_.getSeverity().getInt() == TtcnLogger.Severity.EXECUTOR_LOGOPTIONS.ordinal()) {
String new_log_message = TtcnLogger.get_logger_settings_str();
entry.event_.getLogEvent().getChoice().getExecutorEvent().getChoice().getLogOptions().assign(new_log_message);
new_log_message = "";
}
plugins_.get(i).log(entry.event_, true, false, false);
}
}
}
if (free_entry_list) {
entry_list_.clear();
}
is_first.set(false);
}
public void close_file() {
//FIXME: implement
while (current_event != null) {
finish_event();
}
ring_buffer_dump(true);
}
public void begin_event(final Severity msg_severity) {
......
......@@ -879,7 +879,7 @@ public final class TtcnLogger {
}
}
private static String get_logger_settings_str() {
static String get_logger_settings_str() {
final StringBuilder new_log_message = new StringBuilder();
final String timestamp_format_names[] = {"Time", "DateTime", "Seconds"};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment