Finish initializing.md
This commit is contained in:
parent
ec85882fde
commit
bfbe0b0053
1 changed files with 104 additions and 3 deletions
|
@ -1,7 +1,108 @@
|
|||
---
|
||||
sidebar_position: 1
|
||||
title: Initializing
|
||||
title: Initializing the engine
|
||||
---
|
||||
|
||||
# Initializing
|
||||
## TODO
|
||||
# Initializing the engine
|
||||
To initialize the sos!engine, simply add this to the initialization code of your application:
|
||||
```java
|
||||
new Engine();
|
||||
```
|
||||
|
||||
This is enough to initialize the engine and all installed subsystems. No need to manually initialize them.
|
||||
|
||||
## Printing something
|
||||
Now you'll probably want to print some log output. Before you try using `System.out#println`,
|
||||
`java.util.logging`, Log4J, SLFJ or some other logging library, please don't! The engine
|
||||
provides it's own logging implementation and is HIGHLY recommended to be used instead.
|
||||
|
||||
There are eight log levels you can use:
|
||||
<table>
|
||||
<tr>
|
||||
<th>Level</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>DIAGNOSTIC</th>
|
||||
<th>Provide detailed information about what is happening</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>VERBOSE</th>
|
||||
<th>Additional information that may not be useful</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>SILENT_WARNING</th>
|
||||
<th>Warnings that can be ignored or are caused by invalid (API) user input</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>INFORMATIONAL</th>
|
||||
<th>Useful information about what is happening</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>WARNING</th>
|
||||
<th>Warnings about dangerous or weird behaviour</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>ERROR</th>
|
||||
<th>Non-fatal errors</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>CRASH</th>
|
||||
<th>Fatal errors which may or may not halt the running program (see below)</th>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Here's an example:
|
||||
```java
|
||||
Logger.info(new LogIssuer(Main.class), "Hello World!");
|
||||
```
|
||||
|
||||
Now, what is this `LogIssuer` garbage? It's simple: It describes the class issuing the log call. You can for example pass along information about the data you are handling to easily distinguish instances:
|
||||
```java
|
||||
class ExampleClass() {
|
||||
@NotNull
|
||||
private String string;
|
||||
|
||||
public ExampleClass(@NotNull String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
public boolean checkForEscapes() {
|
||||
Logger.diag(new LogIssuer(getClass(), string), "Checking for escapes");
|
||||
return string.contains("\\");
|
||||
}
|
||||
|
||||
public boolean checkIfEmpty() {
|
||||
Logger.diag(new LogIssuer(getClass(), string), "Checking if empty");
|
||||
return string.isEmpty();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
But it's lame to always pass that to every log call you make. For that reason `LoggerInstance` exists.
|
||||
Here's the class from before but with `LoggerInstance`:
|
||||
```java
|
||||
class ExampleClass() {
|
||||
@NotNull
|
||||
private LoggerInstance logger = new LoggerInstance(new LogIssuer(getClass(), string));
|
||||
|
||||
@NotNull
|
||||
private String string;
|
||||
|
||||
public ExampleClass(@NotNull String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
public boolean checkForEscapes() {
|
||||
logger.diag("Checking for escapes");
|
||||
return string.contains("\\");
|
||||
}
|
||||
|
||||
public boolean checkIfEmpty() {
|
||||
logger.diag("Checking if empty");
|
||||
return string.isEmpty();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
As you can see, it's much simpler. No need to pass that to every call now!
|
||||
|
|
Loading…
Reference in a new issue