Je Suis Un Ami
Je Suis Un Ami
Explore posts from servers
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/11/2024 in #sapphire-support
Formatted Logs
… Hmm. Alright then. Seems like an unnecessary amount of work just to change the format of how log messages are written. But guess I’ll have to do that.
16 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/11/2024 in #sapphire-support
Formatted Logs
Oh. So, am I gonna have to write my own plugin? Or can I configure the plugin to use my custom format?
16 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/11/2024 in #sapphire-support
Formatted Logs
Am I supposed to do something differently? Thought I could just extend the logger and keep using the existing plugin.
16 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/11/2024 in #sapphire-support
Formatted Logs
Which isn't the format I spcified, making me think Sapphire isn't using my extension of the Logger plugin.
16 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/11/2024 in #sapphire-support
Formatted Logs
However, log messages look like this:
024-03-12 16:22:21 - DEBUG - Checking for existing records. FirestoreGuildProfileResource.create
024-03-12 16:22:21 - DEBUG - Checking for existing records. FirestoreGuildProfileResource.create
16 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/11/2024 in #sapphire-support
Formatted Logs
All I am doing is formatting it to add a constext element to show where the log is coming from.
16 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/11/2024 in #sapphire-support
Formatted Logs
For reference, my custom log class looks like this.
export class TourneyMateLogger extends Logger implements ILogger {
constructor(options: LoggerOptions) {
super(options);
}

public override has(level: LogLevel): boolean {
return super.has(level);
}

public override debug(message: string, context: string | null = null): void {
super.debug(this.formatLogMessage(message, context));
}

public override error(message: string, context: string | null = null): void {
super.error(this.formatLogMessage(message, context));
}

public override fatal(message: string, context: string | null = null): void {
return super.fatal(this.formatLogMessage(message, context));
}

public override info(message: string, context: string | null = null): void {
super.info(this.formatLogMessage(message, context));
}

public override trace(message: string, context: string | null = null): void {
super.trace(this.formatLogMessage(message, context));
}

public override warn(message: string, context: string | null = null): void {
super.warn(this.formatLogMessage(message, context));
}

protected formatLogMessage(message: string, context: string | null = null): string {
if (context) {
return `[${context}]: ${message}`;
} else {
return message;
}
}
}
export class TourneyMateLogger extends Logger implements ILogger {
constructor(options: LoggerOptions) {
super(options);
}

public override has(level: LogLevel): boolean {
return super.has(level);
}

public override debug(message: string, context: string | null = null): void {
super.debug(this.formatLogMessage(message, context));
}

public override error(message: string, context: string | null = null): void {
super.error(this.formatLogMessage(message, context));
}

public override fatal(message: string, context: string | null = null): void {
return super.fatal(this.formatLogMessage(message, context));
}

public override info(message: string, context: string | null = null): void {
super.info(this.formatLogMessage(message, context));
}

public override trace(message: string, context: string | null = null): void {
super.trace(this.formatLogMessage(message, context));
}

public override warn(message: string, context: string | null = null): void {
super.warn(this.formatLogMessage(message, context));
}

protected formatLogMessage(message: string, context: string | null = null): string {
if (context) {
return `[${context}]: ${message}`;
} else {
return message;
}
}
}
16 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/11/2024 in #sapphire-support
Formatted Logs
What is happening is it is still using the old logger. Or, at least, it isn't showing my custom log formats.
16 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/11/2024 in #sapphire-support
Formatted Logs
Yeah. I thought that's what I did. I extended the logger from the plugin.
import { Logger, LoggerOptions } from '@sapphire/plugin-logger';

/**
* TourneyMateLogger
*
* The tourneymate logger.
*/

export class TourneyMateLogger extends Logger implements ILogger {...}
import { Logger, LoggerOptions } from '@sapphire/plugin-logger';

/**
* TourneyMateLogger
*
* The tourneymate logger.
*/

export class TourneyMateLogger extends Logger implements ILogger {...}
And, in my custom client, I specified the the instance of the extended logger like so.
logger: {
level: LogLevel.Debug,
instance: new TourneyMateLogger({
level: LogLevel.Debug
})
},
logger: {
level: LogLevel.Debug,
instance: new TourneyMateLogger({
level: LogLevel.Debug
})
},
. Is there something I am supposed to do differently?
16 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/11/2024 in #sapphire-support
Formatted Logs
Bump
16 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/5/2024 in #sapphire-support
Failure Handling With Listeners.
Yeah. Thats an option. I’m not a fan of adding even more complexity though. For now, I’ll just use the retry() option and just have it fail somewhat gracefully if hell breaks loose. 🙂
15 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/5/2024 in #sapphire-support
Failure Handling With Listeners.
Ah. Found it. Thank you. 🙂
15 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/5/2024 in #sapphire-support
Failure Handling With Listeners.
Ooh. I found the Event. What’s the retry package you are referring to? Is it a third-party? I’m looking all over GitHub for it. lol
15 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/5/2024 in #sapphire-support
Failure Handling With Listeners.
I do that already. The challenge is there are multiple things that can go wrong, and need to be undone/rolled back if they fail. And, adding that rollback logic just makes everything more convoluted. For example, a command runs and some data is persisted to my database. In success, a new channel is created in some category. And after that, the bot sends a message to that created channel, then as a side effect, the bot sends a message to the logging channel. If anything fails in the subsequent steps after the data is saved to the DB, rolling back will just be way harder. I.e. the created channel would need to be deleted (which could also fail), and as a result of that, the database record that was created needs to be deleted because it saved the channel ID which now doesn’t exist. And so forth. It’s much easier to read code when all it does is save stuff to the DB and then fire an event and let someone else handle the rest.
15 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/3/2024 in #sapphire-support
Running Async Code in Precinditions
I’m blind. Yes you can. Just found it in the docs. lol
4 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/2/2024 in #sapphire-support
Getting Data from .env File
Oh cool. So I don’t need to submit a bug report 🙂
128 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/2/2024 in #sapphire-support
Getting Data from .env File
Just tried it. Looks like it worked. So, I guess the solution here is to change the build script to add the —strip-leading-paths flag.
128 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/2/2024 in #sapphire-support
Getting Data from .env File
Okay. So, remove the extra ”..”? Kk. Will try later. Working on something else rn.
128 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/2/2024 in #sapphire-support
Getting Data from .env File
First time using it too (and first time using Sapphire). It definitely has its quirks. Even after the changes I made, it still doesn’t like my start script pointing to dist/index.js (can’t find env vars again… but it can load commands now). So, it still needs to point to dist/src/index.js. Might just file a bug report later today tbh. Can’t be the only one facing this.
128 replies
SIASapphire - Imagine a framework
Created by Je Suis Un Ami on 3/2/2024 in #sapphire-support
Getting Data from .env File
Thanks… don’t think that swc template was very well tested lol.
128 replies