<commit_before>import { Rowan, Processor } from "rowan";

import { Context } from "./context";
import { WireServer } from "./wire-server";
import { EventEmitter } from "events";

import { Via } from "./via";
import { Log, ConsoleLog } from "./log";

export class Viae<Ctx extends Context = Context> extends Rowan<Context> {
  private _connections = new Array<Via>();
  private _ev = new EventEmitter();
  private _before = new Rowan<Context>();

  constructor(server: WireServer, middleware?: Processor<Ctx>[]) {
    super(middleware);

    server.on("connection", (wire) => {
      let via = new Via({ wire: wire, log: Viae.Log }).before(this._before).use(this);

      wire.on("close", () => {
        this._connections.splice(this._connections.indexOf(via), 1);
        Viae.Log.info("disconnection", via.wire.meta);
      });

      via.on("error", (err) => {
        wire.close();
      });

      this._connections.push(via);
      this._ev.emit("connection", via);
      Viae.Log.info("connection", via.wire.meta);
    });
  }

  on(event: "connection", cb: (connection: Via<Ctx>) => void) {
    this._ev.on(event, cb);
  }

  before(processor: Processor<Ctx>) {
    this._before.use(processor);
    return this;
  }

  static Log: Log = new ConsoleLog();<commit_msg>feat: configerable log<commit_after>import { Rowan, Processor } from "rowan";

import { Context } from "./context";
import { WireServer } from "./wire-server";
import { EventEmitter } from "events";

import { Via } from "./via";
import { Log, ConsoleLog } from "./log";

export class Viae<Ctx extends Context = Context> extends Rowan<Context> {
  private _connections = new Array<Via>();
  private _ev = new EventEmitter();
  private _before = new Rowan<Context>();

  constructor(server: WireServer, opts: { log?: Log, middleware?: Processor<Ctx>[], }) {
    super((opts) ? opts.middleware : undefined);

    server.on("connection", (wire) => {
      let log = opts && opts.log ? opts.log : Viae.Log;
      let via = new Via({ wire: wire, log: log }).before(this._before).use(this);

      wire.on("close", () => {
        this._connections.splice(this._connections.indexOf(via), 1);
        Viae.Log.info("disconnection", via.wire.meta);
      });

      via.on("error", (err) => {
        wire.close();
      });

      this._connections.push(via);
      this._ev.emit("connection", via);
      Viae.Log.info("connection", via.wire.meta);
    });
  }

  on(event: "connection", cb: (connection: Via<Ctx>) => void) {
    this._ev.on(event, cb);
  }

  before(processor: Processor<Ctx>) {
    this._before.use(processor);
    return this;
  }

  static Log: Log = new ConsoleLog();
{'fraction_non_alphanumeric': 0.17658132530120482, 'fraction_numerical': 0.0007530120481927711, 'mean_word_length': 3.3203252032520325, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2425210', 'n_tokens_mistral': 864, 'n_tokens_neox': 835, 'n_words': 198}