Skip to content

Commit

Permalink
Prismarine 0.10.0-unstable-20241027011822
Browse files Browse the repository at this point in the history
  • Loading branch information
vincss committed Oct 27, 2024
1 parent c20030f commit 87af12a
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 97 deletions.
135 changes: 61 additions & 74 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\""
},
"dependencies": {
"@jsprismarine/prismarine": "^0.8.0",
"@jsprismarine/bedrock-data": "^0.8.0",
"@jsprismarine/prismarine": "0.10.0-unstable-20241027011822",
"@jsprismarine/bedrock-data": "0.10.0-unstable-20241027011822",
"@jsprismarine/brigadier": "0.10.0-unstable-20241027011822",
"@sfirew/minecraft-motd-parser": "^1.1.1",
"express": "^4.18.2",
"express-handlebars": "^7.0.4",
Expand Down
10 changes: 7 additions & 3 deletions src/sleepingBedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {ISleepingServer} from "./sleepingServerInterface";
import {PlayerConnectionCallBackType} from "./sleepingTypes";
import {Settings} from "./sleepingSettings";
import { Config, Server } from '@jsprismarine/prismarine';
import {getLogger, LoggerType} from "./sleepingLogger";
import { Logger as PrismarineLogger } from '@jsprismarine/logger';
import {getLogger, LoggerType, getTransports} from "./sleepingLogger";



Expand All @@ -21,7 +22,10 @@ export class SleepingBedrock implements ISleepingServer {
this.playerConnectionCallBack = playerConnectionCallBack;

const config = new Config();
this.server = new Server({config, logger: this.logger });
const prismarineLogger = new PrismarineLogger('info', getTransports());
// (prismarineLogger as any).logger = this.logger;

this.server = new Server({config, logger: prismarineLogger });
this.server.on("playerConnect", (evt) => {
console.log('DEBUG SleepingBedrock.playerConnect : (): ', evt);
});
Expand All @@ -40,7 +44,7 @@ export class SleepingBedrock implements ISleepingServer {
init = async ()=> {
console.log('DEBUG SleepingBedrock.init : (): ');
try {
this.logger.info("[BedRock] Starting on", this.settings.bedrockPort);
this.logger.info(`[BedRock] Starting on ${this.settings.bedrockPort}` );
await this.server.bootstrap('0.0.0.0', this.settings.bedrockPort);

}catch(err) {
Expand Down
40 changes: 22 additions & 18 deletions src/sleepingLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,32 @@ const DefaultLogger = {
};

export type LoggerType = typeof DefaultLogger;
let logger = DefaultLogger;
let initialized = false;
let _logger = DefaultLogger;
let _transports : transport[] = [new transports.Console()];
let _initialized = false;

const logFolder = "logs/";

export const getLogger = () => {
try {
if (initialized) {
return logger;
if (_initialized) {
return _logger;
}

if (process.env.DEFAULT_LOGGER) {
initialized = true;
logger.info("... Default Logger ...");
return logger;
_initialized = true;
_logger.info("... Default Logger ...");
return _logger;
}

const loggers: transport[] = [new transports.Console()];
if (
!process.env.DISABLE_FILE_LOGS ||
process.env.DISABLE_FILE_LOGS !== "true"
) {
if (!existsSync(logFolder)) {
mkdirSync(logFolder);
}
loggers.push(
_transports.push(
new transports.File({
filename: `${logFolder}sleepingServer.log`,
maxsize: 2 * 1024 * 1024,
Expand All @@ -45,7 +45,7 @@ export const getLogger = () => {
);
}

logger = createLogger({
_logger = createLogger({
level: "info",
format: format.combine(
format.timestamp({
Expand All @@ -57,17 +57,21 @@ export const getLogger = () => {
(info.splat !== undefined ? `${info.splat}` : " ")
)
),
transports: loggers,
transports: _transports,
});
} catch (error) {
logger.error("Failed to initialize logger", error);
logger = DefaultLogger;
_logger.error("Failed to initialize logger", error);
_logger = DefaultLogger;
}
initialized = true;
_initialized = true;
const msg = `... A new story begin v${version} ...`;
const separator = msg.replace(/./g, ".");
logger.info(separator);
logger.info(msg);
logger.info(separator);
return logger;
_logger.info(separator);
_logger.info(msg);
_logger.info(separator);
return _logger;
};

export const getTransports = () => {
return _transports;
}

0 comments on commit 87af12a

Please sign in to comment.