From 0b060e4b194fe93d777f6cba0905f5dad8faa571 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Sat, 1 Oct 2022 15:18:39 +0200 Subject: [PATCH] [DEV] basic code --- .checkstyle | 7 + .classpath | 22 + .gitattributes | 6 + .gitignore | 25 + .gitlab-ci.yml | 28 + .project | 35 ++ CheckStyle.xml | 66 +++ Formatter.xml | 366 +++++++++++++ GLD_reggol-test.json | 27 + GLD_reggol.json | 24 + LICENSE | 373 +++++++++++++ author.txt | 1 + doc/doc_01_overview.md | 6 + doc/tutorial_01_create_library_logger.md | 97 ++++ doc/tutorial_02_control_logger.md | 28 + lutin_org-atriasoft-reggol.py | 44 ++ menu.json | 17 + src/module-info.java | 7 + src/org/atriasoft/reggol/LogLevel.java | 25 + src/org/atriasoft/reggol/Logger.java | 488 ++++++++++++++++++ src/org/atriasoft/reggol/LoggerLocal.java | 130 +++++ src/org/atriasoft/reggol/internal/Log.java | 60 +++ test/.gitignore | 1 + test/src/test/atriasoft/reggol/.keep | 0 test/src/test/atriasoft/reggol/Log.java | 59 +++ test/src/test/atriasoft/reggol/Log2.java | 18 + .../test/atriasoft/reggol/TestBasicLog.java | 102 ++++ version.txt | 1 + 28 files changed, 2063 insertions(+) create mode 100644 .checkstyle create mode 100644 .classpath create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .gitlab-ci.yml create mode 100644 .project create mode 100755 CheckStyle.xml create mode 100644 Formatter.xml create mode 100644 GLD_reggol-test.json create mode 100644 GLD_reggol.json create mode 100644 LICENSE create mode 100644 author.txt create mode 100644 doc/doc_01_overview.md create mode 100644 doc/tutorial_01_create_library_logger.md create mode 100644 doc/tutorial_02_control_logger.md create mode 100644 lutin_org-atriasoft-reggol.py create mode 100644 menu.json create mode 100644 src/module-info.java create mode 100644 src/org/atriasoft/reggol/LogLevel.java create mode 100644 src/org/atriasoft/reggol/Logger.java create mode 100644 src/org/atriasoft/reggol/LoggerLocal.java create mode 100644 src/org/atriasoft/reggol/internal/Log.java create mode 100644 test/.gitignore create mode 100644 test/src/test/atriasoft/reggol/.keep create mode 100644 test/src/test/atriasoft/reggol/Log.java create mode 100644 test/src/test/atriasoft/reggol/Log2.java create mode 100644 test/src/test/atriasoft/reggol/TestBasicLog.java create mode 100644 version.txt diff --git a/.checkstyle b/.checkstyle new file mode 100644 index 0000000..428926e --- /dev/null +++ b/.checkstyle @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..183c41c --- /dev/null +++ b/.classpath @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..00a51af --- /dev/null +++ b/.gitattributes @@ -0,0 +1,6 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# These are explicitly windows files and should use crlf +*.bat text eol=crlf + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0ad04c9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +/bin/ +/Operator/ +/DrawerProperties/ +*.pdfd +*.dbc +SchedulerConfig.txt +scenicView.properties +ScenariumConfig.txt +*.class +*~ +*.bck +build.number +/extern/ +/out/ +/.settings/ +/junit/ +/target/ + +# Ignore Gradle project-specific cache directory +.gradle + +# Ignore Gradle build output directory +build + +/__pycache__/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..f9ff5a2 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,28 @@ +image: heeroyui/scenarium-gitlabci:latest + +variables: + JAVA_TOOL_OPTIONS: "-Dfile.encoding=UTF8" + +before_script: + - which javac + - javac --version + - mvn --version + - ant -version + +stages: + - all + +ant_job: + stage: all + script: + - ant all + #- awk -F, '{ instructions += $4 + $5; covered += $5 } END { print "===============================================\nCoverage Results:\n\n", covered, " / ", instructions, " instructions covered"; print "Total", 100*covered/instructions, "% covered\n==\n===============================================" }' out/coverage/site/jacoco.csv + artifacts: + when: on_success + expire_in: 3 day + paths: + - out/ant/coverage/site + - out/ant/package + reports: + junit: out/ant/junit/TEST-*.xml + diff --git a/.project b/.project new file mode 100644 index 0000000..0536c47 --- /dev/null +++ b/.project @@ -0,0 +1,35 @@ + + + atriasoft-reggol + + + atriasoft-reggol + + + + org.eclipse.jdt.core.javabuilder + + + + + net.sf.eclipsecs.core.CheckstyleBuilder + + + + + + org.eclipse.jdt.core.javanature + net.sf.eclipsecs.core.CheckstyleNature + + + + 1664629886087 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + 1.0-name-matches-false-true-node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/CheckStyle.xml b/CheckStyle.xml new file mode 100755 index 0000000..d68aedd --- /dev/null +++ b/CheckStyle.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Formatter.xml b/Formatter.xml new file mode 100644 index 0000000..79dcbb8 --- /dev/null +++ b/Formatter.xml @@ -0,0 +1,366 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/GLD_reggol-test.json b/GLD_reggol-test.json new file mode 100644 index 0000000..b9789c0 --- /dev/null +++ b/GLD_reggol-test.json @@ -0,0 +1,27 @@ +{ + "type":"BINARY", + "sub-type":"TEST", + "group-id":"org.atriasoft", + "description":"Simple java reggol test ", + "license":"MPL-2", + "license-file":"file://LICENSE", + "maintainer":"file://authors.txt", + "author":"file://authors.txt", + "version":"file://version.txt", + + "source": [ + "test/src/test/atriasoft/reggol/Log2.java", + "test/src/test/atriasoft/reggol/TestBasicLog.java", + "test/src/test/atriasoft/reggol/Log.java" + ], + "path":[ + "test/src/" + ], + "compilation-version": { + "java": 18 + }, + "dependency": [ + "reggol", + "junit-jupiter-api" + ] +} diff --git a/GLD_reggol.json b/GLD_reggol.json new file mode 100644 index 0000000..8f5842f --- /dev/null +++ b/GLD_reggol.json @@ -0,0 +1,24 @@ +{ + "type":"LIBRARY", + "group-id":"org.atriasoft", + "description":"Simple java logger", + "license":"MPL-2", + "license-file":"file://LICENSE", + "maintainer":"file://authors.txt", + "author":"file://authors.txt", + "version":"file://version.txt", + + "source": [ + "src/module-info.java", + "src/io/atriasoft/reggol/LoggerLocal.java", + "src/io/atriasoft/reggol/internal/Log.java", + "src/io/atriasoft/reggol/Logger.java", + "src/io/atriasoft/reggol/LogLevel.java" + ], + "path":[ + "src/" + ], + "compilation-version": { + "java": 18 + } +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a612ad9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/author.txt b/author.txt new file mode 100644 index 0000000..44ea56f --- /dev/null +++ b/author.txt @@ -0,0 +1 @@ +Edouard DUPIN diff --git a/doc/doc_01_overview.md b/doc/doc_01_overview.md new file mode 100644 index 0000000..4a59433 --- /dev/null +++ b/doc/doc_01_overview.md @@ -0,0 +1,6 @@ +atriasoft-reggol Overview +========================= + + +TBD + diff --git a/doc/tutorial_01_create_library_logger.md b/doc/tutorial_01_create_library_logger.md new file mode 100644 index 0000000..0c46ef1 --- /dev/null +++ b/doc/tutorial_01_create_library_logger.md @@ -0,0 +1,97 @@ +Create your own Logger +====================== + +Import the Module +================= + +in the file ```module-info.java``` add the require of the module + + +```{.java} +requires transitive org.atriasoft.reggol; +``` + +Create your local interface +=========================== + +Create a package (that must not be exported): ```src/xxx/yyy/internal/``` + +Add a Class: ```Log.java``` + +with: + +```java +package xxx.yyy.internal; + +import org.atriasoft.reggol.LogLevel; +import org.atriasoft.reggol.Logger; + +public class Log { + private static final String LIB_NAME = "xxx.yyy"; + private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME); + private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL); + private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR); + private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING); + private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO); + private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG); + private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE); + private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO); + private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT); + + private Log() {} + + public static void print(String data) { + if (PRINT_PRINT) + Logger.print(LIB_NAME_DRAW, data); + } + + public static void critical(String data) { + if (PRINT_CRITICAL) + Logger.critical(LIB_NAME_DRAW, data); + } + + public static void error(String data) { + if (PRINT_ERROR) + Logger.error(LIB_NAME_DRAW, data); + } + + public static void warning(String data) { + if (PRINT_WARNING) + Logger.warning(LIB_NAME_DRAW, data); + } + + public static void info(String data) { + if (PRINT_INFO) + Logger.info(LIB_NAME_DRAW, data); + } + + public static void debug(String data) { + if (PRINT_DEBUG) + Logger.debug(LIB_NAME_DRAW, data); + } + + public static void verbose(String data) { + if (PRINT_VERBOSE) + Logger.verbose(LIB_NAME_DRAW, data); + } + + public static void todo(String data) { + if (PRINT_TODO) + Logger.todo(LIB_NAME_DRAW, data); + } +} + +``` + + +Generate some Logs: +=================== + + +```{.java} +final int plop = 51615; +Log.info("ma super ligne de Log " + plop); +Log.error("a beautifull error); +``` + + diff --git a/doc/tutorial_02_control_logger.md b/doc/tutorial_02_control_logger.md new file mode 100644 index 0000000..7abbdbe --- /dev/null +++ b/doc/tutorial_02_control_logger.md @@ -0,0 +1,28 @@ +Control the log level +===================== + +Change the Level of the Log: +============================ + +With the system property: + + - ```reggol.level```: Change the level of the log display: + - critical + - error + - warning + - info + - debug + - verbose; + - ```reggol.color```: Change the color of the log (true/false) + + +The second solution depend of the application capability (check --help) + + +Log in color information +======================== + +If the color is enable thing to change the default console of eclipse, to support the ascii color code. + + + diff --git a/lutin_org-atriasoft-reggol.py b/lutin_org-atriasoft-reggol.py new file mode 100644 index 0000000..8661b0b --- /dev/null +++ b/lutin_org-atriasoft-reggol.py @@ -0,0 +1,44 @@ +#!/usr/bin/python +import realog.debug as debug +import lutin.tools as tools +import realog.debug as debug +import lutin.image as image +import os +import lutin.multiprocess as lutinMultiprocess + + +def get_type(): + return "LIBRARY_DYNAMIC" + +def get_desc(): + return "Scenarium reggol" + +def get_licence(): + return "MPL-2" + +def get_compagny_type(): + return "com" + +def get_compagny_name(): + return "atriasoft" + +#def get_maintainer(): +# return "authors.txt" + +#def get_version(): +# return "version.txt" + +def configure(target, my_module): + + my_module.add_src_file([ + 'src/module-info.java', + 'src/io/atriasoft/reggol/LogLevel.java', + 'src/io/atriasoft/reggol/Logger.java', + 'src/io/atriasoft/reggol/internal/Log.java', + ]) + my_module.add_path('src/', type='java') + + my_module.add_flag('java', "RELEASE_15_PREVIEW"); + + return True + diff --git a/menu.json b/menu.json new file mode 100644 index 0000000..c891b9b --- /dev/null +++ b/menu.json @@ -0,0 +1,17 @@ +{ + "documentation": [ + { + "title": "global overview", + "page": "doc/doc_01_overview.md" + } + ], + "tutorial": [ + { + "title": "Create your own logger", + "page": "doc/tutorial_01_create_library_logger.md" + },{ + "title": "Control the logger", + "page": "doc/tutorial_02_control_logger.md" + } + ] +} \ No newline at end of file diff --git a/src/module-info.java b/src/module-info.java new file mode 100644 index 0000000..954951a --- /dev/null +++ b/src/module-info.java @@ -0,0 +1,7 @@ +/** Basic module interface. + * + * @author Edouard DUPIN */ + +open module org.atriasoft.reggol { + exports org.atriasoft.reggol; +} diff --git a/src/org/atriasoft/reggol/LogLevel.java b/src/org/atriasoft/reggol/LogLevel.java new file mode 100644 index 0000000..3185881 --- /dev/null +++ b/src/org/atriasoft/reggol/LogLevel.java @@ -0,0 +1,25 @@ +package org.atriasoft.reggol; + +public enum LogLevel { + NONE(-3), PRINT(-2), TODO(-1), CRITICAL(0), ERROR(1), WARNING(2), INFO(3), DEBUG(4), VERBOSE(5); + + public final int value; + + LogLevel(int value) { + this.value = value; + } + + public static LogLevel fromString(String logLevel) { + String value = logLevel.toUpperCase(); + LogLevel[] values = LogLevel.values(); + for (LogLevel elem : values) + if (value.contentEquals(elem.name()) || value.contentEquals(String.valueOf(elem.value))) + return elem; + return ERROR; + } + + public boolean isLessEqual(LogLevel other) { + return this.value <= other.value; + } + +} diff --git a/src/org/atriasoft/reggol/Logger.java b/src/org/atriasoft/reggol/Logger.java new file mode 100644 index 0000000..8018dd4 --- /dev/null +++ b/src/org/atriasoft/reggol/Logger.java @@ -0,0 +1,488 @@ +/******************************************************************************* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * Contributors: + * Revilloud Marc - initial API and implementation + ******************************************************************************/ +package org.atriasoft.reggol; + +import java.nio.CharBuffer; +import java.util.HashMap; +import java.util.List; + +import org.atriasoft.reggol.internal.Log; + +@SuppressWarnings("unused") +public class Logger { + static class WrapInt { + public int value; + + public WrapInt(final int val) { + this.value = val; + } + } + + // background colors + private static final String BASH_COLOR_BG_BLACK = "\033[40m"; + + private static final String BASH_COLOR_BG_BLUE = "\033[44m"; + + private static final String BASH_COLOR_BG_CYAN = "\033[46m"; + private static final String BASH_COLOR_BG_GREEN = "\033[42m"; + private static final String BASH_COLOR_BG_MAGENTA = "\033[45m"; + private static final String BASH_COLOR_BG_RED = "\033[41m"; + private static final String BASH_COLOR_BG_WHITE = "\033[47m"; + private static final String BASH_COLOR_BG_YELLOW = "\033[43m"; + // regular colors + private static final String BASH_COLOR_BLACK = "\033[0;30m"; + private static final String BASH_COLOR_BLUE = "\033[0;34m"; + // emphasized (bolded) colors + private static final String BASH_COLOR_BOLD_BLACK = "\033[1;30m"; + private static final String BASH_COLOR_BOLD_BLUE = "\033[1;34m"; + private static final String BASH_COLOR_BOLD_CYAN = "\033[1;36m"; + private static final String BASH_COLOR_BOLD_GREEN = "\033[1;32m"; + private static final String BASH_COLOR_BOLD_MAGENTA = "\033[1;35m"; + private static final String BASH_COLOR_BOLD_RED = "\033[1;31m"; + private static final String BASH_COLOR_BOLD_WHITE = "\033[1;37m"; + private static final String BASH_COLOR_BOLD_YELLOW = "\033[1;33m"; + private static final String BASH_COLOR_CYAN = "\033[0;36m"; + private static final String BASH_COLOR_GREEN = "\033[0;32m"; + private static final String BASH_COLOR_MAGENTA = "\033[0;35m"; + // Return to the normal color settings + private static final String BASH_COLOR_NORMAL = "\033[0m"; + private static final String BASH_COLOR_RED = "\033[0;31m"; + private static final String BASH_COLOR_WHITE = "\033[0;37m"; + private static final String BASH_COLOR_YELLOW = "\033[0;33m"; + // go to the Top of bash + private static final String BASH_GO_TOP = "\033[0;0f"; + static boolean criticalOccured = false; + + private static LogLevel defaultLevel = LogLevel.INFO; + private static boolean haveClassName = false; + // to enable color, you need to install in eclipse the plug-in "ANSI escape in console" + private static boolean haveColor = true; + private static boolean haveFileName = true; + private static boolean haveLibName = true; + private static boolean haveLineNumber = true; + private static boolean haveThreadId = true; + private static boolean haveThreadName = false; + private static boolean isInit = false; + private static HashMap logLevels = new HashMap<>(); + private static WrapInt sizeClassName = new WrapInt(25); + private static WrapInt sizeFileName = new WrapInt(15); + private static WrapInt sizeLibName = new WrapInt(0); + private static WrapInt sizeLineNumber = new WrapInt(3); + private static WrapInt sizeThreadId = new WrapInt(2); + private static WrapInt sizeThreadName = new WrapInt(10); + static { + // Load system color state + String value = System.getProperty("reggol.color"); + if (value != null) { + if (value.contentEquals("true") || value.contentEquals("1")) { + Logger.haveColor = true; + } else if (value.contentEquals("false") || value.contentEquals("0")) { + Logger.haveColor = false; + } else { + System.out.println("error in color state '" + value + "' ==> not in range [true, false, 0, 1]"); + } + } + + // Load system debug level + value = System.getProperty("reggol.level"); + if (value != null) { + final LogLevel level = LogLevel.fromString(value); + System.out.println("Change global level at " + value + " ==> " + level); + Logger.defaultLevel = level; + } + } + + private static String addGeneric(final String level, final String libName) { + final StringBuilder out = new StringBuilder().append(level); + out.append(Logger.printElement("", "", Logger.haveLibName, libName, Logger.sizeLibName)); + out.append(Logger.printElement(" | ", "", Logger.haveThreadId, Long.toString(Thread.currentThread().getId()), Logger.sizeThreadId)); + out.append(Logger.printElement(" | ", "", Logger.haveThreadName, Thread.currentThread().getName(), Logger.sizeThreadName)); + if (Logger.haveClassName || Logger.haveFileName || Logger.haveLineNumber) { + final StackTraceElement callElem = Logger.getCallerElement(); + out.append(Logger.printElementLeft(" | l=", "", Logger.haveLineNumber, Long.toString(callElem.getLineNumber()), Logger.sizeLineNumber)); + out.append(Logger.printElement(" | ", "", Logger.haveClassName, callElem.getClassName(), Logger.sizeClassName)); + out.append(Logger.printElement(" | ", "", Logger.haveFileName, callElem.getFileName(), Logger.sizeFileName)); + } + return out.toString(); + } + + /** + * Replace all the values {} with the associated value in the parameters + * @param data A generic string composed with "{}" element that will be replace. + * @param values List of all element to add in the string. + * @return a string with all the transformed data. + */ + public static String concatenate(final String data, final Object... values) { + final String[] cliped = data.split("\\{\\}"); + final StringBuilder out = new StringBuilder(); + final int nbElement = Math.max(values.length, cliped.length); + for (int iii = 0; iii < nbElement; iii++) { + if (iii < cliped.length) { + out.append(cliped[iii]); + } else { + out.append(" ?? "); + } + if (iii < values.length) { + if (values[iii] == null) { + out.append("null"); + } else { + out.append(values[iii].toString()); + } + } else if (cliped.length - 1 != values.length) { + out.append("{}"); + } + } + return out.toString(); + } + + public static void critical(final String libName, final String data) { + criticalInternal(libName, data); + } + + public static void critical(final String libName, final String data, final Object... values) { + if (values.length == 0) { + criticalInternal(libName, data); + } else { + critical(libName, concatenate(data, values)); + } + } + + private static void criticalInternal(final String libName, final String data) { + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_BOLD_RED); + } + System.out.println(Logger.addGeneric("[C] ", libName) + " | " + data); + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_NORMAL); + } + System.out.flush(); + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_YELLOW); + } + for (final StackTraceElement ste : Thread.currentThread().getStackTrace()) { + System.out.println(ste); + } + System.out.print(Logger.BASH_COLOR_NORMAL); + System.out.flush(); + Logger.criticalOccured = true; + System.exit(-50); + } + + public static void debug(final String libName, final String data) { + debugInternal(libName, data); + } + + public static void debug(final String libName, final String data, final Object... values) { + if (values.length == 0) { + debugInternal(libName, data); + } else { + debugInternal(libName, concatenate(data, values)); + } + } + + public static void debugInternal(final String libName, final String data) { + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_YELLOW); + } + System.out.println(Logger.addGeneric("[D] ", libName) + " | " + data); + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_NORMAL); + } + } + + public static void displayBackTrace(final String libNameDraw) { + final StackTraceElement[] list = Thread.currentThread().getStackTrace(); + Logger.error(libNameDraw, "Display Stacktrace :"); + for (int iii = 0; iii < list.length; iii++) { + Logger.error(libNameDraw, " - " + list[iii]); + } + } + + public static void error(final String libName, final String data) { + errorInternal(libName, data); + } + + public static void error(final String libName, final String data, final Object... values) { + if (values.length == 0) { + errorInternal(libName, data); + } else { + errorInternal(libName, concatenate(data, values)); + } + } + + private static void errorInternal(final String libName, final String data) { + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_RED); + } + System.out.println(Logger.addGeneric("[E] ", libName) + " | " + data); + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_NORMAL); + } + } + + private static StackTraceElement getCallerElement() { + if (Thread.currentThread().getStackTrace().length > 6) { + return Thread.currentThread().getStackTrace()[6]; + } + if (Thread.currentThread().getStackTrace().length > 5) { + return Thread.currentThread().getStackTrace()[5]; + } + if (Thread.currentThread().getStackTrace().length > 4) { + return Thread.currentThread().getStackTrace()[4]; + } + if (Thread.currentThread().getStackTrace().length > 3) { + return Thread.currentThread().getStackTrace()[3]; + } + if (Thread.currentThread().getStackTrace().length > 2) { + return Thread.currentThread().getStackTrace()[2]; + } + if (Thread.currentThread().getStackTrace().length > 1) { + return Thread.currentThread().getStackTrace()[1]; + } + return Thread.currentThread().getStackTrace()[0]; + } + + /** This function permit to get the printable string to print in the log element (select here the number of char to print) + * @param libName Name of the library + * @return string to set in the reggol information */ + public static String getDrawableName(final String libName) { + return libName; // String.format("%1$" + 15 + "s", libName); + } + + public static boolean getNeedPrint(final String libName, final LogLevel level) { + final LogLevel reference = Logger.logLevels.get(libName); + if (reference == null) { + return level.isLessEqual(Logger.defaultLevel); + } + return level.isLessEqual(reference); + } + + public static void info(final String libName, final String data) { + infoInternal(libName, data); + } + + public static void info(final String libName, final String data, final Object... values) { + if (values.length == 0) { + infoInternal(libName, data); + } else { + infoInternal(libName, concatenate(data, values)); + } + } + + private static void infoInternal(final String libName, final String data) { + final StackTraceElement callElem = Logger.getCallerElement(); + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_CYAN); + } + System.out.println(Logger.addGeneric("[I] ", libName) + " | " + data); + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_NORMAL); + } + } + + /** Initialize the library with generic argument in command line + * @param args list of argument that are filtered after */ + public static void init(final List args) { + if (Logger.isInit) { + return; + } + Logger.isInit = true; + for (int iii = 0; iii < args.size(); ++iii) { + final String data = args.get(iii); + if (data.startsWith("--log-level=")) { + final String value = data.substring(12); + final LogLevel level = LogLevel.fromString(value); + System.out.println("Change global level at " + value + " ==> " + level); + Logger.defaultLevel = level; + } else if (data.contentEquals("--log-color")) { + Logger.haveColor = true; + } else if (data.contentEquals("--log-no-color")) { + Logger.haveColor = false; + } else if (data.startsWith("--log-lib=")) { + final String value = data.substring(10); + String[] values = value.split("/"); + if (values.length != 2) { + values = value.split(":"); + if (values.length != 2) { + values = value.split("\\+"); + if (values.length != 2) { + System.err.println("Can not set the --reggol-lib= with value='" + value + "' not formated name:X or name/X or name+X"); + continue; + } + } + } + System.out.println("Change level of '" + values[0] + "' at " + LogLevel.fromString(values[1])); + Logger.logLevels.put(values[0], LogLevel.fromString(values[1])); + } + } + // Clear all reggol elements. + int iii = 0; + while (iii < args.size()) { + final String data = args.get(iii); + if (data.startsWith("--log")) { + args.remove(iii); + } else { + iii++; + } + } + } + + public static boolean isCriticalOccured() { + return Logger.criticalOccured; + } + + public static void print(final String libName, final String data) { + System.out.println(data); + //printInternal(libName, data); + } + + public static void print(final String libName, final String data, final Object... values) { + if (values.length == 0) { + System.out.println(data); + //printInternal(libName, data); + } else { + System.out.println(concatenate(data, values)); + //printInternal(libName, concatenate(data, values)); + } + } + + private static String printElement(final String separator, final String separatorEnd, final boolean isActive, String data, final WrapInt size) { + if (!isActive) { + return ""; + } + if (data == null) { + data = "???"; + } + final int stringSize = data.length(); + if (size.value < stringSize) { + size.value = stringSize; + } + final int rest = size.value - stringSize; + return separator + data + Logger.spaces(rest) + separatorEnd; + } + + private static String printElementLeft(final String separator, final String separatorEnd, final boolean isActive, String data, final WrapInt size) { + if (!isActive) { + return ""; + } + if (data == null) { + data = "???"; + } + final int stringSize = data.length(); + if (size.value < stringSize) { + size.value = stringSize; + } + final int rest = size.value - stringSize; + return separator + Logger.spaces(rest) + data + separatorEnd; + } + + private static void printInternal(final String libName, final String data) { + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_WHITE); + } + System.out.println(Logger.addGeneric("[P] ", libName) + " | " + data); + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_NORMAL); + } + System.out.flush(); + } + + public static String spaces(final int spaces) { + return CharBuffer.allocate(spaces).toString().replace('\0', ' '); + } + + public static void todo(final String libName, final String data) { + todoInternal(libName, data); + } + + public static void todo(final String libName, final String data, final Object... values) { + if (values.length == 0) { + todoInternal(libName, data); + } else { + todoInternal(libName, concatenate(data, values)); + } + } + + private static void todoInternal(final String libName, final String data) { + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_WHITE); + } + System.out.println(Logger.addGeneric("[TODO] ", libName) + " | " + data); + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_NORMAL); + } + } + + public static void usage() { + Log.print(" [log]: Log session interface"); + Log.print(" --log-level= Change the default log level (set all Log level):"); + Log.print(" -3/none: debug None"); + Log.print(" -2/print: debug Print"); + Log.print(" -1/todo: debug Todo"); + Log.print(" 0/critical: debug Critical (default)"); + Log.print(" 1/error: debug Error"); + Log.print(" 2/warning: debug Warning"); + Log.print(" 3/info: debug Info"); + Log.print(" 4/debug: debug Debug"); + Log.print(" 5/verbose: debug Verbose"); + Log.print(" --log-lib=name:X Set a library specific level:"); + Log.print(" name Name of the library"); + Log.print(" X Log level to set [0..6]"); + Log.print(" !note!: ':' can be replace with '/' or '+'"); + Log.print(" --log-color Enable color in log"); + Log.print(" --log-no-color Disable color in log (default)"); + Log.print(""); + } + + public static void verbose(final String libName, final String data) { + verboseInternal(libName, data); + } + + public static void verbose(final String libName, final String data, final Object... values) { + if (values.length == 0) { + verboseInternal(libName, data); + } else { + verboseInternal(libName, concatenate(data, values)); + } + } + + private static void verboseInternal(final String libName, final String data) { + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_WHITE); + } + System.out.println(Logger.addGeneric("[V] ", libName) + " | " + data); + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_NORMAL); + } + } + + public static void warning(final String libName, final String data) { + warningInternal(libName, data); + } + + public static void warning(final String libName, final String data, final Object... values) { + if (values.length == 0) { + warningInternal(libName, data); + } else { + warningInternal(libName, concatenate(data, values)); + } + } + + private static void warningInternal(final String libName, final String data) { + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_MAGENTA); + } + System.out.println(Logger.addGeneric("[W] ", libName) + " | " + data); + if (Logger.haveColor) { + System.out.print(Logger.BASH_COLOR_NORMAL); + } + } + + private Logger() {} +} diff --git a/src/org/atriasoft/reggol/LoggerLocal.java b/src/org/atriasoft/reggol/LoggerLocal.java new file mode 100644 index 0000000..fd79059 --- /dev/null +++ b/src/org/atriasoft/reggol/LoggerLocal.java @@ -0,0 +1,130 @@ +package org.atriasoft.reggol; + +public class LoggerLocal { + private final String className; + private final String libraryName; + private final String libraryNameDraw; + private final boolean force; + private final boolean printCritical; + private final boolean printDebug; + private final boolean printError; + private final boolean printInfo; + private final boolean printPrint; + private final boolean printTodo; + private final boolean printVerbose; + private final boolean printWarning; + + public LoggerLocal(String libraryName, final Class clazz) { + this(libraryName, clazz, false); + } + + public LoggerLocal(String libraryName, final Class clazz, boolean force) { + this.force = force; + this.libraryName = libraryName; + this.className = clazz.getCanonicalName(); + this.libraryNameDraw = Logger.getDrawableName(this.libraryName); + this.printCritical = Logger.getNeedPrint(this.libraryName, LogLevel.CRITICAL); + this.printDebug = Logger.getNeedPrint(this.libraryName, LogLevel.DEBUG); + this.printError = Logger.getNeedPrint(this.libraryName, LogLevel.ERROR); + this.printInfo = Logger.getNeedPrint(this.libraryName, LogLevel.INFO); + this.printPrint = Logger.getNeedPrint(this.libraryName, LogLevel.PRINT); + this.printTodo = Logger.getNeedPrint(this.libraryName, LogLevel.TODO); + this.printVerbose = Logger.getNeedPrint(this.libraryName, LogLevel.VERBOSE); + this.printWarning = Logger.getNeedPrint(this.libraryName, LogLevel.WARNING); + } + + public void critical(final String data) { + if (this.printCritical || this.force) { + Logger.critical(this.libraryNameDraw, data); + } + } + + public void critical(final String data, Object... values) { + if (this.printCritical || this.force) { + Logger.critical(this.libraryNameDraw, data, values); + } + } + + public void debug(final String data) { + if (this.printDebug || this.force) { + Logger.debug(this.libraryNameDraw, data); + } + } + + public void debug(final String data, Object... values) { + if (this.printDebug || this.force) { + Logger.debug(this.libraryNameDraw, data, values); + } + } + + public void displayBackTrace() { + // TODO Auto-generated method stub + } + + public void error(final String data) { + if (this.printError || this.force) { + Logger.error(this.libraryNameDraw, data); + } + } + + public void error(final String data, Object... values) { + if (this.printError || this.force) { + Logger.error(this.libraryNameDraw, data, values); + } + } + + public void info(final String data) { + if (this.printInfo || this.force) { + Logger.info(this.libraryNameDraw, data); + } + } + + public void info(final String data, Object... values) { + if (this.printInfo || this.force) { + Logger.info(this.libraryNameDraw, data, values); + } + } + + public void print(final String data) { + if (this.printPrint || this.force) { + Logger.print(this.libraryNameDraw, data); + } + } + + public void print(final String data, Object... values) { + if (this.printPrint || this.force) { + Logger.print(this.libraryNameDraw, data, values); + } + } + + public void todo(final String data) { + if (this.printTodo || this.force) { + Logger.todo(this.libraryNameDraw, data); + } + } + + public void todo(final String data, Object... values) { + if (this.printTodo || this.force) { + Logger.todo(this.libraryNameDraw, data, values); + } + } + + public void verbose(final String data) { + if (this.printVerbose || this.force) { + Logger.verbose(this.libraryNameDraw, data); + } + } + + public void warning(final String data) { + if (this.printWarning || this.force) { + Logger.warning(this.libraryNameDraw, data); + } + } + + public void warning(final String data, Object... values) { + if (this.printWarning || this.force) { + Logger.warning(this.libraryNameDraw, data, values); + } + } + +} diff --git a/src/org/atriasoft/reggol/internal/Log.java b/src/org/atriasoft/reggol/internal/Log.java new file mode 100644 index 0000000..bf6ca7f --- /dev/null +++ b/src/org/atriasoft/reggol/internal/Log.java @@ -0,0 +1,60 @@ +package org.atriasoft.reggol.internal; + +import org.atriasoft.reggol.LogLevel; +import org.atriasoft.reggol.Logger; + +public class Log { + private static final String LIB_NAME = "reggol"; + private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME); + private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL); + private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR); + private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING); + private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO); + private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG); + private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE); + private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO); + private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT); + + private Log() {} + + public static void print(String data) { + if (PRINT_PRINT) + Logger.print(LIB_NAME_DRAW, data); + } + + public static void todo(String data) { + if (PRINT_TODO) + Logger.todo(LIB_NAME_DRAW, data); + } + + public static void critical(String data) { + if (PRINT_CRITICAL) + Logger.critical(LIB_NAME_DRAW, data); + } + + public static void error(String data) { + if (PRINT_ERROR) + Logger.error(LIB_NAME_DRAW, data); + } + + public static void warning(String data) { + if (PRINT_WARNING) + Logger.warning(LIB_NAME_DRAW, data); + } + + public static void info(String data) { + if (PRINT_INFO) + Logger.info(LIB_NAME_DRAW, data); + } + + public static void debug(String data) { + if (PRINT_DEBUG) + Logger.debug(LIB_NAME_DRAW, data); + } + + public static void verbose(String data) { + if (PRINT_VERBOSE) + Logger.verbose(LIB_NAME_DRAW, data); + } + +} diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/test/src/test/atriasoft/reggol/.keep b/test/src/test/atriasoft/reggol/.keep new file mode 100644 index 0000000..e69de29 diff --git a/test/src/test/atriasoft/reggol/Log.java b/test/src/test/atriasoft/reggol/Log.java new file mode 100644 index 0000000..76192d2 --- /dev/null +++ b/test/src/test/atriasoft/reggol/Log.java @@ -0,0 +1,59 @@ +package test.atriasoft.reggol; + +import org.atriasoft.reggol.LogLevel; +import org.atriasoft.reggol.Logger; + +public class Log { + private static final String LIB_NAME = "sc-log-test"; + private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME); + private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL); + private static final boolean PRINT_ERROR = Logger.getNeedPrint(LIB_NAME, LogLevel.ERROR); + private static final boolean PRINT_WARNING = Logger.getNeedPrint(LIB_NAME, LogLevel.WARNING); + private static final boolean PRINT_INFO = Logger.getNeedPrint(LIB_NAME, LogLevel.INFO); + private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG); + private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(LIB_NAME, LogLevel.VERBOSE); + private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO); + private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT); + + private Log() {} + + public static void print(String data) { + if (PRINT_PRINT) + Logger.print(LIB_NAME_DRAW, data); + } + + public static void critical(String data) { + if (PRINT_CRITICAL) + Logger.critical(LIB_NAME_DRAW, data); + } + + public static void error(String data) { + if (PRINT_ERROR) + Logger.error(LIB_NAME_DRAW, data); + } + + public static void warning(String data) { + if (PRINT_WARNING) + Logger.warning(LIB_NAME_DRAW, data); + } + + public static void info(String data) { + if (PRINT_INFO) + Logger.info(LIB_NAME_DRAW, data); + } + + public static void debug(String data) { + if (PRINT_DEBUG) + Logger.debug(LIB_NAME_DRAW, data); + } + + public static void verbose(String data) { + if (PRINT_VERBOSE) + Logger.verbose(LIB_NAME_DRAW, data); + } + + public static void todo(String data) { + if (PRINT_TODO) + Logger.todo(LIB_NAME_DRAW, data); + } +} diff --git a/test/src/test/atriasoft/reggol/Log2.java b/test/src/test/atriasoft/reggol/Log2.java new file mode 100644 index 0000000..74cf75f --- /dev/null +++ b/test/src/test/atriasoft/reggol/Log2.java @@ -0,0 +1,18 @@ +package test.atriasoft.reggol; + +import org.atriasoft.reggol.LogLevel; +import org.atriasoft.reggol.Logger; + +public class Log2 { + private static final String LIB_NAME = "sc-log-test-2"; + private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME); + private static final boolean PRINT_DEBUG = Logger.getNeedPrint(LIB_NAME, LogLevel.DEBUG); + + private Log2() {} + + public static void debug(String data) { + if (PRINT_DEBUG) + Logger.debug(LIB_NAME_DRAW, data); + } + +} diff --git a/test/src/test/atriasoft/reggol/TestBasicLog.java b/test/src/test/atriasoft/reggol/TestBasicLog.java new file mode 100644 index 0000000..ea09931 --- /dev/null +++ b/test/src/test/atriasoft/reggol/TestBasicLog.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * Contributors: + * Revilloud Marc - initial API and implementation + ******************************************************************************/ +package test.atriasoft.reggol; + +import java.util.ArrayList; +import java.util.List; + +import org.atriasoft.reggol.Logger; + +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; + +@TestMethodOrder(OrderAnnotation.class) +public class TestBasicLog { + + @Test + @Order(1) + public void aaFirstInitialisation() { + List args = new ArrayList<>(); + args.add("--log-level=999"); + args.add("--log-level=1"); + args.add("--log-no-color"); + args.add("--log-color"); + args.add("--log-lib=sc-log-test+6"); + args.add("--log-lib=sc-log-test/6"); + args.add("--log-lib=sc-log-test:6"); + args.add("--log-lib=sc-log-test:verbose"); + args.add("--log-lib=sc-log-test2+3"); + args.add("--log-lib=sc-log-test"); + args.add("--log-with-stupid-parameter=sdkfjsqdlkf"); + args.add("--help"); + Logger.init(args); + } + + @Test + @Order(2) + public void bbSecondInitialisation() { + List args = new ArrayList<>(); + Logger.init(args); + } + + @Test + @Order(3) + public void ccBasicLogCall() { + Log.print("Simple print"); + Log.todo("Simple todo"); + Log.error("Simple error"); + Log.warning("Simple warning"); + Log.info("Simple info"); + Log.debug("Simple debug"); + Log.verbose("Simple verbose"); + } + + // TODO REFACTO REMOVE this and set it in the Test of the reggol. + public static String getAAAAAAA(int dfsdf) { + int hhh = 0; + for (int kkk = 0; kkk < dfsdf; kkk++) + for (int iii = 0; iii < 10000; iii++) + for (int jjj = 0; jjj < 100000; jjj++) + for (int lll = 0; lll < 100000; lll++) + hhh++; + return "kkk" + hhh; + } + + public static void testLog() { + Log.print("test direct [START]"); + // test de 10 secondes contre 0.0?? second quand le niveau n'est pas assez grand ... + long timeStart = System.currentTimeMillis(); + for (int iii = 0; iii < 100000000; iii++) + Log2.debug("test direct"); + long timeStop = System.currentTimeMillis(); + Log.print("test direct [END] : " + timeStart + " to " + timeStop + " ==> delta=" + (timeStop - timeStart)); + Log.print("test concat [START]"); + // C'est très long dans les 2 cas ... + timeStart = System.currentTimeMillis(); + for (int iii = 0; iii < 6; iii++) + Log2.debug("test concat: non fonctionnel, il applelle le get a chaque log ... " + getAAAAAAA(iii)); + timeStop = System.currentTimeMillis(); + Log.print("test concat [END] : " + timeStart + " to " + timeStop + " ==> delta=" + (timeStop - timeStart)); + } + + @Test + @Order(4) + public void ddTestSimpleLog() { + testLog(); + } + + @Test + @Order(4) + public void eeUsage() { + Logger.usage(); + } + +} diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..c70836c --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.9.0-dev