-
-
Notifications
You must be signed in to change notification settings - Fork 1
Logging
Nexus does perform some form of logging, but this is rarely used, although due to using logging, we needed some form of flexible logging configuration. As such, we support using custom logging adapters for developers to use to handle the logging of Nexus.
By default, Nexus will use a default implementation of NexusConsoleLoggingAdapter
when there are no available SLF4J bindings.
To create your own logging adapter, you have to implement the NexusLoggingAdapter
which sports 4 methods (info
, error
, warn
and debug
). Originally, Nexus uses SLF4J as a default (although, we use Kotlin to interpolate data, so don't worry about placeholders!).
Once you've created your own logging adapter, you can then set the logging adapter to Nexus:
Nexus.configure {
global.logger = <your logging adapter>
}
You can refer to the existing, built-in logging adapters for more information about different logging adapters:
-
NexusDefaultLoggingAdapter
: used when there is an available SLF4J-binding. -
NexusConsoleLoggingAdapter
: a default implementation is used when there are no available SLF4J-binding.
Nexus comes with a built-in logging adapter that uses System.out
and comes with level support. The console logging adapter is customizable enough for one's liking and can therefore be used, but we provide default configurations that follows Javacord's logging style with an example of the logging message being:
2022-03-09 15:57:20.493+0800 INFO Nexus You have received the message: Hello World
You can configure Nexus to use this logging adapter with a single line of code:
Nexus.setLogger(new NexusConsoleLoggingAdapter(new NexusConsoleLoggingConfiguration()));
The default configuration follows the specific configuration:
-
$_DATE $_LEVEL Nexus $_MESSAGE
format - A default date-time format of
yyyy-MM-dd HH:mm:ss.SSSZ
.
You can customize the format but keep the default date-time format by creating a new instance with this:
new NexusConsoleLoggingConfiguration(
"$_DATE $_LEVEL Nexus is Potato! $_MESSAGE"
)
This will create a configuration that has the following:
-
$_DATE $_LEVEL Nexus is Potato! $_MESSAGE
format which translates into2022-03-09 15:57:20.493+0800 INFO Nexus is Potato! You have received the message: Hello World
. - A default date-time format of
yyyy-MM-dd HH:mm:ss.SSSZ
.
You can customize the date-time format but keep the default logging format by creating a new instance with this:
new NexusConsoleLoggingConfiguration(
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSZ")
)
You can also customize both of them at the same time if you wish by creating a new instance like this:
new NexusConsoleLoggingConfiguration(
"$_DATE $_LEVEL Nexus is Potato! $_MESSAGE",
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSZ")
)
You can disable date-time formatting by either not including $_DATE
in the format or by setting the date-time format as null
.
If you want to enable DEBUG logging level then you can use the method:
new NexusConsoleLoggingConfiguration().allow(NexusConsoleLoggingLevel.DEBUG);
If you want to prevent the logging of a specific level, for instance, INFO then you can use the method:
new NexusConsoleLoggingConfiguration().disallow(NexusConsoleLoggingLevel.INFO);
If you want to set specific logging levels without using disallow
everytime then you can use this method:
new NexusConsoleLoggingConfiguration().set(NexusConsoleLoggingLevel.ERROR, NexusConsoleLoggingLevel.WARN);
All information in this wiki was written during v1.2.0
, we recommend updating to that version if you are below, or creating an issue in GitHub, updating the wiki if the current information is missing, outdated or lacking.
To get started with Nexus, we recommend reading the following in chronological:
- Installation & Preparing Nexus
- Designing Commands
- Command Interceptors
- Additional Features (Subcommand Router, Option Validation)
- Context Menus
- Command Synchronization
You may want to read a specific part of handling command and middleware responses:
You can also read about additional features of Nexus:
- Subcommand Routing
- Option Validation
- Express Way (shard management)
- Inheritance
- Feather Pagination
- Nexus.R
You can read about synchronizing commands to Discord:
For more additional performance:
Additional configurations: