Skip to content

add new logger system#27

Open
kryllyxofficial01 wants to merge 21 commits into
masterfrom
New-Logger
Open

add new logger system#27
kryllyxofficial01 wants to merge 21 commits into
masterfrom
New-Logger

Conversation

@kryllyxofficial01
Copy link
Copy Markdown
Contributor

No description provided.

*/
public void addHeader(String header) {
if (hasHeader(header)) {
System.err.println("The header \"" + header + "\" already exists.");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define a constant instead of duplicating this literal "The header "" 3 times.

}
}
}
private BufferedWriter logger;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename field "logger"

public class DriveModule implements Loggable {

private final double VELOCITY_COEFFICIENT = 600 / 2048;
// private final double VELOCITY_COEFFICIENT = 600 / 2048;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of commented-out lines of code should be removed.

Comment thread src/main/java/frc/robot/Robot.java Outdated
import frc.robot.logging.LoggableCompressor;
import frc.robot.logging.LoggableController;
import frc.robot.logging.LoggableGyro;
// import frc.robot.logging.LoggableGyro;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of commented-out lines of code should be removed.

}
else {
if (hasData(header)) {
System.err.println("The header \"" + header + "\" already has data.");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is longer than 100 characters (found 102).

import frc.robot.logging.LoggableTimer;
import frc.robot.logging.Logger;

import java.io.IOException;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra separation in import group before 'java.io.IOException'

Comment thread src/main/java/frc/robot/Robot.java Outdated
try {
logger.createLog();
} catch (IOException e) {
// TODO Auto-generated catch block
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found

Comment thread src/main/java/frc/robot/Robot.java Outdated
try {
logger.writeData();
} catch (IOException e) {
// TODO Auto-generated catch block
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found

Comment thread src/main/java/frc/robot/Robot.java Outdated
try {
logger.writeData();
} catch (IOException e) {
// TODO Auto-generated catch block
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found

Comment thread src/main/java/frc/robot/Robot.java Outdated
try {
logger.writeData();
} catch (IOException e) {
// TODO Auto-generated catch block
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 23, 2022

Codecov Report

Merging #27 (a5412f1) into master (2c8045c) will increase coverage by 0.34%.
The diff coverage is 1.23%.

❗ Current head a5412f1 differs from pull request most recent head f1439e3. Consider uploading reports for the commit f1439e3 to get more accurate results

Impacted file tree graph

@@             Coverage Diff             @@
##             master     #27      +/-   ##
===========================================
+ Coverage      9.63%   9.98%   +0.34%     
  Complexity       17      17              
===========================================
  Files            18      19       +1     
  Lines           685     661      -24     
  Branches         47      43       -4     
===========================================
  Hits             66      66              
+ Misses          619     595      -24     
Impacted Files Coverage Δ
src/main/java/frc/robot/Climber.java 0.00% <0.00%> (ø)
src/main/java/frc/robot/ClimberGates.java 0.00% <0.00%> (ø)
src/main/java/frc/robot/ClimberSensors.java 0.00% <0.00%> (ø)
src/main/java/frc/robot/DriveModule.java 0.00% <0.00%> (ø)
src/main/java/frc/robot/Drivetrain.java 0.00% <0.00%> (ø)
src/main/java/frc/robot/Robot.java 0.00% <0.00%> (ø)
src/main/java/frc/robot/logging/LogTimer.java 0.00% <0.00%> (ø)
...ain/java/frc/robot/logging/LoggableCompressor.java 0.00% <0.00%> (ø)
...ain/java/frc/robot/logging/LoggableController.java 0.00% <0.00%> (ø)
...va/frc/robot/logging/LoggableFirstOrderFilter.java 0.00% <0.00%> (ø)
... and 5 more

Impacted file tree graph

* Sends all accumulated data to log file.
*/
public void logAll() {
// logAllData();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of commented-out lines of code should be removed.

// writeData();
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of commented-out lines of code should be removed.

Comment thread src/main/java/frc/robot/Robot.java Outdated
@Override
public void robotInit() {
logger = new Logger();
runnable = new Runnable() {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this anonymous inner class a lambda (sonar.java.source not set. Assuming 8 or greater.)

// e.printStackTrace();
// }

// throw new NullPointerException();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of commented-out lines of code should be removed.

// try {
// writeData();
// } catch (IOException e) {
// // TODO Auto-generated catch block
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found

@kryllyxofficial01 kryllyxofficial01 added bug Something isn't working enhancement New feature or request requires robot Will require robot to test ready to test Needs to be tested on robot or test board labels Jun 24, 2022
Comment thread src/main/java/frc/robot/Robot.java Outdated
// import frc.robot.logging.LoggableGyro;
import frc.robot.logging.LoggablePowerDistribution;
import frc.robot.logging.LoggableTimer;
import frc.robot.logging.LogTimer;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong lexicographical order for 'frc.robot.logging.LogTimer' import. Should be before 'frc.robot.logging.LoggableTimer'.

}
writeData();
} catch (IOException e) {
// TODO Auto-generated catch block
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found

Comment thread src/main/java/frc/robot/Robot.java Outdated
try {
logger.writeHeaders();
} catch (IOException e) {
// TODO Auto-generated catch block
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO found

@kryllyxofficial01 kryllyxofficial01 removed the bug Something isn't working label Jul 1, 2022
Calendar calendar = Calendar.getInstance();
String dir = "\\home\\lvuser\\logs";
Path path = Paths.get(dir + "\\" + calendar.get(Calendar.YEAR) + "-"
+ (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DAY_OF_MONTH) + "-"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is longer than 100 characters (found 102).

i was going to add images, but the code snippets I think work better
Comment thread README.md
package frc.robot.logging

public class LoggableTest implements Loggable {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

Comment thread README.md
public class LoggableTest implements Loggable {
@Override
public void logHeaders(Logger logger) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

Comment thread README.md
public void logHeaders(Logger logger) {

}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

Comment thread README.md

@Override
public void logData(Logger logger) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

Comment thread README.md
logger.addHeader("first_name");
logger.addHeader("last_name");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

Comment thread README.md
```
<br>

6. There you go! Our *Loggable* object has been created. Don't think that you can't add other things as well. Constructors, other methods, those won't get in the way (except, of course, if you name other methods the same name). As long as your class has `logHeaders()` and `logData()`, you're good.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Comment thread README.md Outdated
### Create the Loggable
1. Go to ***/src/main/java/frc/robot/logging*** and create a new Java file. The naming system used for the loggables are like this: *Loggable*, followed immediately by the name of the system being logged. For demonstrations purposes, I will call it *LoggableTest.java*.

2. Inside this file, create a new class. You'll also need to have it implement *Loggable.java* (`public class LoggableTest implements Loggable`). This contains the methods needed to accumulate data to send to the log file. No import will be needed, as *Loggable.java* is in the same file as our *LoggableTest* class.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Comment thread README.md Outdated
```
<br>

3. Next you'll need to implement the methods from *Loggable.java*. The first method is `logHeaders()`. This method is only for logging headers. The second method is `logData()`. This is only for logging data. **Make sure to have the `@Override` decorator above both methods.**
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Comment thread README.md
```
<br>

4. In the `logHeaders()` method, we will have two headers: *first_name*, and *last_name*. So, we need to use the `logger` parameter to access the necessary method to add these headers.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Comment thread README.md
```
<br>

5. Now let's add our data. Under `logData()`, use the `logger` parameter to access the needed methods. Make sure to specify the header you want the data to go under. Don't worry about converting the data to `string` type. The logger does that automatically.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

i also fixed the pronouns
Comment thread README.md
public class LoggableTest implements Loggable {
@Override
public void logHeaders(Logger logger) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

Comment thread README.md
public void logHeaders(Logger logger) {

}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

Comment thread README.md

@Override
public void logData(Logger logger) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

Comment thread README.md
logger.addHeader("first_name");
logger.addHeader("last_name");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

Comment thread README.md

@Override
public void logData(Logger logger) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing spaces

Comment thread README.md
```
<br>

4. Now go into the `robotInit()` method and create the new instance. This is what the logger will register. If there's a constructor, make sure to give the necessary values.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Comment thread README.md
```
<br>

5. Go to the bottom of the `robotInit()` method and use the `logger.addLoggable()` method to register `loggableTest` (This is assuming that the *Loggable* is a standalone system. If this is part of another system, then make sure to add it to whatever if-statements belong to that system, if any.) This will allow the logger to call `logHeaders()` and `logData()`.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Comment thread README.md
```
<br>

6. You are now all set! You've added the *LoggableTest* object to the logger, so now, when you start the robot, the log file should contain the info being logged by your *Loggable* object.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Comment thread README.md
### Create the Loggable
1. Go to ***/src/main/java/frc/robot/logging*** and create a new Java file. The naming system used for the loggables are like this: *Loggable*, followed immediately by the name of the system being logged. For demonstrations purposes, I will call it *LoggableTest.java*.

2. Inside this file, create a new class. You'll also need to have it implement *Loggable.java*. This contains the methods needed to accumulate data to send to the log file. No import will be needed, as *Loggable.java* is in the same file as our *LoggableTest* class.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Comment thread README.md
```
<br>

3. Next you'll need to implement the methods from *Loggable.java*. The first method is `logHeaders()`, which is for logging the type of data. It is called only when the robot starts. The second method is `logData()`. This is called approximately 30 times a second. **Make sure to have the `@Override` decorator above both methods.**
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

public void log(Logger logger) {
// TODO Auto-generated method stub
}
public void logData(Logger logger) {}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'}' at column 41 should be alone on a line.

Comment thread README.md
<br>

4. Now go into the `robotInit()` method and create the new instance. This is what the logger will register. If there's a constructor, make sure to give the necessary values.
```java
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

Comment thread README.md
```
<br>

5. Now let's add our data. Under `logData()`, use the `logger` parameter to access the needed methods. Make sure to specify the header you want the data to go under. Don't worry about converting the data to `string` type. The logger does that automatically.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Comment thread README.md
```
<br>

6. There you go! Our *Loggable* object has been created. Don't think that you can't add other things as well. Constructors, other methods, those won't get in the way (except, of course, if you name other methods the same name). As long as your class has `logHeaders()` and `logData()`, you're good.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Comment thread README.md
### Registering the Loggable
1. Go to the main *Robot.java* file in ***/src/main/java/frc/robot***. This is where all of the robot code is.

2. Import *LoggableTest.java*.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Comment thread README.md
<br>

5. Now let's add our data. Under `logData()`, use the `logger` parameter to access the needed methods. Make sure to specify the header you want the data to go under. Don't worry about converting the data to `string` type. The logger does that automatically.
```java
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

Comment thread README.md
logger.addData("last_name", "Bezos")
}
}
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

Comment thread README.md
1. Go to the main *Robot.java* file in ***/src/main/java/frc/robot***. This is where all of the robot code is.

2. Import *LoggableTest.java*.
```java
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

Comment thread README.md
2. Import *LoggableTest.java*.
```java
import frc.robot.logging.LoggableTest;
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

Comment thread README.md
<br>

3. Go to the top of the `Robot` class and create a new *LoggableTest* object.
```java
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

Comment thread README.md
```
<br>

4. In the `logHeaders()` method, we will have two headers: *first_name*, and *last_name*. So, we need to use the `logger` parameter to access the necessary method to add these headers.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ordered list item prefix

Comment thread README.md
3. Go to the top of the `Robot` class and create a new *LoggableTest* object.
```java
LoggableTest loggableTest;
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

Comment thread README.md
4. Now go into the `robotInit()` method and create the new instance. This is what the logger will register. If there's a constructor, make sure to give the necessary values.
```java
loggableTest = new LoggableTest();
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

Comment thread README.md
<br>

5. Go to the bottom of the `robotInit()` method and use the `logger.addLoggable()` method to register `loggableTest` (This is assuming that the *Loggable* is a standalone system. If this is part of another system, then make sure to add it to whatever if-statements belong to that system, if any.) This will allow the logger to call `logHeaders()` and `logData()`.
```java
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

Comment thread README.md
5. Go to the bottom of the `robotInit()` method and use the `logger.addLoggable()` method to register `loggableTest` (This is assuming that the *Loggable* is a standalone system. If this is part of another system, then make sure to add it to whatever if-statements belong to that system, if any.) This will allow the logger to call `logHeaders()` and `logData()`.
```java
logger.addLoggable(loggableTest);
```
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenced code blocks should be surrounded by blank lines

Comment thread README.md

}
```
<br>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML

Comment thread README.md
}
}
```
<br>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML

Comment thread README.md
}
}
```
<br>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML

Comment thread README.md
}
}
```
<br>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML

Comment thread README.md
```java
import frc.robot.logging.LoggableTest;
```
<br>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML

Comment thread README.md
```java
LoggableTest loggableTest;
```
<br>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML

Comment thread README.md
```java
loggableTest = new LoggableTest();
```
<br>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML

Comment thread README.md
```java
logger.addLoggable(loggableTest);
```
<br>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline HTML

Comment thread README.md
To show how to use the logger system, this document will demonstrate the creation of a `Loggable` object and how to register it in the log file.

### Create the Loggable
1. Go to ***/src/main/java/frc/robot/logging*** and create a new Java file. The naming system used for the loggables are like this: *Loggable*, followed immediately by the name of the system being logged. For demonstrations purposes, let's call it *LoggableTest.java*.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line length

Comment thread README.md
To show how to use the logger system, this document will demonstrate the creation of a `Loggable` object and how to register it in the log file.

### Create the Loggable
1. Go to ***/src/main/java/frc/robot/logging*** and create a new Java file. The naming system used for the loggables are like this: *Loggable*, followed immediately by the name of the system being logged. For demonstrations purposes, let's call it *LoggableTest.java*.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lists should be surrounded by blank lines

@kryllyxofficial01 kryllyxofficial01 requested review from NotMePipe and removed request for TheBitEffect and sreeves750 September 7, 2022 13:43
@qlty-cloud-legacy
Copy link
Copy Markdown

Code Climate has analyzed commit a5412f1 and detected 76 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 2
Clarity 3
Style 71

Note: there is 1 critical issue.

The test coverage on the diff in this pull request is 1.2% (50% is the threshold).

This pull request will bring the total coverage in the repository to 9.9% (0.3% change).

View more on Code Climate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ready to test Needs to be tested on robot or test board requires robot Will require robot to test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants