Use Logger instead of println #126
@ -5,7 +5,10 @@ import org.apache.logging.log4j.LogManager;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class ExampleMod implements ModInitializer {
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
![]() Why not Why not `LOGGER.info("Hello Fabric world!")`?
![]() Would be fine with me, i just thought this would more obviously hint towards other options besides INFO. Should i change it? Would be fine with me, i just thought this would more obviously hint towards other options besides INFO.
Should i change it?
![]() I would, I generally dont pass the level like that in a case like this. I would, I generally dont pass the level like that in a case like this.
![]() Alright, give me a minute. Alright, give me a minute.
![]() Might want to give the logger a name, for example Might want to give the logger a name, for example `LogManager.getLogger("ExampleMod")`.
![]() By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
```java
// Returns a Logger with the name of the calling class.
// Returns:
// The Logger for the calling class.
// Throws:
// UnsupportedOperationException – if the calling class cannot be determined.
public static Logger getLogger() {
return getLogger(StackLocatorUtil.getCallerClass(2));
}
```
![]() Imo we should use the mod id for the logger name. Imo we should use the mod id for the logger name.
![]() Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices. Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices.
![]() @sfPlayer1 How would I get the mod id? Or do you mean @sfPlayer1 How would I get the mod id? Or do you mean `LogManager.getLogger("modid")`?
![]() Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported. Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported.
![]() How does this sound?
How does this sound?
```java
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LogManager.getLogger("modid");
```
|
||||
// This logger is used to write text to the console and the log file.
|
||||
![]() Why not Why not `LOGGER.info("Hello Fabric world!")`?
![]() Would be fine with me, i just thought this would more obviously hint towards other options besides INFO. Should i change it? Would be fine with me, i just thought this would more obviously hint towards other options besides INFO.
Should i change it?
![]() I would, I generally dont pass the level like that in a case like this. I would, I generally dont pass the level like that in a case like this.
![]() Alright, give me a minute. Alright, give me a minute.
![]() Might want to give the logger a name, for example Might want to give the logger a name, for example `LogManager.getLogger("ExampleMod")`.
![]() By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
```java
// Returns a Logger with the name of the calling class.
// Returns:
// The Logger for the calling class.
// Throws:
// UnsupportedOperationException – if the calling class cannot be determined.
public static Logger getLogger() {
return getLogger(StackLocatorUtil.getCallerClass(2));
}
```
![]() Imo we should use the mod id for the logger name. Imo we should use the mod id for the logger name.
![]() Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices. Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices.
![]() @sfPlayer1 How would I get the mod id? Or do you mean @sfPlayer1 How would I get the mod id? Or do you mean `LogManager.getLogger("modid")`?
![]() Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported. Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported.
![]() How does this sound?
How does this sound?
```java
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LogManager.getLogger("modid");
```
|
||||
// It is considered best practice to use your mod id as the logger's name.
|
||||
![]() Why not Why not `LOGGER.info("Hello Fabric world!")`?
![]() Would be fine with me, i just thought this would more obviously hint towards other options besides INFO. Should i change it? Would be fine with me, i just thought this would more obviously hint towards other options besides INFO.
Should i change it?
![]() I would, I generally dont pass the level like that in a case like this. I would, I generally dont pass the level like that in a case like this.
![]() Alright, give me a minute. Alright, give me a minute.
![]() Might want to give the logger a name, for example Might want to give the logger a name, for example `LogManager.getLogger("ExampleMod")`.
![]() By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
```java
// Returns a Logger with the name of the calling class.
// Returns:
// The Logger for the calling class.
// Throws:
// UnsupportedOperationException – if the calling class cannot be determined.
public static Logger getLogger() {
return getLogger(StackLocatorUtil.getCallerClass(2));
}
```
![]() Imo we should use the mod id for the logger name. Imo we should use the mod id for the logger name.
![]() Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices. Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices.
![]() @sfPlayer1 How would I get the mod id? Or do you mean @sfPlayer1 How would I get the mod id? Or do you mean `LogManager.getLogger("modid")`?
![]() Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported. Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported.
![]() How does this sound?
How does this sound?
```java
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LogManager.getLogger("modid");
```
|
||||
// That way, it's clear which mod wrote info, warnings, and errors.
|
||||
![]() Why not Why not `LOGGER.info("Hello Fabric world!")`?
![]() Would be fine with me, i just thought this would more obviously hint towards other options besides INFO. Should i change it? Would be fine with me, i just thought this would more obviously hint towards other options besides INFO.
Should i change it?
![]() I would, I generally dont pass the level like that in a case like this. I would, I generally dont pass the level like that in a case like this.
![]() Alright, give me a minute. Alright, give me a minute.
![]() Might want to give the logger a name, for example Might want to give the logger a name, for example `LogManager.getLogger("ExampleMod")`.
![]() By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
```java
// Returns a Logger with the name of the calling class.
// Returns:
// The Logger for the calling class.
// Throws:
// UnsupportedOperationException – if the calling class cannot be determined.
public static Logger getLogger() {
return getLogger(StackLocatorUtil.getCallerClass(2));
}
```
![]() Imo we should use the mod id for the logger name. Imo we should use the mod id for the logger name.
![]() Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices. Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices.
![]() @sfPlayer1 How would I get the mod id? Or do you mean @sfPlayer1 How would I get the mod id? Or do you mean `LogManager.getLogger("modid")`?
![]() Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported. Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported.
![]() How does this sound?
How does this sound?
```java
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LogManager.getLogger("modid");
```
|
||||
public static final Logger LOGGER = LogManager.getLogger("modid");
|
||||
![]() Why not Why not `LOGGER.info("Hello Fabric world!")`?
![]() Would be fine with me, i just thought this would more obviously hint towards other options besides INFO. Should i change it? Would be fine with me, i just thought this would more obviously hint towards other options besides INFO.
Should i change it?
![]() I would, I generally dont pass the level like that in a case like this. I would, I generally dont pass the level like that in a case like this.
![]() Alright, give me a minute. Alright, give me a minute.
![]() Might want to give the logger a name, for example Might want to give the logger a name, for example `LogManager.getLogger("ExampleMod")`.
![]() By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
```java
// Returns a Logger with the name of the calling class.
// Returns:
// The Logger for the calling class.
// Throws:
// UnsupportedOperationException – if the calling class cannot be determined.
public static Logger getLogger() {
return getLogger(StackLocatorUtil.getCallerClass(2));
}
```
![]() Imo we should use the mod id for the logger name. Imo we should use the mod id for the logger name.
![]() Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices. Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices.
![]() @sfPlayer1 How would I get the mod id? Or do you mean @sfPlayer1 How would I get the mod id? Or do you mean `LogManager.getLogger("modid")`?
![]() Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported. Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported.
![]() How does this sound?
How does this sound?
```java
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LogManager.getLogger("modid");
```
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
|
||||
![]() Why not Why not `LOGGER.info("Hello Fabric world!")`?
![]() Why not Why not `LOGGER.info("Hello Fabric world!")`?
![]() Would be fine with me, i just thought this would more obviously hint towards other options besides INFO. Should i change it? Would be fine with me, i just thought this would more obviously hint towards other options besides INFO.
Should i change it?
![]() Would be fine with me, i just thought this would more obviously hint towards other options besides INFO. Should i change it? Would be fine with me, i just thought this would more obviously hint towards other options besides INFO.
Should i change it?
![]() I would, I generally dont pass the level like that in a case like this. I would, I generally dont pass the level like that in a case like this.
![]() I would, I generally dont pass the level like that in a case like this. I would, I generally dont pass the level like that in a case like this.
![]() Alright, give me a minute. Alright, give me a minute.
![]() Alright, give me a minute. Alright, give me a minute.
![]() Might want to give the logger a name, for example Might want to give the logger a name, for example `LogManager.getLogger("ExampleMod")`.
![]() Might want to give the logger a name, for example Might want to give the logger a name, for example `LogManager.getLogger("ExampleMod")`.
![]() By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
```java
// Returns a Logger with the name of the calling class.
// Returns:
// The Logger for the calling class.
// Throws:
// UnsupportedOperationException – if the calling class cannot be determined.
public static Logger getLogger() {
return getLogger(StackLocatorUtil.getCallerClass(2));
}
```
![]() By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
```java
// Returns a Logger with the name of the calling class.
// Returns:
// The Logger for the calling class.
// Throws:
// UnsupportedOperationException – if the calling class cannot be determined.
public static Logger getLogger() {
return getLogger(StackLocatorUtil.getCallerClass(2));
}
```
![]() Imo we should use the mod id for the logger name. Imo we should use the mod id for the logger name.
![]() Imo we should use the mod id for the logger name. Imo we should use the mod id for the logger name.
![]() Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices. Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices.
![]() Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices. Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices.
![]() @sfPlayer1 How would I get the mod id? Or do you mean @sfPlayer1 How would I get the mod id? Or do you mean `LogManager.getLogger("modid")`?
![]() @sfPlayer1 How would I get the mod id? Or do you mean @sfPlayer1 How would I get the mod id? Or do you mean `LogManager.getLogger("modid")`?
![]() Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported. Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported.
![]() Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported. Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported.
![]() How does this sound?
How does this sound?
```java
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LogManager.getLogger("modid");
```
![]() How does this sound?
How does this sound?
```java
// This logger is used to write text to the console and the log file.
// It is considered best practice to use your mod id as the logger's name.
// That way, it's clear which mod wrote info, warnings, and errors.
public static final Logger LOGGER = LogManager.getLogger("modid");
```
|
Why not
LOGGER.info("Hello Fabric world!")
?Why not
LOGGER.info("Hello Fabric world!")
?Would be fine with me, i just thought this would more obviously hint towards other options besides INFO.
Should i change it?
Would be fine with me, i just thought this would more obviously hint towards other options besides INFO.
Should i change it?
I would, I generally dont pass the level like that in a case like this.
I would, I generally dont pass the level like that in a case like this.
Alright, give me a minute.
Alright, give me a minute.
Might want to give the logger a name, for example
LogManager.getLogger("ExampleMod")
.Might want to give the logger a name, for example
LogManager.getLogger("ExampleMod")
.By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
By default, the getLogger will use the Caller's class name. So that would be ExampleMod anyways.
Imo we should use the mod id for the logger name.
Imo we should use the mod id for the logger name.
Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices.
Yes, definitely mod id. It is the most useful for the end user and we want to promote best practices.
@sfPlayer1 How would I get the mod id? Or do you mean
LogManager.getLogger("modid")
?@sfPlayer1 How would I get the mod id? Or do you mean
LogManager.getLogger("modid")
?Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported.
Yes, but please add a comment to encourage using the actual mod id. I may add something to Loader to determine it from a class eventually, but for now it's not really supported.
How does this sound?
How does this sound?