Logging #1

1 year ago

Avatar of Vilsol
Vilsol, Admin
Offline

Here is my view on how we should handle logging:

There should be a single static class that handles all logging, most likely called TridentLogger. In this class would be static methods info(), debug() and error(). Each one would link back to an internal private method with a passed enum of the type of the record. From there, the method will look up the stack trace and see what class called the initial method, get the classloader and look up the plugin. Because each plugin will have its own classloader, two plugins would not collide if they had the same package and class names. From there, the method would pass it down to System.out or System.err respectively. The final output should look like [12:04:32][Info][TestPlugin] Test Info Log.

Last edit by Vilsol, 1 year ago
0

Logging #2

1 year ago

Avatar of xTrollxDudex
xTrollxDudex, Admin
Offline

Currently the way I'm implementing it is through pipelining where each "console" has a specific function and passes it all the way down the the underlying console.

class Console {
    void log(String string);
}

 

class FileLogger {
    private final Console delegate;
    @Override public void log(String string) {
        // File logging logic
        delegate.log(string);
    }
} 

 

FileLogger logger = new FileLogger(new UnixConsole());
logger.log("string");
0

Logging #3

1 year ago

Avatar of Vilsol
Vilsol, Admin
Offline

Yes, that's logging to a file, I am talking about general logging.

 
0

Logging #4

1 year ago

Avatar of xTrollxDudex
xTrollxDudex, Admin
Offline

General logging needs to log to a file as well.

0

Logging #5

1 year ago

Avatar of TheWasp
TheWasp, Member
Offline

Please make the logger abstract, something like:


Logger interface

DelegateLogger abstract class

FileLogger class


That way someone can inject their own logger into the process so they are able to view the logged output to send it to a web interface or a skype bot or whatever they want without having to extend FileLogger, which is messy.

Last edit by TheWasp, 1 year ago
0

Logging #6

10 months ago

Avatar of xTrollxDudex
xTrollxDudex, Admin
Offline

Loggers can be inserted using https://github.com/TridentSDK/TridentSDK/blob/fc6b5eec705476957034f822562fd4c287b1bdeb/src/main/java/net/tridentsdk/command/logger/LogHandler.java#L41


LogHandler.intercept(null, new LogHandler() {
    public void handle(LogMessage msg) {
        // Handle message
    }
});
0
Copyright © 2017 TridentSDK
Made by Vilsol