npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

minecraft-server-logs

v1.1.8

Published

Library for parsing and streaming Minecraft logs

Downloads

7

Readme

minecraft-server-logs

Library for parsing and streaming Minecraft logs

Install

Install with npm

$ npm i minecraft-server-logs --save

or

$ yarn add minecraft-server-logs

Usage

const { createLoggedMessage } = require('minecraft-server-logs');

const message = createLoggedMessage(
  '[00:00:00] [Dummy thread/INFO]: Hello world!'
);

console.dir(message);
// outputs: { timestamp: '00:00:00', thread: 'Dummy thread', level: 'INFO', message: 'Hello world!'}
import { createLoggedMessage } = from 'minecraft-server-logs';

const message = createLoggedMessage('[00:00:00] [Dummy thread/INFO]: Hello world!');
console.dir(message);
// outputs: { timestamp: '00:00:00', thread: 'Dummy thread', level: 'INFO', message: 'Hello world!'}

const event = createLoggedEvent(message);
console.dir(event);
// outputs: {
//    timestamp: '00:00:00',
//    thread: 'Dummy thread',
//    level: 'INFO',
//    message: 'Dummy joined the game',
//    eventName: 'playerJoined',
//    playerName: 'Dummy'
// }
import { streamLoggedLines, streamLoggedMessages } from 'minecraft-server-logs';

import { appendFileSync } from 'fs';
import { join } from 'path';

const logsFile = join(process.cwd(), 'logs', 'latest.log');

const messages$ = streamLoggedMessages(
  streamLoggedLines(logsFile, {
    fromBeginning: true,
  })
);

messages$.subscribe((v) => console.log(`${v.timestamp}: ${v.message}`));

appendFileSync(logsFile, '[00:00:00] [Dummy thread/INFO]: Hello world!\n');

// outputs: 00:00:00: Hello world!
import { streamLoggedEvents } from 'minecraft-server-logs';
import { filter, map } from 'rxjs';

const events$ = streamLoggedEvents('./logs/latest.log');

const playerJoined$ = events$.pipe(
  filter((v) => v.eventName === 'playerJoined'),
  map((v) => v as LoggedEvent<PlayerJoinedEvent>)
);
import {
  HasEventName,
  LoggedEvent,
  PlayerJoinedEvent,
  PlayerLeftEvent,
} from 'minecraft-server-logs';

import { filter, map } from 'rxjs';

const filterPresenceEvents = filter(
  ({ eventName }: HasEventName) =>
    eventName === 'playerJoined' || eventName === 'playerLeft'
);

const mapToPresenceEvent = map(
  (v: LoggedEvent) => v as LoggedEvent<PlayerJoinedEvent | PlayerLeftEvent>
);

const presence$ = events$.pipe(filterPresenceEvents, mapToPresenceEvent);

presence$.subscribe(({ eventName, timestamp, playerName }) => {
  console.log(`[${timestamp}] ${eventName}(${playerName})`);
});
const { openSync, appendFileSync } = require('fs');
const {
  createLoggedMessage,
  createLoggedEvent,
  streamLoggedMessages,
  streamLoggedEvents,
  filterEq,
  streamLoggedEventsNamed,
} = require('minecraft-server-logs');
const { of, interval } = require('rxjs');

const HELLO_WORLD =
  '[00:00:00] [Dummy thread/INFO]: LordSequoia joined the game';

const message = createLoggedMessage(HELLO_WORLD);
const event = createLoggedEvent(message);
console.dir({ rawLog: HELLO_WORLD, message, event });

const rawLogs = of(
  '[00:00:00] [Foo thread/INFO]: Server starting',
  '[00:00:00] [Dummy thread/INFO]: Hello world!',
  '[00:00:01] [Server thread/INFO]: LordSequoia joined the game',
  '[00:00:02] [Server thread/INFO]: Starting minecraft server version (1.19)',
  '[00:00:03] [Dummy thread/INFO]: <LordSequoia> Hello world!',
  '[00:00:01] [Server thread/INFO]: LordSequoia left the game'
);

// const rawLogs = './logs/latest.log'
const messages$ = streamLoggedMessages(rawLogs);
const events$ = streamLoggedEvents(rawLogs);

messages$.subscribe(({ timestamp, thread, level, message }) =>
  console.log(`[${level}] ${timestamp}: ${message}`)
);

events$.subscribe((v) => console.log(`[EVENT] ${v.eventName}`));

const playerJoined$ = events$.pipe(filterEq('eventName', 'playerJoined'));

playerJoined$.subscribe(({ timestamp, playerName }) =>
  console.log(`${timestamp} ${playerName} joined!`)
);

const playerLeft$ = streamLoggedEventsNamed(rawLogs, 'playerLeft');

playerLeft$.subscribe(({ timestamp, playerName }) =>
  console.log(`${timestamp} ${playerName} left :(`)
);

const serverEvents$ = streamLoggedEvents('./logs/latest.log');
serverEvents$.subscribe((v) =>
  console.log(`[REAL-TIME] ${v.eventName} -> ${v.message}`)
);

const appendLog = (rawLog) => {
  const appendOpts = { encoding: 'utf-8', flag: 'w' };
  appendFileSync('./logs/latest.log', '\n' + rawLog, appendOpts);
};

interval(3 * 1000).subscribe((v) =>
  appendLog(`[00:00:03] [Dummy thread/INFO]: <LordSequoia> Hello world ${v}!`)
);

Running tests

Install dev dependencies:

$ npm i -d && npm test

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue

Author

LordSequoia

License

Copyright © 2022 LordSequoia Licensed under the MIT license.


This file was generated by readme-generator on July 06, 2022.