diff --git a/LICENSE b/LICENSE index 75dadd7..7203a0a 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 SantaSpeen +Copyright (c) 2020 Maxim Khomutov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Logger.java b/Logger.java new file mode 100644 index 0000000..4ea3adb --- /dev/null +++ b/Logger.java @@ -0,0 +1,22 @@ +import java.text.SimpleDateFormat; +import java.util.Date; + +public class Logger { + + private final String module; + + public Logger(String module){ + this.module = module; + } + + public String getTime() { + SimpleDateFormat formatForDateNow = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SS"); + return formatForDateNow.format(new Date()); + } + + public Logger core(String text){System.out.println("\033[34m["+getTime()+" CORE]: \033[35m["+this.module+"]\033[0m \033[34m" + text + "\033[0m"); return this;} + public Logger info(String text){System.out.println("\033[32m["+getTime()+" INFO]\033[0m: \033[35m[" + this.module + "]\033[0m " + text); return this;} + public Logger warn(String text){System.out.println("\033[33m\033[5m["+getTime()+" WARN]\033[0m: \033[35m[" + this.module + "]\033[0m " + text); return this;} + public Logger error(String text){System.out.println("\033[31m\033[6m["+getTime()+" ERROR]\033[0m:\033[35m[" + this.module + "]\033[0m " + text); return this;} + +} diff --git a/Logger.kts b/Logger.kts new file mode 100644 index 0000000..8c69bb8 --- /dev/null +++ b/Logger.kts @@ -0,0 +1,30 @@ +import java.text.SimpleDateFormat +import java.util.* + +class Logger(private val module: String) { + val time: String + get() { + val formatForDateNow = SimpleDateFormat("dd.MM.yyyy HH:mm:ss.SS") + return formatForDateNow.format(Date()) + } + + fun core(text: String): Logger { + println("\u001b[34m[$time CORE]: \u001b[35m[$module]\u001b[0m \u001b[34m$text\u001b[0m") + return this + } + + fun info(text: String): Logger { + println("\u001b[32m[$time INFO]\u001b[0m: \u001b[35m[$module]\u001b[0m $text") + return this + } + + fun warn(text: String): Logger { + println("\u001b[33m\u001b[5m[$time WARN]\u001b[0m: \u001b[35m[$module]\u001b[0m $text") + return this + } + + fun error(text: String): Logger { + println("\u001b[31m\u001b[6m[$time ERROR]\u001b[0m:\u001b[35m[$module]\u001b[0m $text") + return this + } +} \ No newline at end of file diff --git a/README.md b/README.md index 82aaaf2..f068adb 100644 --- a/README.md +++ b/README.md @@ -1 +1,54 @@ -# Logger.Java \ No newline at end of file +# Logger for Java + +

+ + +

+ +### Installing + +* Download this repo +* Init in your project + +### Usage +Java: +```java +import Logger; + +class main{ + private static final Logger LOG = new Logger("Module name"); + + public static void main(String[] args) { + LOG.core("Logger: Core"); + LOG.info("Logger: Info"); + LOG.warn("Logger: Warn"); + LOG.error("Logger: Error"); + } + +} +``` +Kotlin: +```kotlin +import Logger + +class main{ + var LOG = Logger("Module name") + + @JvmStatic + fun main(args: Array) { + LOG.core("Logger: Core") + LOG.info("Logger: Info") + LOG.warn("Logger: Warn") + LOG.error("Logger: Error") + } +} + +``` + +### Links! + +- [Python](python.org) + +- [Link to this project](https://github.com/SantaSpeen/Logger.Java) + +- [Author](https://vk.com/id370926160) \ No newline at end of file