Compare commits

...

6 Commits

Author SHA1 Message Date
p.belezov 2959fe6dab Some readme changes 2024-03-06 15:52:55 +08:00
p.belezov d6f1f3d859 Delete already 2024-03-06 15:51:10 +08:00
p.belezov f8766840fa Dumbass 2024-03-06 15:50:30 +08:00
p.belezov 17e2d6f8c5 I said removed .idea directory 2024-03-06 15:48:06 +08:00
p.belezov 9ca675cfaf removed .idea directory 2024-03-06 15:47:05 +08:00
p.belezov 1c9047e298 Slightly improved safety; Added Readme 2024-03-06 15:45:40 +08:00
8 changed files with 88 additions and 152 deletions

1
.gitignore vendored
View File

@ -4,6 +4,7 @@ out/
!**/src/test/**/out/ !**/src/test/**/out/
### Eclipse ### ### Eclipse ###
.idea/
.apt_generated .apt_generated
.classpath .classpath
.factorypath .factorypath

3
.idea/.gitignore vendored
View File

@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -1,9 +0,0 @@
<component name="ArtifactManager">
<artifact type="jar" name="dhaverdLogs-2.0">
<output-path>$PROJECT_DIR$/out/artifacts/dhaverdLogs</output-path>
<root id="archive" name="dhaverdLogs-2.0.jar">
<element id="module-output" name="dhaverdLogs 2.0" />
<element id="module-source" name="dhaverdLogs 2.0" />
</root>
</artifact>
</component>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/dhaverdLogs 2.0.iml" filepath="$PROJECT_DIR$/dhaverdLogs 2.0.iml" />
</modules>
</component>
</project>

View File

@ -1,124 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

75
Readme.md Normal file
View File

@ -0,0 +1,75 @@
# What it is
This is simple logging library for Java, mostly written for myself. It can log what you want into file and console output.
# Usage
### Initialize
There is 2 way to initialize the DLogger class. There is no particular difference between them.
```
DLogger logger = new DLogger(true);
// Log file name will be: 2024.03.06_14-37-12_log.log
OR
DLogger logger = new DLogger(false, "log.log");
// Log file name will be: 2024.03.06_14-37-12_your_log_name.log
// Chars \ / : * ? " < > | will be replace with _
```
### Using
Now you can set up logging directory. But you don't have to, then the default directory will be the project root "./".
```
logger.setLogDir("/home/user/logs/");
```
Next you can use logger. Logger accepts 4 parameters:
- String context - a property added for convenience that allows you to manually indicate where a log line was called from;
- String text - log text;
- boolean addTime - should logger add current time to log line;
- boolean addIndent - should logger add indent (22 spaces) to log line;
Examples:
```
logger.log("Some context", "Some text", false false);
// Output
// [Some context] Some text
logger.log("MyClass", "Abracadabra", true, false);
// Output
// [2024-03-06 15:28:31] [MyClass] Abracadabra
logger.log("MyClass", "Abracadabra", false, true);
// Output
// [MyClass] Abracadabra
logger.log("MyClass", "Abracadabra", true, true);
// Output
// [2024-03-06 15:28:31] [MyClass] Abracadabra
// By the way you can use logger to log exeptions
...
catch(Exeption e){
for (StackTraceElement trace : e.getStackTrace()){
logger.log("MyClass Exeption", trace.toString(), true, false);
}
}
// Output
// [2024-03-06 15:28:31] [MyClass Exeption] NullPointerExeption
// [2024-03-06 15:28:31] [MyClass Exeption] Exeption trace line 1
// [2024-03-06 15:28:31] [MyClass Exeption] Exeption trace line 2
// ...
```

View File

@ -14,11 +14,14 @@ public class DLogger {
private String fileName; private String fileName;
private boolean autoGenerateFileName; private boolean autoGenerateFileName;
private static String logDir = ""; private static String logDir = "";
private String[] unacceptableChars = {"\\", "/", ":", "*", "?", "\"", "<", ">", "|"};
private boolean customLogDir; private boolean customLogDir;
public DLogger(String fileName, boolean autoGenerateFileName) { public DLogger(boolean autoGenerateFileName, String ...fileName) {
this.fileName = fileName; if (fileName.length != 0){
this.fileName = replaceUnacceptableChar(fileName[0]);
}
this.autoGenerateFileName = autoGenerateFileName; this.autoGenerateFileName = autoGenerateFileName;
} }
@ -27,6 +30,13 @@ public class DLogger {
this.customLogDir = true; this.customLogDir = true;
} }
private String replaceUnacceptableChar(String str){
for (String character : unacceptableChars){
str = str.replace(character, "_");
}
return str;
}
private String getCurrentTime(){ private String getCurrentTime(){
String time; String time;
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");