Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tutorial on logging in FastJ #7

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions wiki/tutorials/logging-in-fastj.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
sidebar_position: 3

keywords:
- fastj tutorial
- how to use fastj
- tutorial for fastj
- how to fastj
- fastj how to
- fastj in 5 minutes
- how do I use fastj
- fastj guide
- fastj how to use logging
- fastj how to log messages
- log messages in fastj
- fastj how to make a game
description: Debug your application using the logging capabilities of FastJ!
---

# Logging in FastJ

After the last tutorial, you should have a basic FastJ project which runs successfully.
If you don't, be sure to check the last tutorial which can be found [here][FastJ-In-Minutes-Link] and follow through or at least read it through thoroughly.

So, what even is logging? Well, when your application is running, many things are happening in your application. Even for a simple app, many different things are going on
in the backend. It would be quite helpful to see exactly what's happening right? For example, let's say your game crashes because of a variable having a incorrect value.
One option, would be to spend a minute to walk through the code and figure out what the variable value is. The easier way? Print out the variable and look at the value.
Logging is basically exactly that, but better. It lets you print detailed messages about everything happening in your game, so you can debug with ease.

FastJ has an inbuilt system for handling logging, which is what we will be covering in this article.

## Standard Logging Messages
This is the most basic type of log. Nothing too complicated, just simple logging to the console. Usually just used for sending messages
which just give debugging data. The way to do it is as follows:

```java
import tech.fastj.engine.FastJEngine;

public class Main {
public static void main(String[] args) {
FastJEngine.log("Hello! This is an informational logging statement.");
}
}
```

## Warning Logging
Warnings are a useful tool to warn you of possible errors in your code before they happen. You can put warning logs in places where you think
your code might have a problem, so that it is easier for you to find the cause of the problem faster. You can use them like so:
```java
import tech.fastj.engine.FastJEngine;

public class Main {
public static void main(String[] args) {
FastJEngine.warning("Be careful now! This is a warning.");
}
}
```

## Error Logging
Error logging is a powerful tool in FastJ which will allow you, the user, to be able to see when code isnt executing as expected or when conditions aren't being satisfied for functionality to be performed correctly. This is how you use error logs:
```java
import tech.fastj.engine.FastJEngine;

public class Main {
public static void main(String[] args) {
IllegalStateException exampleException = new IllegalStateException("This is an example exception.");
FastJEngine.error("Oh dear, looks like something went wrong. This is an error message.", exampleException);
}
}
```


## Conclusion
Basically, logging is a very powerful tool you can use to make debugging process much simpler so that you can spend more time working on your game than fixing errors, and using FastJ's in-built tools, it becomes very easy.

[FastJ-In-Minutes-Link]: /wiki/fastj-basics/fastj-quick-start "Hit the ground running by creating your first FastJ program!"
[HelloFastJ-Example-Link]: https://example.fastj.dev/hellofastj/Main.java "Hello, FastJ! | FastJ Tutorials"
[Engine-Configuration-Tutorial-Link]: /wiki/tutorials/fastj-configuration "Configure FastJEngine's FPS, UPS, initial window size, and more!"
[Discord-Link]: https://discord.gg/FTWsYVSDv6 "Join the FastJ Discord!"
[Examples-Link]: https://example.fastj.dev/ "FastJ Examples"


21 changes: 8 additions & 13 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@
dependencies:
"@babel/types" "^7.15.4"

"@babel/helper-validator-identifier@^7.12.11", "@babel/helper-validator-identifier@^7.14.5", "@babel/helper-validator-identifier@^7.14.9", "@babel/helper-validator-identifier@^7.15.7":
"@babel/helper-validator-identifier@^7.14.5", "@babel/helper-validator-identifier@^7.14.9", "@babel/helper-validator-identifier@^7.15.7":
version "7.15.7"
resolved "https://registry.yarnpkg.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.15.7.tgz#220df993bfe904a4a6b02ab4f3385a5ebf6e2389"
integrity sha512-K4JvCtQqad9OY2+yTU8w+E82ywk/fe+ELNlt1G8z3bVGlZfn/hOcQQsUhGhW/N+tb3fxK800wLtKOE/aM0m72w==
Expand Down Expand Up @@ -3084,11 +3084,6 @@ commander@^5.1.0:
resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae"
integrity sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==

commander@^6.2.0:
version "6.2.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c"
integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA==

commander@^7.2.0:
version "7.2.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"
Expand Down Expand Up @@ -3378,9 +3373,9 @@ css-what@^3.2.1:
integrity sha512-ACUm3L0/jiZTqfzRM3Hi9Q8eZqd6IK37mMWPLz9PJxkLWllYeRf+EHUSHYEtFop2Eqytaq1FizFVh7XfBnXCDQ==

css-what@^5.0.0:
version "5.0.1"
resolved "https://registry.yarnpkg.com/css-what/-/css-what-5.0.1.tgz#3efa820131f4669a8ac2408f9c32e7c7de9f4cad"
integrity sha512-FYDTSHb/7KXsWICVsxdmiExPjCfRC4qRFBdVwv7Ax9hMnvMmEjP9RfxTEZ3qPZGmADDn2vAKSo9UcN1jKVYscg==
version "5.1.0"
resolved "https://registry.yarnpkg.com/css-what/-/css-what-5.1.0.tgz#3f7b707aadf633baf62c2ceb8579b545bb40f7fe"
integrity sha512-arSMRWIIFY0hV8pIxZMEfmMI47Wj3R/aWpZDDxWYCPEiOMv6tfOrnpDtgxBYPEQD4V0Y/958+1TdC3iWTFcUPw==

cssesc@^3.0.0:
version "3.0.0"
Expand Down Expand Up @@ -9096,14 +9091,14 @@ web-namespaces@^1.0.0, web-namespaces@^1.1.2:
integrity sha512-wYxSGajtmoP4WxfejAPIr4l0fVh+jeMXZb08wNc0tMg6xsfZXj3cECqIK0G7ZAqUq0PP8WlMDtaOGVBTAWztNw==

webpack-bundle-analyzer@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/webpack-bundle-analyzer/-/webpack-bundle-analyzer-4.4.2.tgz#39898cf6200178240910d629705f0f3493f7d666"
integrity sha512-PIagMYhlEzFfhMYOzs5gFT55DkUdkyrJi/SxJp8EF3YMWhS+T9vvs2EoTetpk5qb6VsCq02eXTlRDOydRhDFAQ==
version "4.5.0"
resolved "https://registry.yarnpkg.com/webpack-bundle-analyzer/-/webpack-bundle-analyzer-4.5.0.tgz#1b0eea2947e73528754a6f9af3e91b2b6e0f79d5"
integrity sha512-GUMZlM3SKwS8Z+CKeIFx7CVoHn3dXFcUAjT/dcZQQmfSZGvitPfMob2ipjai7ovFFqPvTqkEZ/leL4O0YOdAYQ==
dependencies:
acorn "^8.0.4"
acorn-walk "^8.0.0"
chalk "^4.1.0"
commander "^6.2.0"
commander "^7.2.0"
gzip-size "^6.0.0"
lodash "^4.17.20"
opener "^1.5.2"
Expand Down