<commit_before>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.f1x.log.file;

import org.f1x.api.session.SessionID;
import org.f1x.log.LogFormatter;
import org.f1x.util.TimeSource;

import java.io.*;
import java.util.Calendar;
import java.util.TimeZone;

public class DailyFileMessageLog extends PeriodicFlushingMessageLog {
    private final OutputStreamRollover dailyFileRoller;


    public DailyFileMessageLog(SessionID sessionID, File logDir, TimeSource timeSource, TimeZone tz, int bufferSize, int flushPeriod) {
        super(null, sessionID, timeSource, flushPeriod);

        this.dailyFileRoller = new OutputStreamRollover(logDir, sessionID, timeSource, tz, bufferSize);
        this.os = dailyFileRoller.createCurrentStream();

        this.dailyFileRoller.start();
    }

    public DailyFileMessageLog(SessionID sessionID, File logDir, LogFormatter formatter, TimeSource timeSource, TimeZone tz, int bufferSize, int flushPeriod) {
        super(null, sessionID, formatter, timeSource, flushPeriod);

        this.dailyFileRoller = new OutputStreamRollover(logDir, sessionID, timeSource, tz, bufferSize);
        this.os = dailyFileRoller.createCurrentStream();

        this.dailyFileRoller.start();
    }

    @Override
    public void close() {
        dailyFileRoller.interrupt();
        super.close();
    }

    private final class OutputStreamRollover extends Thread {
        private final StringBuilder nextFileName = new StringBuilder();
        private final Calendar calendar;
        private final SessionID sessionID;
        private final TimeSource timeSource;
        private final File logDir;
        private final int bufferSize;


        OutputStreamRollover(File logDir, SessionID sessionID, TimeSource timeSource, TimeZone tz, int bufferSize) {
            this.logDir = logDir;
            this.bufferSize = bufferSize;
            this.sessionID = sessionID;
            this.timeSource = timeSource;
            this.calendar = getCurrentDayStart(timeSource, tz);
        }

        @Override
        public void run() {
            while (true) {
                try {
<commit_msg>minor: daily rollover thread name/priority<commit_after>/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.f1x.log.file;

import org.f1x.api.session.SessionID;
import org.f1x.log.LogFormatter;
import org.f1x.util.TimeSource;

import java.io.*;
import java.util.Calendar;
import java.util.TimeZone;

public class DailyFileMessageLog extends PeriodicFlushingMessageLog {
    private final OutputStreamRollover dailyFileRoller;


    public DailyFileMessageLog(SessionID sessionID, File logDir, TimeSource timeSource, TimeZone tz, int bufferSize, int flushPeriod) {
        super(null, sessionID, timeSource, flushPeriod);

        this.dailyFileRoller = new OutputStreamRollover(logDir, sessionID, timeSource, tz, bufferSize);
        this.os = dailyFileRoller.createCurrentStream();

        this.dailyFileRoller.start();
    }

    public DailyFileMessageLog(SessionID sessionID, File logDir, LogFormatter formatter, TimeSource timeSource, TimeZone tz, int bufferSize, int flushPeriod) {
        super(null, sessionID, formatter, timeSource, flushPeriod);

        this.dailyFileRoller = new OutputStreamRollover(logDir, sessionID, timeSource, tz, bufferSize);
        this.os = dailyFileRoller.createCurrentStream();

        this.dailyFileRoller.start();
    }

    @Override
    public void close() {
        dailyFileRoller.interrupt();
        super.close();
    }

    private final class OutputStreamRollover extends Thread {
        private final StringBuilder nextFileName = new StringBuilder();
        private final Calendar calendar;
        private final SessionID sessionID;
        private final TimeSource timeSource;
        private final File logDir;
        private final int bufferSize;


        OutputStreamRollover(File logDir, SessionID sessionID, TimeSource timeSource, TimeZone tz, int bufferSize) {
            super("Daily roll for " + sessionID);
            setDaemon(true);
            setPriority(Thread.NORM_PRIORITY - 1);
            this.logDir = logDir;
            this.bufferSize = bufferSize;
            this.sessionID = sessionID;
            this.timeSource = timeSource;
            this.calendar = getCurrentDayStart(timeSource, tz);
        }

        @Override
        public void run() {
            while (true) {
                try {

{'fraction_non_alphanumeric': 0.0747965197866966, 'fraction_numerical': 0.00406960426606792, 'mean_word_length': 3.3141646489104115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 5, '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': '3868152', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1792, 'n_words': 695}