Use Logger instead of println #126
@ -14,6 +14,6 @@ public class ExampleMod implements ModInitializer {
|
||||
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
|
||||
LOGGER.log(Level.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?
![]() 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");
```
|
||||
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?
![]() 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");
```
|
||||
}
|
||||
}
|
||||
|
||||
![]() 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");
```
|
@ -12,6 +12,6 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
public class ExampleMixin {
|
||||
@Inject(at = @At("HEAD"), method = "init()V")
|
||||
private void init(CallbackInfo info) {
|
||||
ExampleMod.LOGGER.log(Level.INFO, "This line is printed by an example mod mixin!");
|
||||
ExampleMod.LOGGER.info("This line is printed by an example mod mixin!");
|
||||
}
|
||||
}
|
||||
|
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?