├── .github └── workflows │ ├── build.yml │ ├── codeql.yml │ └── test.yml ├── .gitignore ├── LICENCE ├── Optilog.png ├── Profile_main.sdt ├── README-en.md ├── README.md ├── build.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src ├── main └── java │ ├── com │ └── optilog │ │ ├── log │ │ ├── Appender.java │ │ ├── IOptilog.java │ │ ├── Level.java │ │ ├── LevelBuild.java │ │ ├── Log.java │ │ ├── LogEvent.java │ │ ├── LogMark.java │ │ ├── Logger.java │ │ ├── Optilog.java │ │ ├── Packing.java │ │ ├── Send.java │ │ ├── client │ │ │ └── Client.java │ │ ├── console │ │ │ ├── Console.java │ │ │ └── ZipLog.java │ │ └── jdbc │ │ │ └── MySQL.java │ │ ├── setting │ │ ├── JsonSettingBean.java │ │ ├── JsonSettings.java │ │ ├── PropSettings.java │ │ ├── SettingFiles.java │ │ ├── XmlSettingBean.java │ │ ├── XmlSettings.java │ │ └── YamlSettings.java │ │ └── util │ │ ├── LambdaExecute.java │ │ ├── OnlyInInit.java │ │ ├── OnlyInLog.java │ │ ├── Util.java │ │ ├── exception │ │ ├── ConfigureException.java │ │ ├── InvalidCommandException.java │ │ └── OptilogException.java │ │ └── tools │ │ ├── Assert.java │ │ └── LocalField.java │ └── module-info.java └── test ├── java └── com │ └── optilog │ ├── JsonClassPathOptilogTest.java │ ├── JsonPathOptilogTest.java │ ├── PerformanceTester.java │ ├── PropertiesClassPathOptilogTest.java │ ├── PropertiesPathOptilogTest.java │ ├── XmlClassPathOptilogTest.java │ ├── XmlPathOptilogTest.java │ ├── YamlClassPathOptilogTest.java │ └── YamlPathOptilogTest.java └── resources ├── Settings.json ├── Settings.properties ├── Settings.xml └── Settings.yaml /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | on: [ pull_request, push ] 3 | 4 | jobs: 5 | build: 6 | strategy: 7 | matrix: 8 | java: [ 11, 17 ] 9 | os: [ ubuntu-latest, windows-latest, macos-latest ] 10 | 11 | runs-on: ${{ matrix.os }} 12 | steps: 13 | - name: checkout repository 14 | uses: actions/checkout@v2 15 | - name: validate gradle wrapper 16 | uses: gradle/wrapper-validation-action@v1 17 | - name: setup jdk ${{ matrix.java }} 18 | uses: actions/setup-java@v2 19 | with: 20 | distribution: adopt 21 | java-version: ${{ matrix.java }} 22 | - name: prepare gradle wrapper 23 | if: ${{ runner.os != 'Windows' }} 24 | run: chmod +x ./gradlew 25 | - name: clean 26 | run: ./gradlew clean 27 | - name: build 28 | run: ./gradlew build 29 | - name: capture build artifacts 30 | if: ${{ runner.os == 'Linux' && matrix.java == '17' }} 31 | uses: actions/upload-artifact@v2 32 | with: 33 | name: Artifacts 34 | path: build/libs/ 35 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ master ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ master ] 20 | schedule: 21 | - cron: '33 3 * * 1' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | runs-on: ubuntu-latest 27 | permissions: 28 | actions: read 29 | contents: read 30 | security-events: write 31 | 32 | strategy: 33 | fail-fast: false 34 | matrix: 35 | language: [ 'java' ] 36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 37 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 38 | 39 | steps: 40 | - name: Checkout repository 41 | uses: actions/checkout@v3 42 | 43 | # Initializes the CodeQL tools for scanning. 44 | - name: Initialize CodeQL 45 | uses: github/codeql-action/init@v2 46 | with: 47 | languages: ${{ matrix.language }} 48 | # If you wish to specify custom queries, you can do so here or in a config file. 49 | # By default, queries listed here will override any specified in a config file. 50 | # Prefix the list here with "+" to use these queries and those in the config file. 51 | 52 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 53 | # queries: security-extended,security-and-quality 54 | 55 | 56 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 57 | # If this step fails, then you should remove it and run the build manually (see below) 58 | - name: Autobuild 59 | uses: github/codeql-action/autobuild@v2 60 | 61 | # ℹ️ Command-line programs to run using the OS shell. 62 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 63 | 64 | # If the Autobuild fails above, remove it and uncomment the following three lines. 65 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 66 | 67 | # - run: | 68 | # echo "Run, Build Application using script" 69 | # ./location_of_script_within_repo/buildscript.sh 70 | 71 | - name: Perform CodeQL Analysis 72 | uses: github/codeql-action/analyze@v2 73 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | on: [ pull_request, push ] 3 | 4 | jobs: 5 | test: 6 | strategy: 7 | matrix: 8 | java: [ 11,17 ] 9 | os: [ ubuntu-latest, windows-latest, macos-latest ] 10 | 11 | runs-on: ${{ matrix.os }} 12 | 13 | steps: 14 | - name: checkout repository 15 | uses: actions/checkout@v2 16 | - name: validate gradle wrapper 17 | uses: gradle/wrapper-validation-action@v1 18 | - name: setup jdk ${{ matrix.java }} 19 | uses: actions/setup-java@v2 20 | with: 21 | distribution: adopt 22 | java-version: ${{ matrix.java }} 23 | - name: prepare gradle wrapper 24 | if: ${{ runner.os != 'Windows' }} 25 | run: chmod +x ./gradlew 26 | - name: clean 27 | run: ./gradlew clean 28 | - name: build 29 | run: ./gradlew build 30 | - name: clean log cache (Linux & macOS) 31 | if: ${{ runner.os != 'Windows' }} 32 | run: | 33 | rm -rf ./logs 34 | mkdir logs 35 | - name: clean log cache (Windows) 36 | if: ${{ runner.os == 'Windows' }} 37 | run: | 38 | if (Test-Path '.\logs') { 39 | rd /s /q .\logs 40 | } 41 | mkdir .\logs 42 | - name: test 43 | run: ./gradlew test 44 | - name: capture test log (Linux) 45 | if: ${{ matrix.java == '17' && runner.os == 'Linux' }} 46 | uses: actions/upload-artifact@v2 47 | with: 48 | name: test-log-linux-jdk17 49 | path: ./logs/ 50 | - name: capture test log (Linux) 51 | if: ${{ matrix.java == '11' && runner.os == 'Linux' }} 52 | uses: actions/upload-artifact@v2 53 | with: 54 | name: test-log-linux-jdk11 55 | path: ./logs/ 56 | - name: capture test log (macOS) 57 | if: ${{ matrix.java == '17' && runner.os == 'macOS' }} 58 | uses: actions/upload-artifact@v2 59 | with: 60 | name: test-log-macos-jdk17 61 | path: ./logs/ 62 | - name: capture test log (macOS) 63 | if: ${{ matrix.java == '11' && runner.os == 'macOS' }} 64 | uses: actions/upload-artifact@v2 65 | with: 66 | name: test-log-macos-jdk11 67 | path: ./logs/ 68 | - name: capture test log (Windows) 69 | if: ${{ matrix.java == '17' && runner.os == 'Windows' }} 70 | uses: actions/upload-artifact@v2 71 | with: 72 | name: test-log-windows-jdk17 73 | path: .\logs\ 74 | - name: capture test log (Windows) 75 | if: ${{ matrix.java == '11' && runner.os == 'Windows' }} 76 | uses: actions/upload-artifact@v2 77 | with: 78 | name: test-log-windows-jdk11 79 | path: .\logs\ 80 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle/ 2 | .idea/ 3 | build/ 4 | Optilog-RunVideo.mp4 5 | Optilog-Tutorial.mp4 6 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 OptiJava 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Optilog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OptiJava/Optilog-Client/6fe72f15739ff0fe7b526429ee0c0f536f64917b/Optilog.png -------------------------------------------------------------------------------- /Profile_main.sdt: -------------------------------------------------------------------------------- 1 | ({"_classDescription":{"_className":"com.optilog.Profile","_attributes":["public"]},"_methodName":"main","_attributes":["public","static"],"_argNames":["args"],"_argTypes":["java.lang.String[]"],"_returnType":"void","offset":97} ({"_classDescription":{"_className":"com.optilog.log.Log","_attributes":["public","abstract","interface"]},"_methodName":"initLog","_attributes":["public","static"],"_argNames":["pathOfSettingFile"],"_argTypes":["java.lang.String"],"_returnType":"com.optilog.log.Log","offset":141} ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"new","_attributes":["packageLocal"],"_argNames":["s"],"_argTypes":["java.lang.String"],"_returnType":"com.optilog.log.Optilog","offset":264} ) ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"logPreparer","_attributes":["public"],"_argNames":["settingFilePath","instance"],"_argTypes":["java.lang.String","com.optilog.log.Optilog"],"_returnType":"void","offset":312} ({"_classDescription":{"_className":"com.optilog.setting.SettingFiles","_attributes":["public"]},"_methodName":"check","_attributes":["public","static"],"_argNames":["str","instance"],"_argTypes":["java.lang.String","com.optilog.log.Optilog"],"_returnType":"void","offset":1316} ({"_classDescription":{"_className":"com.optilog.setting.JsonSettings","_attributes":["public"]},"_methodName":"getJsonSettings","_attributes":["public","static"],"_argNames":["path","isClasspath","instance"],"_argTypes":["java.lang.String","boolean","com.optilog.log.Optilog"],"_returnType":"void","offset":2067} ({"_classDescription":{"_className":"com.optilog.setting.SettingFiles","_attributes":["public"]},"_methodName":"readAsString","_attributes":["public","static"],"_argNames":["input"],"_argTypes":["java.io.InputStream"],"_returnType":"java.lang.String","offset":6332} )) ({"_classDescription":{"_className":"com.optilog.setting.JsonSettings","_attributes":["public"]},"_methodName":"getJsonSettings","_attributes":["public","static"],"_argNames":["path","isClasspath","instance"],"_argTypes":["java.lang.String","boolean","com.optilog.log.Optilog"],"_returnType":"void","offset":2230} ({"_classDescription":{"_className":"com.optilog.setting.SettingFiles","_attributes":["public"]},"_methodName":"readAsString","_attributes":["public","static"],"_argNames":["input"],"_argTypes":["java.io.InputStream"],"_returnType":"java.lang.String","offset":6332} )) ({"_classDescription":{"_className":"com.optilog.setting.XmlSettings","_attributes":["public"]},"_methodName":"xml","_attributes":["static","packageLocal"],"_argNames":["path","isClasspath","instance"],"_argTypes":["java.lang.String","boolean","com.optilog.log.Optilog"],"_returnType":"void","offset":2395} ) ({"_classDescription":{"_className":"com.optilog.setting.XmlSettings","_attributes":["public"]},"_methodName":"xml","_attributes":["static","packageLocal"],"_argNames":["path","isClasspath","instance"],"_argTypes":["java.lang.String","boolean","com.optilog.log.Optilog"],"_returnType":"void","offset":2543} ) ({"_classDescription":{"_className":"com.optilog.util.exception.ConfigureException","_attributes":["public","final"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg"],"_argTypes":["java.lang.String"],"_returnType":"com.optilog.util.exception.ConfigureException","offset":3030} ({"_classDescription":{"_className":"com.optilog.util.exception.OptilogException","_attributes":["public"]},"_methodName":"new","_attributes":["public"],"_argNames":["message"],"_argTypes":["java.lang.String"],"_returnType":"com.optilog.util.exception.OptilogException","offset":216} )) ({"_classDescription":{"_className":"com.optilog.setting.PropSettings","_attributes":["public"]},"_methodName":"properties","_attributes":["static","packageLocal"],"_argNames":["content","instance"],"_argTypes":["java.io.InputStream","com.optilog.log.Optilog"],"_returnType":"void","offset":3147} ({"_classDescription":{"_className":"com.optilog.util.exception.ConfigureException","_attributes":["public","final"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","th"],"_argTypes":["java.lang.String","java.lang.Throwable"],"_returnType":"com.optilog.util.exception.ConfigureException","offset":3969} )) ({"_classDescription":{"_className":"com.optilog.setting.PropSettings","_attributes":["public"]},"_methodName":"properties","_attributes":["static","packageLocal"],"_argNames":["content","instance"],"_argTypes":["java.io.InputStream","com.optilog.log.Optilog"],"_returnType":"void","offset":3425} ({"_classDescription":{"_className":"com.optilog.util.exception.ConfigureException","_attributes":["public","final"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","th"],"_argTypes":["java.lang.String","java.lang.Throwable"],"_returnType":"com.optilog.util.exception.ConfigureException","offset":3969} )) ({"_classDescription":{"_className":"com.optilog.setting.YamlSettings","_attributes":["public"]},"_methodName":"yaml","_attributes":["public","static"],"_argNames":["path","isClasspath","instance"],"_argTypes":["java.lang.String","boolean","com.optilog.log.Optilog"],"_returnType":"void","offset":3591} ({"_classDescription":{"_className":"com.optilog.util.exception.ConfigureException","_attributes":["public","final"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","th"],"_argTypes":["java.lang.String","java.lang.Throwable"],"_returnType":"com.optilog.util.exception.ConfigureException","offset":735} ) ({"_classDescription":{"_className":"com.optilog.util.exception.ConfigureException","_attributes":["public","final"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","th"],"_argTypes":["java.lang.String","java.lang.Throwable"],"_returnType":"com.optilog.util.exception.ConfigureException","offset":1102} )) ({"_classDescription":{"_className":"com.optilog.setting.YamlSettings","_attributes":["public"]},"_methodName":"yaml","_attributes":["public","static"],"_argNames":["path","isClasspath","instance"],"_argTypes":["java.lang.String","boolean","com.optilog.log.Optilog"],"_returnType":"void","offset":3743} ({"_classDescription":{"_className":"com.optilog.util.exception.ConfigureException","_attributes":["public","final"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","th"],"_argTypes":["java.lang.String","java.lang.Throwable"],"_returnType":"com.optilog.util.exception.ConfigureException","offset":735} ) ({"_classDescription":{"_className":"com.optilog.util.exception.ConfigureException","_attributes":["public","final"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","th"],"_argTypes":["java.lang.String","java.lang.Throwable"],"_returnType":"com.optilog.util.exception.ConfigureException","offset":1102} ))) ({"_classDescription":{"_className":"com.optilog.log.console.Console","_attributes":["public"]},"_methodName":"initAppender","_attributes":["public","static"],"_argNames":["instance"],"_argTypes":["com.optilog.log.Optilog"],"_returnType":"void","offset":1427} ({"_classDescription":{"_className":"com.optilog.log.console.Console","_attributes":["public"]},"_methodName":"checkFile","_attributes":["private","static"],"_argNames":["f","instance"],"_argTypes":["java.io.File","com.optilog.log.Optilog"],"_returnType":"boolean","offset":1171} )) ({"_classDescription":{"_className":"com.optilog.log.client.Client","_attributes":["public"]},"_methodName":"initAppender","_attributes":["public","static"],"_argNames":["instance"],"_argTypes":["com.optilog.log.Optilog"],"_returnType":"void","offset":1474} ) ({"_classDescription":{"_className":"com.optilog.util.exception.OptilogException","_attributes":["public"]},"_methodName":"new","_attributes":["public"],"_argNames":["message","cause"],"_argTypes":["java.lang.String","java.lang.Throwable"],"_returnType":"com.optilog.util.exception.OptilogException","offset":1680} ))) ({"_classDescription":{"_className":"com.optilog.log.Log","_attributes":["public","abstract","interface"]},"_methodName":"info","_attributes":["public","abstract"],"_argNames":[],"_argTypes":[],"_returnType":"void","offset":196} ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"info","_attributes":["public"],"_argNames":[],"_argTypes":[],"_returnType":"void","offset":1804} ({"_classDescription":{"_className":"com.optilog.log.LogEvent","_attributes":["public"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","level"],"_argTypes":["java.lang.String","com.optilog.log.Level"],"_returnType":"com.optilog.log.LogEvent","offset":1842} ) ({"_classDescription":{"_className":"com.optilog.log.Logger","_attributes":["public"]},"_methodName":"logInfo","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":1929} ({"_classDescription":{"_className":"com.optilog.log.Send","_attributes":["public"]},"_methodName":"loggerPrint","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":384} ({"_classDescription":{"_className":"com.optilog.log.Packing","_attributes":["public"]},"_methodName":"packMessage","_attributes":["public","static"],"_argNames":["msg","level","instance","appender"],"_argTypes":["java.lang.String","java.lang.String","com.optilog.log.Optilog","com.optilog.log.Appender"],"_returnType":"java.lang.String","offset":448} )) ({"_classDescription":{"_className":"com.optilog.log.Send","_attributes":["public"]},"_methodName":"loggerConsole","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":522} ({"_classDescription":{"_className":"com.optilog.log.Packing","_attributes":["public"]},"_methodName":"packMessage","_attributes":["public","static"],"_argNames":["msg","level","instance","appender"],"_argTypes":["java.lang.String","java.lang.String","com.optilog.log.Optilog","com.optilog.log.Appender"],"_returnType":"java.lang.String","offset":966} ) ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"error","_attributes":["public"],"_argNames":["msg","ex"],"_argTypes":["java.lang.Object","java.lang.Throwable"],"_returnType":"void","offset":1217} ({"_classDescription":{"_className":"com.optilog.log.LogEvent","_attributes":["public"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","level"],"_argTypes":["java.lang.String","com.optilog.log.Level"],"_returnType":"com.optilog.log.LogEvent","offset":10621} ) ({"_classDescription":{"_className":"com.optilog.log.Logger","_attributes":["public"]},"_methodName":"logError","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":10730} )) ({"_classDescription":{"_className":"com.optilog.log.Packing","_attributes":["public"]},"_methodName":"packMessage","_attributes":["public","static"],"_argNames":["msg","level","instance","appender"],"_argTypes":["java.lang.String","java.lang.String","com.optilog.log.Optilog","com.optilog.log.Appender"],"_returnType":"java.lang.String","offset":1691} ) ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"error","_attributes":["public"],"_argNames":["msg","ex"],"_argTypes":["java.lang.Object","java.lang.Throwable"],"_returnType":"void","offset":1942} ({"_classDescription":{"_className":"com.optilog.log.LogEvent","_attributes":["public"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","level"],"_argTypes":["java.lang.String","com.optilog.log.Level"],"_returnType":"com.optilog.log.LogEvent","offset":10621} ) ({"_classDescription":{"_className":"com.optilog.log.Logger","_attributes":["public"]},"_methodName":"logError","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":10730} )) ({"_classDescription":{"_className":"com.optilog.log.Packing","_attributes":["public"]},"_methodName":"packMessage","_attributes":["public","static"],"_argNames":["msg","level","instance","appender"],"_argTypes":["java.lang.String","java.lang.String","com.optilog.log.Optilog","com.optilog.log.Appender"],"_returnType":"java.lang.String","offset":2492} ) ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"error","_attributes":["public"],"_argNames":["msg","ex"],"_argTypes":["java.lang.Object","java.lang.Throwable"],"_returnType":"void","offset":2743} ({"_classDescription":{"_className":"com.optilog.log.LogEvent","_attributes":["public"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","level"],"_argTypes":["java.lang.String","com.optilog.log.Level"],"_returnType":"com.optilog.log.LogEvent","offset":10621} ) ({"_classDescription":{"_className":"com.optilog.log.Logger","_attributes":["public"]},"_methodName":"logError","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":10730} )) ({"_classDescription":{"_className":"com.optilog.log.Packing","_attributes":["public"]},"_methodName":"packMessage","_attributes":["public","static"],"_argNames":["msg","level","instance","appender"],"_argTypes":["java.lang.String","java.lang.String","com.optilog.log.Optilog","com.optilog.log.Appender"],"_returnType":"java.lang.String","offset":3289} ) ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"error","_attributes":["public"],"_argNames":["msg","ex"],"_argTypes":["java.lang.Object","java.lang.Throwable"],"_returnType":"void","offset":3540} ({"_classDescription":{"_className":"com.optilog.log.LogEvent","_attributes":["public"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","level"],"_argTypes":["java.lang.String","com.optilog.log.Level"],"_returnType":"com.optilog.log.LogEvent","offset":10621} ) ({"_classDescription":{"_className":"com.optilog.log.Logger","_attributes":["public"]},"_methodName":"logError","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":10730} )) ({"_classDescription":{"_className":"com.optilog.log.Packing","_attributes":["public"]},"_methodName":"packMessage","_attributes":["public","static"],"_argNames":["msg","level","instance","appender"],"_argTypes":["java.lang.String","java.lang.String","com.optilog.log.Optilog","com.optilog.log.Appender"],"_returnType":"java.lang.String","offset":4014} ) ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"error","_attributes":["public"],"_argNames":["msg","ex"],"_argTypes":["java.lang.Object","java.lang.Throwable"],"_returnType":"void","offset":4265} ({"_classDescription":{"_className":"com.optilog.log.LogEvent","_attributes":["public"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","level"],"_argTypes":["java.lang.String","com.optilog.log.Level"],"_returnType":"com.optilog.log.LogEvent","offset":10621} ) ({"_classDescription":{"_className":"com.optilog.log.Logger","_attributes":["public"]},"_methodName":"logError","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":10730} )) ({"_classDescription":{"_className":"com.optilog.log.Packing","_attributes":["public"]},"_methodName":"packMessage","_attributes":["public","static"],"_argNames":["msg","level","instance","appender"],"_argTypes":["java.lang.String","java.lang.String","com.optilog.log.Optilog","com.optilog.log.Appender"],"_returnType":"java.lang.String","offset":4752} ) ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"error","_attributes":["public"],"_argNames":["msg","ex"],"_argTypes":["java.lang.Object","java.lang.Throwable"],"_returnType":"void","offset":5003} ({"_classDescription":{"_className":"com.optilog.log.LogEvent","_attributes":["public"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","level"],"_argTypes":["java.lang.String","com.optilog.log.Level"],"_returnType":"com.optilog.log.LogEvent","offset":10621} ) ({"_classDescription":{"_className":"com.optilog.log.Logger","_attributes":["public"]},"_methodName":"logError","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":10730} )) ({"_classDescription":{"_className":"com.optilog.log.Packing","_attributes":["public"]},"_methodName":"packMessage","_attributes":["public","static"],"_argNames":["msg","level","instance","appender"],"_argTypes":["java.lang.String","java.lang.String","com.optilog.log.Optilog","com.optilog.log.Appender"],"_returnType":"java.lang.String","offset":5466} ) ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"error","_attributes":["public"],"_argNames":["msg","ex"],"_argTypes":["java.lang.Object","java.lang.Throwable"],"_returnType":"void","offset":5717} ({"_classDescription":{"_className":"com.optilog.log.LogEvent","_attributes":["public"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","level"],"_argTypes":["java.lang.String","com.optilog.log.Level"],"_returnType":"com.optilog.log.LogEvent","offset":10621} ) ({"_classDescription":{"_className":"com.optilog.log.Logger","_attributes":["public"]},"_methodName":"logError","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":10730} )) ({"_classDescription":{"_className":"com.optilog.log.Packing","_attributes":["public"]},"_methodName":"packMessage","_attributes":["public","static"],"_argNames":["msg","level","instance","appender"],"_argTypes":["java.lang.String","java.lang.String","com.optilog.log.Optilog","com.optilog.log.Appender"],"_returnType":"java.lang.String","offset":6152} ) ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"error","_attributes":["public"],"_argNames":["msg","ex"],"_argTypes":["java.lang.Object","java.lang.Throwable"],"_returnType":"void","offset":6403} ({"_classDescription":{"_className":"com.optilog.log.LogEvent","_attributes":["public"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","level"],"_argTypes":["java.lang.String","com.optilog.log.Level"],"_returnType":"com.optilog.log.LogEvent","offset":10621} ) ({"_classDescription":{"_className":"com.optilog.log.Logger","_attributes":["public"]},"_methodName":"logError","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":10730} )) ({"_classDescription":{"_className":"com.optilog.log.Packing","_attributes":["public"]},"_methodName":"packMessage","_attributes":["public","static"],"_argNames":["msg","level","instance","appender"],"_argTypes":["java.lang.String","java.lang.String","com.optilog.log.Optilog","com.optilog.log.Appender"],"_returnType":"java.lang.String","offset":6866} ) ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"error","_attributes":["public"],"_argNames":["msg","ex"],"_argTypes":["java.lang.Object","java.lang.Throwable"],"_returnType":"void","offset":7117} ({"_classDescription":{"_className":"com.optilog.log.LogEvent","_attributes":["public"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","level"],"_argTypes":["java.lang.String","com.optilog.log.Level"],"_returnType":"com.optilog.log.LogEvent","offset":10621} ) ({"_classDescription":{"_className":"com.optilog.log.Logger","_attributes":["public"]},"_methodName":"logError","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":10730} )) ({"_classDescription":{"_className":"com.optilog.log.Packing","_attributes":["public"]},"_methodName":"packMessage","_attributes":["public","static"],"_argNames":["msg","level","instance","appender"],"_argTypes":["java.lang.String","java.lang.String","com.optilog.log.Optilog","com.optilog.log.Appender"],"_returnType":"java.lang.String","offset":7580} ) ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"error","_attributes":["public"],"_argNames":["msg","ex"],"_argTypes":["java.lang.Object","java.lang.Throwable"],"_returnType":"void","offset":7831} ({"_classDescription":{"_className":"com.optilog.log.LogEvent","_attributes":["public"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","level"],"_argTypes":["java.lang.String","com.optilog.log.Level"],"_returnType":"com.optilog.log.LogEvent","offset":10621} ) ({"_classDescription":{"_className":"com.optilog.log.Logger","_attributes":["public"]},"_methodName":"logError","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":10730} )) ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"error","_attributes":["public"],"_argNames":["msg","ex"],"_argTypes":["java.lang.Object","java.lang.Throwable"],"_returnType":"void","offset":8039} ({"_classDescription":{"_className":"com.optilog.log.LogEvent","_attributes":["public"]},"_methodName":"new","_attributes":["public"],"_argNames":["msg","level"],"_argTypes":["java.lang.String","com.optilog.log.Level"],"_returnType":"com.optilog.log.LogEvent","offset":10621} ) ({"_classDescription":{"_className":"com.optilog.log.Logger","_attributes":["public"]},"_methodName":"logError","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":10730} ))) ({"_classDescription":{"_className":"com.optilog.log.Send","_attributes":["public"]},"_methodName":"loggerToServer","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":695} ({"_classDescription":{"_className":"com.optilog.log.Packing","_attributes":["public"]},"_methodName":"packMessage","_attributes":["public","static"],"_argNames":["msg","level","instance","appender"],"_argTypes":["java.lang.String","java.lang.String","com.optilog.log.Optilog","com.optilog.log.Appender"],"_returnType":"java.lang.String","offset":8288} ) ({"_classDescription":{"_className":"com.optilog.log.client.Client","_attributes":["public"]},"_methodName":"logAppender","_attributes":["public","static"],"_argNames":["msg","instance"],"_argTypes":["java.lang.String","com.optilog.log.Optilog"],"_returnType":"void","offset":8268} ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"error","_attributes":["public"],"_argNames":["msg","ex"],"_argTypes":["java.lang.Object","java.lang.Throwable"],"_returnType":"void","offset":1048} )) ({"_classDescription":{"_className":"com.optilog.log.Packing","_attributes":["public"]},"_methodName":"packMessage","_attributes":["public","static"],"_argNames":["msg","level","instance","appender"],"_argTypes":["java.lang.String","java.lang.String","com.optilog.log.Optilog","com.optilog.log.Appender"],"_returnType":"java.lang.String","offset":8449} ) ({"_classDescription":{"_className":"com.optilog.log.client.Client","_attributes":["public"]},"_methodName":"logAppender","_attributes":["public","static"],"_argNames":["msg","instance"],"_argTypes":["java.lang.String","com.optilog.log.Optilog"],"_returnType":"void","offset":8429} ({"_classDescription":{"_className":"com.optilog.log.Optilog","_attributes":["public"]},"_methodName":"error","_attributes":["public"],"_argNames":["msg","ex"],"_argTypes":["java.lang.Object","java.lang.Throwable"],"_returnType":"void","offset":1048} ))) ({"_classDescription":{"_className":"com.optilog.log.Send","_attributes":["public"]},"_methodName":"loggerToJdbc","_attributes":["static","packageLocal"],"_argNames":["le","instance"],"_argTypes":["com.optilog.log.LogEvent","com.optilog.log.Optilog"],"_returnType":"void","offset":799} ({"_classDescription":{"_className":"com.optilog.log.Packing","_attributes":["public"]},"_methodName":"packMessage","_attributes":["public","static"],"_argNames":["msg","level","instance","appender"],"_argTypes":["java.lang.String","java.lang.String","com.optilog.log.Optilog","com.optilog.log.Appender"],"_returnType":"java.lang.String","offset":8749} ) ({"_classDescription":{"_className":"com.optilog.log.jdbc.MySQL","_attributes":["public"]},"_methodName":"logAppender","_attributes":["public","static"],"_argNames":["logEvent","clazz","allMessage","instance"],"_argTypes":["com.optilog.log.LogEvent","java.lang.String","java.lang.String","com.optilog.log.Optilog"],"_returnType":"void","offset":8667} )))))) 2 | -------------------------------------------------------------------------------- /README-en.md: -------------------------------------------------------------------------------- 1 | # [Optilog-Client](https://github.com/OptiJava/Optilog-Client) 2 | 3 | ![Build](https://img.shields.io/badge/Build-Passing-green) 4 | ![Statistic](https://img.shields.io/badge/Code-3429Line-red) 5 | [![Latest-Release](https://img.shields.io/badge/Release-Latest-blue)](https://github.com/OptiJava/Optilog-Client/releases/latest) 6 | 7 | [中文](https://github.com/OptiJava/Optilog-Client/blob/master/README.md) 8 | 9 | **_Thank you all for supporting this project_** 10 | 11 | **Optilog needs Java 11+** 12 | 13 | **This is an open source logging framework written in Java language. It has more advantages than other open source 14 | logging frameworks (such as Log4j and SLF4j)** 15 | 16 | The wiki of optilog will be updated at any time. Problems or bugs will be raised 17 | on [issues](https://github.com/OptiJava/Optilog-Client/issues) 18 | or [discussions](https://github.com/OptiJava/Optilog-Client/discussions). 19 | 20 | **Be sure to read the [wiki](https://github.com/OptiJava/Optilog-Client/wiki) of this project before using it** 21 | 22 | _If you like, you are welcome to contribute to optilog through fork. The code of this project is quite basic, and anyone 23 | can contribute._ 24 | 25 | ## Optilog advantages 26 | 27 | 1. High performance: After initialization, another log (output to the screen + output to a file + output to the server 28 | through socket) can be output as fast as 8 milliseconds (it will be optimized later). Optilog is a synchronous log, 29 | which has no delay at all, and there is no need to consider the 30 | problem of multithreaded atomic operations. 31 | Optilog occupies slightly less memory than log4j, and one log output takes about 502344 bytes. 32 | Only output to screen+file in ideal state only takes 6 milliseconds 33 | 34 | 2. Placeholder convenience: optilog supports unlimited placeholders and can be reused (#1 #1 outputs the first 35 | placeholder twice). Log4j only supports 9 placeholders. 36 | 37 | 3. Configuration file can be placed in any location. The name of the configuration file is unlimited. Two types of 38 | configuration files are supported. In log4j, the configuration file can only be in classpath and the name can only be 39 | log4j2 xml. 40 | 41 | 4. Support the client to send logs to [Server](https://github.com/OptiJava/Optilog-Server). 42 | 43 | 5. All possible exceptions in Optilog are basically captured without affecting the main logic. 44 | 45 | 6. You only need one jar package, and you can use it directly by typing in the classpath (I don't know the feeling of 46 | adding dozens of jar packages at once when using gradle). 47 | 48 | 7. Suitable for beginners without complex configuration files. 49 | 50 | 8. Few [dependence](https://github.com/OptiJava/Optilog-Client/blob/master/README-en.md#dependency). 51 | 52 | 9. Class, method and other information output in the log are absolutely accurate, because Optilog uses StackTraceElement 53 | internally to determine that information, and there is no need to write the class instance when initializing the 54 | log. 55 | 56 | 10. Optilog can directly generate a default configuration file. Beginners do not need to look for the configuration file 57 | example ([Tutorial](https://github.com/OptiJava/Optilog-Client/wiki/%E6%9B%B4%E5%A4%9A%E5%8A%9F%E8%83%BD#%E5%85%AD%E7%94%9F%E6%88%90%E9%BB%98%E8%AE%A4%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6)) 58 | 59 | 11. Support configuration files in multiple formats, including JSON, yaml, XML and properties. Support for .toml 60 | configuration files will be added later. 61 | 62 | 12. Optilog supports configuration modification during runtime. Of course, only some configuration items of true and 63 | false can be modified. Output file paths cannot be modified(Related functions will be added in the future. Things 64 | like packingFormat can be modified directly. If you really want to modify the output path, you may need to 65 | reInitialize it internally). 66 | 67 | 13. Support outputting logs to JDBC. 68 | 69 | ## Optilog log picture: 70 | 71 | ![image](https://user-images.githubusercontent.com/106148777/170864247-7da18dd5-f5b9-4e5c-aee7-4174d29a8969.png) 72 | _Generate by [carbon.now.sh](https://carbon.now.sh)_ 73 | 74 | ## Dependency: 75 | 76 | `com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.3` 77 | \ 78 | `org.yaml:snakeyaml:1.30` `mysql:mysql-connector-java:8.0.29` 79 | \ 80 | `mysql:mysql-connector-java:8.0.29` 81 | \ 82 | (You needn't add dependency if you don't use these function.) 83 | 84 | ## Contributor: 85 | 86 | JavauserO 87 | 88 | ## Future plans 89 | 90 | realize remote call 91 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Optilog-Client](https://github.com/OptiJava/Optilog-Client/) 2 | 3 | ![Build](https://img.shields.io/badge/Build-Passing-green) 4 | ![Statistic](https://img.shields.io/badge/Code-3379Line-red) 5 | [![Latest-Release](https://img.shields.io/badge/Release-Latest-blue)](https://github.com/OptiJava/Optilog-Client/releases/latest) 6 | 7 | [English](https://github.com/OptiJava/Optilog-Client/blob/master/README-en.md) 8 | 9 | **_欢迎Star或Fork以支持本项目的开发工作!哪怕只是改了一点点也要pr,这是对该项目的巨大支持awa_** 10 | 11 | **Optilog目前需要Java11+** 12 | 13 | 这是一个用java语言编写的开源日志框架,他相比现在其他开源日志框架(比如log4j,slf4j)有更多的[优势](https://github.com/OptiJava/Optilog-Client#optilog%E7%9A%84%E4%BC%98%E5%8A%BF) 14 | 15 | Optilog的Wiki随时会更新,有问题或者发现了bug在[Issues](https://github.com/OptiJava/Optilog-Client/issues) 16 | 或[Discussions](https://github.com/OptiJava/Optilog-Client/discussions)上提。 17 | 18 | 使用前一定!看[本项目Wiki](https://github.com/OptiJava/Optilog-Client/wiki) 19 | 20 | _如果你愿意,欢迎Fork这个仓库为Optilog做出贡献,本项目的代码比较基础,任何人都可以做出贡献。非常欢迎向本项目发送PullRequest,哪怕只是改改文档也好。_ 21 | 想要快速了解本项目的话,推荐看[Optilog的具体日志流程图](https://github.com/OptiJava/Optilog-Client/blob/master/Optilog.png) 22 | ,也可以用IDEA插件:SequenceDiagram看看方法调用流程图 23 | 24 | ## Optilog的优势 25 | 26 | 1.性能高: 27 | 在初始化后+输出一条日志(输出到屏幕+输出到文件+通过socket输出到服务端)最快只需要30毫秒(后续还会再优化)。而且Optilog是同步日志,完全没有延迟,也无需考虑多线程原子操作问题。Optilog占用内存略小于log4j,输出一条日志约占502344字节 28 | \ 29 | 仅输出到屏幕+文件在理想状态下仅需6毫秒 30 | 31 | 2.占位符方便:Optilog支持无限个占位符,并且可以重复使用(#1 #1输出两次第一个占位符),log4j只支持9个占位符 32 | 33 | 3.配置文件可以放在任意位置,配置文件名字不限,支持两种配置文件,在log4j中配置文件只能在classpath中且名字只能是log4j2.xml 34 | 35 | 4.支持客户端发送日志到[服务端](https://github.com/OptiJava/Optilog-Server) 36 | 37 | 5.Optilog内部可能出现的异常基本全部被捕获,不影响主要逻辑 38 | 39 | 6.只需一个jar包,打进classpath就能直接用(用gradle的不知道一下子加几十个jar包的感受) 40 | 41 | 7.适用于初学者,没有复杂的配置文件 ~~最主要优势~~ 42 | 43 | 8.需要的依赖少 44 | 45 | 9.日志中输出的Class、Method等信息是绝对准确的,因为Optilog内部使用StackTraceElement确定这些信息,并且无需在初始化日志时写入Class实例 46 | 47 | 10.Optilog可以直接生成一个默认的配置文件,初学者不用找配置文件范例([教程](https://github.com/OptiJava/Optilog-Client/wiki/%E6%9B%B4%E5%A4%9A%E5%8A%9F%E8%83%BD#%E5%85%AD%E7%94%9F%E6%88%90%E9%BB%98%E8%AE%A4%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6) 48 | ) 49 | 50 | 11.支持多种格式的配置文件,包括json,yaml,xml和properties,后续还会增加对toml配置文件的支持 51 | 52 | 12.Optilog支持在运行期修改配置,当然只能修改true和false的一些配置项,输出文件路径什么的不能修改(以后会加入相关的功能,像packingFormat这类东西可以就直接修改了,如果真要修改输出路径可能要在内部重新初始化一下) 53 | 54 | 13.支持输出日志到jdbc 55 | 56 | ## Optilog输出日志预览: 57 | 58 | ![image](https://user-images.githubusercontent.com/106148777/170864247-7da18dd5-f5b9-4e5c-aee7-4174d29a8969.png) 59 | _使用[carbon.now.sh](https://carbon.now.sh)生成_ 60 | 61 | ## Dependency: 62 | 63 | `com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.3` 64 | \ 65 | `org.yaml:snakeyaml:1.30` 66 | \ 67 | `mysql:mysql-connector-java:8.0.29` 68 | \ 69 | (如果你只用properties作为配置文件的话Gson,Jackson,snakeyaml也可以不加,mysql不用也可以不加) 70 | 71 | ## Contributor: 72 | 73 | `JavaUserO` 74 | 75 | ## 未来计划 76 | 77 | 实现远程调用 78 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | import java.nio.file.Files 2 | import java.nio.file.NoSuchFileException 3 | 4 | plugins { 5 | id 'java' 6 | } 7 | 8 | group 'com.optilog' 9 | version '2022.6.4' 10 | 11 | repositories { 12 | mavenCentral() 13 | } 14 | 15 | dependencies { 16 | implementation 'org.junit.jupiter:junit-jupiter-engine:5.8.2' 17 | 18 | implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.3' 19 | implementation 'org.yaml:snakeyaml:1.30' 20 | implementation 'com.google.code.gson:gson:2.9.0' 21 | runtimeOnly 'mysql:mysql-connector-java:8.0.29' 22 | } 23 | 24 | compileJava { 25 | options.compilerArgs.add("--release") 26 | options.compilerArgs.add("11") 27 | } 28 | 29 | task cleanTestLog { 30 | try { 31 | Files.delete(java.nio.file.Path.of('./logs')) 32 | } catch (NoSuchFileException ignored) { 33 | print "'./logs' file not found." 34 | } 35 | try { 36 | Files.createDirectory(java.nio.file.Path.of('./logs')) 37 | } catch (IOException e) { 38 | e.printStackTrace() 39 | } 40 | } 41 | 42 | test { 43 | useJUnitPlatform() 44 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OptiJava/Optilog-Client/6fe72f15739ff0fe7b526429ee0c0f536f64917b/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'Optilog-Client' 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/log/Appender.java: -------------------------------------------------------------------------------- 1 | package com.optilog.log; 2 | 3 | public enum Appender { 4 | PRINT, FILE, SERVER, JDBC 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/log/IOptilog.java: -------------------------------------------------------------------------------- 1 | package com.optilog.log; 2 | 3 | public interface IOptilog { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/log/Level.java: -------------------------------------------------------------------------------- 1 | package com.optilog.log; 2 | 3 | import com.optilog.util.OnlyInLog; 4 | 5 | public class Level { 6 | /* */ 7 | public final static Level INFO = new Level("info"); 8 | public final static Level ERROR = new Level("Error"); 9 | public final static Level WARN = new Level("Warning"); 10 | public final static Level DEBUG = new Level("debug"); 11 | public final static Level FATAL = new Level("FATAL"); 12 | 13 | @OnlyInLog 14 | Level(String name) { 15 | this.name = name; 16 | } 17 | 18 | public String getName() { 19 | return this.name; 20 | } 21 | 22 | private final String name; 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/log/LevelBuild.java: -------------------------------------------------------------------------------- 1 | package com.optilog.log; 2 | 3 | import com.optilog.util.OnlyInLog; 4 | 5 | public class LevelBuild { 6 | String levelName; 7 | 8 | Level levelTemplate; 9 | 10 | @OnlyInLog 11 | public LevelBuild(String levelName, Level levelTemplate) { 12 | this.levelName = levelName; 13 | this.levelTemplate = levelTemplate; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/log/Log.java: -------------------------------------------------------------------------------- 1 | package com.optilog.log; 2 | 3 | import com.optilog.util.LambdaExecute; 4 | 5 | public interface Log extends IOptilog { 6 | static Log initLog(String pathOfSettingFile) { 7 | Optilog optilog = new Optilog(pathOfSettingFile); 8 | optilog.logPreparer(pathOfSettingFile, optilog); 9 | return optilog; 10 | } 11 | 12 | static Log initLog(Log optilog) { 13 | return optilog; 14 | } 15 | 16 | void logPreparer(String settingFilePath, Optilog instance); 17 | 18 | void info(); 19 | 20 | void info(Object msg, Object... occupy); 21 | 22 | void info(Object msg, LambdaExecute... occupy); 23 | 24 | void info(Object msg, Throwable ex); 25 | 26 | void info(long x); 27 | 28 | void info(double x); 29 | 30 | void info(char[] x); 31 | 32 | void info(short x); 33 | 34 | void info(int x); 35 | 36 | void info(float x); 37 | 38 | void info(String x); 39 | 40 | void info(Object x); 41 | 42 | void error(); 43 | 44 | void error(Object msg, Object... occupy); 45 | 46 | void error(Object msg, LambdaExecute... occupy); 47 | 48 | void error(Object msg, Throwable ex); 49 | 50 | void error(long x); 51 | 52 | void error(double x); 53 | 54 | void error(char[] x); 55 | 56 | void error(short x); 57 | 58 | void error(int x); 59 | 60 | void error(float x); 61 | 62 | void error(String x); 63 | 64 | void error(Object x); 65 | 66 | void warn(); 67 | 68 | void warn(Object msg, Object... occupy); 69 | 70 | void warn(Object msg, LambdaExecute... occupy); 71 | 72 | void warn(Object msg, Throwable ex); 73 | 74 | void warn(long x); 75 | 76 | void warn(double x); 77 | 78 | void warn(char[] x); 79 | 80 | void warn(short x); 81 | 82 | void warn(int x); 83 | 84 | void warn(float x); 85 | 86 | void warn(String x); 87 | 88 | void warn(Object x); 89 | 90 | void debug(); 91 | 92 | void debug(Object msg, Object... occupy); 93 | 94 | void debug(Object msg, LambdaExecute... occupy); 95 | 96 | void debug(Object msg, Throwable ex); 97 | 98 | void debug(long x); 99 | 100 | void debug(double x); 101 | 102 | void debug(char[] x); 103 | 104 | void debug(short x); 105 | 106 | void debug(int x); 107 | 108 | void debug(float x); 109 | 110 | void debug(String x); 111 | 112 | void debug(Object x); 113 | 114 | void fatal(); 115 | 116 | void fatal(Object msg, Object... occupy); 117 | 118 | void fatal(Object msg, LambdaExecute... occupy); 119 | 120 | void fatal(Object msg, Throwable ex); 121 | 122 | void fatal(long x); 123 | 124 | void fatal(double x); 125 | 126 | void fatal(char[] x); 127 | 128 | void fatal(short x); 129 | 130 | void fatal(int x); 131 | 132 | void fatal(float x); 133 | 134 | void fatal(String x); 135 | 136 | void fatal(Object x); 137 | 138 | void command(String x); 139 | 140 | void setPrintInfo(boolean printInfo); 141 | 142 | void setPrintError(boolean printError); 143 | 144 | void setPrintWarn(boolean printWarn); 145 | 146 | void setPrintDebug(boolean printDebug); 147 | 148 | void setPrintFatal(boolean printFatal); 149 | 150 | void setConsoleInfo(boolean consoleInfo); 151 | 152 | void setConsoleError(boolean consoleError); 153 | 154 | void setConsoleWarn(boolean consoleWarn); 155 | 156 | void setConsoleDebug(boolean serverDebug); 157 | 158 | void setConsoleFatal(boolean serverFatal); 159 | 160 | void setServerInfo(boolean serverInfo); 161 | 162 | void setServerError(boolean serverError); 163 | 164 | void setServerWarn(boolean serverWarn); 165 | 166 | void setServerDebug(boolean serverDebug); 167 | 168 | void setServerFatal(boolean serverFatal); 169 | 170 | void setPrintPackingFormat(String printPackingFormat); 171 | 172 | void setFilePackingFormat(String filePackingFormat); 173 | 174 | void setServerPackingFormat(String serverPackingFormat); 175 | 176 | void startSendToJdbc(String url, String dataBaseName, String username, String password); 177 | 178 | void stopSendToJdbc(String url, String dataBaseName, String username, String password); 179 | 180 | void getAllField(Object instance); 181 | 182 | void log(Object obj, LevelBuild levelBuild); 183 | 184 | void log(Object x, LevelBuild levelBuild, Object... occupy); 185 | 186 | void log(Object x, LevelBuild levelBuild, LambdaExecute... occupy); 187 | 188 | void log(Object msg, LevelBuild levelBuild, Throwable ex); 189 | } -------------------------------------------------------------------------------- /src/main/java/com/optilog/log/LogEvent.java: -------------------------------------------------------------------------------- 1 | package com.optilog.log; 2 | 3 | import com.optilog.util.OnlyInLog; 4 | 5 | public class LogEvent { 6 | public String message; 7 | 8 | public final Level level; 9 | 10 | public LogMark marker = LogMark.NONE; 11 | 12 | @OnlyInLog 13 | public LogEvent(String msg, Level level) { 14 | this.level = level; 15 | this.message = msg; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/log/LogMark.java: -------------------------------------------------------------------------------- 1 | package com.optilog.log; 2 | 3 | public enum LogMark { 4 | NONE("NONE"), TEMPLATEInfo("info"), TEMPLATEError("Error"), TEMPLATEWarn("Warning"), TEMPLATEDebug("debug"), TEMPLATEFatal("FATAL"); 5 | 6 | public final String name; 7 | 8 | LogMark(String name) { 9 | this.name = name; 10 | } 11 | 12 | public String getName() { 13 | return this.name; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/log/Logger.java: -------------------------------------------------------------------------------- 1 | package com.optilog.log; 2 | 3 | import com.optilog.log.client.Client; 4 | import com.optilog.log.console.ZipLog; 5 | import com.optilog.util.OnlyInLog; 6 | import com.optilog.util.exception.InvalidCommandException; 7 | 8 | public class Logger { 9 | private Logger() { 10 | } 11 | 12 | @OnlyInLog 13 | static void logInfo(LogEvent le, Optilog instance) { 14 | if (instance.allSetting.printInfo) { 15 | Send.loggerPrint(le, instance); 16 | } 17 | 18 | if (instance.consoleFileMasterCaution && instance.allSetting.consoleInfo) { 19 | Send.loggerConsole(le, instance); 20 | } 21 | 22 | if (instance.consoleFileMasterCaution && instance.allSetting.serverInfo && instance.allSetting.startClient) { 23 | Send.loggerToServer(le, instance); 24 | } 25 | 26 | if (instance.connection.sendToJdbc) { 27 | Send.loggerToJdbc(le, instance); 28 | } 29 | } 30 | 31 | @OnlyInLog 32 | static void logError(LogEvent le, Optilog instance) { 33 | 34 | if (instance.allSetting.printError) { 35 | Send.loggerPrint(le, instance); 36 | } 37 | 38 | if (instance.consoleFileMasterCaution && instance.allSetting.consoleError) { 39 | Send.loggerConsole(le, instance); 40 | } 41 | 42 | if (instance.consoleFileMasterCaution && instance.allSetting.serverError && instance.allSetting.startClient) { 43 | Send.loggerToServer(le, instance); 44 | } 45 | 46 | if (instance.connection.sendToJdbc) { 47 | Send.loggerToJdbc(le, instance); 48 | } 49 | } 50 | 51 | @OnlyInLog 52 | static void logWarn(LogEvent le, Optilog instance) { 53 | 54 | if (instance.allSetting.printWarn) { 55 | Send.loggerPrint(le, instance); 56 | } 57 | 58 | if (instance.consoleFileMasterCaution && instance.allSetting.consoleWarn) { 59 | Send.loggerConsole(le, instance); 60 | } 61 | 62 | if (instance.consoleFileMasterCaution && instance.allSetting.serverWarn && instance.allSetting.startClient) { 63 | Send.loggerToServer(le, instance); 64 | } 65 | 66 | if (instance.connection.sendToJdbc) { 67 | Send.loggerToJdbc(le, instance); 68 | } 69 | } 70 | 71 | @OnlyInLog 72 | static void logDebug(LogEvent le, Optilog instance) { 73 | 74 | if (instance.allSetting.printDebug) { 75 | Send.loggerPrint(le, instance); 76 | } 77 | 78 | if (instance.consoleFileMasterCaution && instance.allSetting.consoleDebug) { 79 | Send.loggerConsole(le, instance); 80 | } 81 | 82 | if (instance.consoleFileMasterCaution && instance.allSetting.serverDebug && instance.allSetting.startClient) { 83 | Send.loggerToServer(le, instance); 84 | } 85 | 86 | if (instance.connection.sendToJdbc) { 87 | Send.loggerToJdbc(le, instance); 88 | } 89 | } 90 | 91 | @OnlyInLog 92 | static void logFatal(LogEvent le, Optilog instance) { 93 | 94 | if (instance.allSetting.printFatal) { 95 | Send.loggerPrint(le, instance); 96 | } 97 | 98 | if (instance.consoleFileMasterCaution && instance.allSetting.consoleFatal) { 99 | Send.loggerConsole(le, instance); 100 | } 101 | 102 | if (instance.consoleFileMasterCaution && instance.allSetting.serverFatal && instance.allSetting.startClient) { 103 | Send.loggerToServer(le, instance); 104 | } 105 | 106 | if (instance.connection.sendToJdbc) { 107 | Send.loggerToJdbc(le, instance); 108 | } 109 | } 110 | 111 | @OnlyInLog 112 | static void logCommand(String command, Optilog instance) { 113 | if (command.equals("%stop -client")) { 114 | Client.stop(instance); 115 | } else if (command.startsWith("%zip -d")) { 116 | ZipLog.zipAllLog(true, instance, command.substring(8)); 117 | } else if (command.startsWith("%zip")) { 118 | ZipLog.zipAllLog(false, instance, command.substring(5)); 119 | } else { 120 | try { 121 | throw new InvalidCommandException("Invalid Command '" + command + "' ", new IllegalArgumentException()); 122 | } catch (RuntimeException e) { 123 | instance.error("Optilog Note:Invalid command ' " + command + " '", e); 124 | } 125 | } 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/log/Packing.java: -------------------------------------------------------------------------------- 1 | package com.optilog.log; 2 | 3 | import com.optilog.util.OnlyInLog; 4 | 5 | import java.time.LocalDateTime; 6 | import java.time.format.DateTimeFormatter; 7 | import java.util.Objects; 8 | import java.util.regex.Matcher; 9 | 10 | public class Packing { 11 | private Packing() { 12 | super(); 13 | } 14 | 15 | @OnlyInLog 16 | public static String packMessage(String msg, String level, Optilog instance, Appender appender) { 17 | final StackTraceElement[] arr = Thread.currentThread().getStackTrace(); 18 | String returnString = instance.allSetting.printPackingFormat; 19 | if (appender == Appender.FILE) { 20 | returnString = instance.allSetting.consolePackingFormat; 21 | } else if (appender == Appender.SERVER) { 22 | returnString = instance.allSetting.serverPackingFormat; 23 | } 24 | 25 | try { 26 | returnString = returnString.replace("%thread", Matcher.quoteReplacement(getLocalThread())); 27 | 28 | returnString = returnString.replace("%yyyy", DateTimeFormatter.ofPattern("yyyy").format(LocalDateTime.now())); 29 | returnString = returnString.replace("%MM", DateTimeFormatter.ofPattern("MM").format(LocalDateTime.now())); 30 | returnString = returnString.replace("%dd", DateTimeFormatter.ofPattern("dd").format(LocalDateTime.now())); 31 | returnString = returnString.replace("%HH", DateTimeFormatter.ofPattern("HH").format(LocalDateTime.now())); 32 | returnString = returnString.replace("%mm", DateTimeFormatter.ofPattern("mm").format(LocalDateTime.now())); 33 | returnString = returnString.replace("%ss", DateTimeFormatter.ofPattern("ss").format(LocalDateTime.now())); 34 | returnString = returnString.replace("%SS", DateTimeFormatter.ofPattern("SS").format(LocalDateTime.now())); 35 | 36 | returnString = returnString.replace("%level", Matcher.quoteReplacement(level)); 37 | 38 | returnString = returnString.replace("%class", Matcher.quoteReplacement(arr[5].getClassName())); 39 | returnString = returnString.replace("%line", String.valueOf(arr[5].getLineNumber())); 40 | returnString = returnString.replace("%file", Matcher.quoteReplacement(Objects.requireNonNull(arr[5].getFileName()))); 41 | returnString = returnString.replace("%msg", Matcher.quoteReplacement(msg)); 42 | returnString = returnString.replace("%method", Matcher.quoteReplacement(arr[5].getMethodName())); 43 | } catch (NullPointerException i) { 44 | i.getStackTrace(); 45 | } 46 | return returnString + "\n"; 47 | } 48 | 49 | @OnlyInLog 50 | private static String getLocalThread() { 51 | return Thread.currentThread().getName(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/log/Send.java: -------------------------------------------------------------------------------- 1 | package com.optilog.log; 2 | 3 | import com.optilog.log.client.Client; 4 | import com.optilog.log.jdbc.MySQL; 5 | import com.optilog.util.OnlyInLog; 6 | import com.optilog.util.Util; 7 | 8 | import java.io.IOException; 9 | import java.nio.charset.StandardCharsets; 10 | import java.nio.file.Files; 11 | import java.nio.file.Path; 12 | 13 | public class Send { 14 | private Send() { 15 | super(); 16 | } 17 | 18 | @OnlyInLog 19 | static void loggerPrint(LogEvent le, Optilog instance) { 20 | Util.getOutput().print(Packing.packMessage(le.message, le.level.getName(), instance, Appender.PRINT)); 21 | } 22 | 23 | @OnlyInLog 24 | static void loggerConsole(LogEvent le, Optilog instance) { 25 | String MSG = "Optilog Note:Java throws Exception when log is output"; 26 | 27 | try { 28 | if (Level.INFO.getName().equals(le.level.getName()) && !instance.info.isBlank() && instance.consoleFileMasterCaution) { 29 | try { 30 | synchronized (Util.getOutput()) { 31 | Files.writeString(Path.of(instance.info), Files.readString(Path.of(instance.info), StandardCharsets.UTF_8) + Packing.packMessage(le.message, le.level.getName(), instance, Appender.FILE), StandardCharsets.UTF_8); 32 | } 33 | } catch (IOException e) { 34 | instance.consoleFileMasterCaution = false; 35 | instance.error(MSG, e); 36 | } 37 | return; 38 | } 39 | if (Level.ERROR.getName().equals(le.level.getName()) && !instance.error.isBlank() && instance.consoleFileMasterCaution) { 40 | try { 41 | synchronized (Util.getOutput()) { 42 | Files.writeString(Path.of(instance.error), Files.readString(Path.of(instance.error), StandardCharsets.UTF_8) + Packing.packMessage(le.message, le.level.getName(), instance, Appender.FILE), StandardCharsets.UTF_8); 43 | } 44 | } catch (IOException e) { 45 | instance.consoleFileMasterCaution = false; 46 | instance.error(MSG, e); 47 | } 48 | return; 49 | } 50 | if (Level.DEBUG.getName().equals(le.level.getName()) && !instance.debug.isBlank() && instance.consoleFileMasterCaution) { 51 | try { 52 | synchronized (Util.getOutput()) { 53 | Files.writeString(Path.of(instance.debug), Files.readString(Path.of(instance.debug), StandardCharsets.UTF_8) + Packing.packMessage(le.message, le.level.getName(), instance, Appender.FILE), StandardCharsets.UTF_8); 54 | } 55 | } catch (IOException e) { 56 | instance.consoleFileMasterCaution = false; 57 | instance.error(MSG, e); 58 | } 59 | return; 60 | } 61 | if (Level.WARN.getName().equals(le.level.getName()) && !instance.warn.isBlank() && instance.consoleFileMasterCaution) { 62 | try { 63 | synchronized (Util.getOutput()) { 64 | Files.writeString(Path.of(instance.warn), Files.readString(Path.of(instance.warn), StandardCharsets.UTF_8) + Packing.packMessage(le.message, le.level.getName(), instance, Appender.FILE), StandardCharsets.UTF_8); 65 | } 66 | } catch (IOException e) { 67 | instance.consoleFileMasterCaution = false; 68 | instance.error(MSG, e); 69 | } 70 | return; 71 | } 72 | if (Level.FATAL.getName().equals(le.level.getName()) && !instance.fatal.isBlank() && instance.consoleFileMasterCaution) { 73 | try { 74 | synchronized (Util.getOutput()) { 75 | Files.writeString(Path.of(instance.fatal), Files.readString(Path.of(instance.fatal), StandardCharsets.UTF_8) + Packing.packMessage(le.message, le.level.getName(), instance, Appender.FILE), StandardCharsets.UTF_8); 76 | } 77 | } catch (IOException e) { 78 | instance.consoleFileMasterCaution = false; 79 | instance.error(MSG, e); 80 | } 81 | return; 82 | } 83 | // Marker runner 84 | if (le.marker == LogMark.TEMPLATEInfo && instance.consoleFileMasterCaution && (!instance.info.isBlank())) { 85 | try { 86 | synchronized (Util.getOutput()) { 87 | Files.writeString(Path.of(instance.info), Files.readString(Path.of(instance.info), StandardCharsets.UTF_8) + Packing.packMessage(le.message, le.level.getName(), instance, Appender.FILE), StandardCharsets.UTF_8); 88 | } 89 | } catch (IOException e) { 90 | instance.consoleFileMasterCaution = false; 91 | instance.error(MSG, e); 92 | } 93 | return; 94 | } 95 | 96 | if (le.marker == LogMark.TEMPLATEError && instance.consoleFileMasterCaution && (!instance.error.isBlank())) { 97 | try { 98 | synchronized (Util.getOutput()) { 99 | Files.writeString(Path.of(instance.error), Files.readString(Path.of(instance.error), StandardCharsets.UTF_8) + Packing.packMessage(le.message, le.level.getName(), instance, Appender.FILE), StandardCharsets.UTF_8); 100 | } 101 | } catch (IOException e) { 102 | instance.consoleFileMasterCaution = false; 103 | instance.error(MSG, e); 104 | } 105 | } 106 | 107 | if (le.marker == LogMark.TEMPLATEWarn && instance.consoleFileMasterCaution && (!instance.warn.isBlank())) { 108 | try { 109 | synchronized (Util.getOutput()) { 110 | Files.writeString(Path.of(instance.warn), Files.readString(Path.of(instance.warn), StandardCharsets.UTF_8) + Packing.packMessage(le.message, le.level.getName(), instance, Appender.FILE), StandardCharsets.UTF_8); 111 | } 112 | } catch (IOException e) { 113 | instance.consoleFileMasterCaution = false; 114 | instance.error(MSG, e); 115 | } 116 | return; 117 | } 118 | 119 | if (le.marker == LogMark.TEMPLATEDebug && instance.consoleFileMasterCaution && (!instance.debug.isBlank())) { 120 | try { 121 | synchronized (Util.getOutput()) { 122 | Files.writeString(Path.of(instance.debug), Files.readString(Path.of(instance.debug), StandardCharsets.UTF_8) + Packing.packMessage(le.message, le.level.getName(), instance, Appender.FILE), StandardCharsets.UTF_8); 123 | } 124 | } catch (IOException e) { 125 | instance.consoleFileMasterCaution = false; 126 | instance.error(MSG, e); 127 | } 128 | return; 129 | } 130 | 131 | if (le.marker == LogMark.TEMPLATEFatal && instance.consoleFileMasterCaution && (!instance.fatal.isBlank())) { 132 | try { 133 | synchronized (Util.getOutput()) { 134 | Files.writeString(Path.of(instance.fatal), Files.readString(Path.of(instance.fatal), StandardCharsets.UTF_8) + Packing.packMessage(le.message, le.level.getName(), instance, Appender.FILE), StandardCharsets.UTF_8); 135 | } 136 | } catch (IOException e) { 137 | instance.consoleFileMasterCaution = false; 138 | instance.error(MSG, e); 139 | } 140 | } 141 | 142 | } catch (Exception e) { 143 | instance.consoleFileMasterCaution = false; 144 | instance.error(MSG, e); 145 | } 146 | } 147 | 148 | @OnlyInLog 149 | static void loggerToServer(LogEvent le, final Optilog instance) { 150 | if (le.marker != LogMark.NONE) { 151 | Client.logAppender(Packing.packMessage(le.message, le.level.getName(), instance, Appender.SERVER) + le.marker.getName(), instance); 152 | } else { 153 | Client.logAppender(Packing.packMessage(le.message, le.level.getName(), instance, Appender.SERVER) + le.level.getName(), instance); 154 | } 155 | } 156 | 157 | @OnlyInLog 158 | static void loggerToJdbc(LogEvent le, final Optilog instance) { 159 | MySQL.logAppender(le, Thread.currentThread().getStackTrace()[4].getClassName(), Packing.packMessage(le.message, le.level.getName(), instance, Appender.JDBC), instance); 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/log/client/Client.java: -------------------------------------------------------------------------------- 1 | package com.optilog.log.client; 2 | 3 | import com.optilog.log.Optilog; 4 | import com.optilog.util.OnlyInInit; 5 | import com.optilog.util.OnlyInLog; 6 | 7 | import java.io.IOException; 8 | import java.net.*; 9 | 10 | public class Client { 11 | @OnlyInInit 12 | public static void initAppender(Optilog instance) { 13 | if (instance.allSetting.startClient) { 14 | try { 15 | instance.socket = new DatagramSocket(); 16 | instance.socket.setSoTimeout(1000); 17 | instance.socket.connect(InetAddress.getByName(instance.allSetting.host), instance.allSetting.socketNumber); 18 | } catch (UnknownHostException | SocketException exception) { 19 | System.err.println("Optilog Note: Exception in init client."); 20 | exception.printStackTrace(); 21 | } 22 | } 23 | } 24 | 25 | @OnlyInLog 26 | public static void logAppender(String msg, Optilog instance) { 27 | try { 28 | if (instance.allSetting.startClient) { 29 | instance.socket.send(new DatagramPacket(msg.getBytes(), msg.getBytes().length)); 30 | } 31 | } catch (PortUnreachableException pue) { 32 | if (instance.allSetting.forceDisableSocketWhenException) { 33 | instance.allSetting.serverInfo = false; 34 | instance.allSetting.serverError = false; 35 | instance.allSetting.serverWarn = false; 36 | instance.allSetting.serverFatal = false; 37 | instance.allSetting.serverDebug = false; 38 | instance.error("Optilog Note: Force disabled socket because exception when send packet.", pue); 39 | } else { 40 | instance.error("Optilog Note: PortUnreachableException in Client.", pue); 41 | } 42 | } catch (IOException e) { 43 | instance.error("Optilog Note: IOException in Client.", e); 44 | } 45 | } 46 | 47 | @OnlyInLog 48 | public static void stop(Optilog instance) { 49 | instance.socket.disconnect(); 50 | instance.info("Optilog Note: Socket Disconnected!"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/log/console/Console.java: -------------------------------------------------------------------------------- 1 | package com.optilog.log.console; 2 | 3 | import com.optilog.log.Optilog; 4 | import com.optilog.util.OnlyInInit; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.time.LocalDateTime; 9 | import java.time.format.DateTimeFormatter; 10 | import java.util.regex.Matcher; 11 | 12 | public class Console { 13 | @OnlyInInit 14 | public static void initAppender(Optilog instance) { 15 | if (instance.consoleFileMasterCaution) { 16 | instance.allSetting.fileName = instance.allSetting.fileName.replace("%time", Matcher.quoteReplacement(DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss-SS").format(LocalDateTime.now()))); 17 | 18 | if (instance.allSetting.defaultConsolePath.isBlank() && instance.allSetting.Path1.isBlank() && instance.allSetting.Path2.isBlank() && instance.allSetting.Path3.isBlank() && instance.allSetting.Path4.isBlank() && instance.allSetting.Path5.isBlank()) { 19 | instance.consoleFileMasterCaution = false; 20 | return; 21 | } 22 | 23 | if (!instance.allSetting.defaultConsolePath.isBlank() && instance.consoleFileMasterCaution) { 24 | final File f = new File(instance.allSetting.defaultConsolePath); 25 | if (Console.checkFile(f, instance)) { 26 | File defFile = new File(instance.allSetting.defaultConsolePath + File.separator + instance.allSetting.fileName); 27 | try { 28 | if (!defFile.isFile()) { 29 | if (!defFile.createNewFile()) { 30 | instance.consoleFileMasterCaution = false; 31 | throw new IOException("Failed to create log file in default console path!"); 32 | } 33 | } 34 | if (instance.consoleFileMasterCaution) { 35 | instance.info = defFile.getAbsolutePath(); 36 | instance.error = defFile.getAbsolutePath(); 37 | instance.warn = defFile.getAbsolutePath(); 38 | instance.debug = defFile.getAbsolutePath(); 39 | instance.fatal = defFile.getAbsolutePath(); 40 | } 41 | } catch (IOException e) { 42 | System.err.println("Optilog Note: IOException in init default path log file!"); 43 | instance.consoleFileMasterCaution = false; 44 | } 45 | } else { 46 | System.err.println("Optilog Note: ConsolePath maybe not correct or not exists"); 47 | instance.consoleFileMasterCaution = false; 48 | return; 49 | } 50 | } 51 | 52 | if (!instance.allSetting.Path1.equals("") && instance.consoleFileMasterCaution) { 53 | File file = new File(instance.allSetting.Path1 + File.separator + instance.allSetting.fileName); 54 | try { 55 | if (!file.isFile()) { 56 | if (!file.createNewFile()) { 57 | throw new IOException("Create new initAppender failed!"); 58 | } 59 | } 60 | instance.allSetting.Path1 = file.getAbsolutePath(); 61 | } catch (IOException e) { 62 | throw new RuntimeException(e); 63 | } 64 | } 65 | if (!instance.allSetting.Path2.equals("") && instance.consoleFileMasterCaution) { 66 | File file = new File(instance.allSetting.Path2 + File.separator + instance.allSetting.fileName); 67 | try { 68 | if (!file.isFile()) { 69 | if (!file.createNewFile()) { 70 | throw new IOException("Create new initAppender failed!"); 71 | } 72 | } 73 | instance.allSetting.Path2 = file.getAbsolutePath(); 74 | } catch (IOException e) { 75 | throw new RuntimeException(e); 76 | } 77 | } 78 | if (!instance.allSetting.Path3.equals("") && instance.consoleFileMasterCaution) { 79 | File file = new File(instance.allSetting.Path3 + File.separator + instance.allSetting.fileName); 80 | try { 81 | if (!file.isFile()) { 82 | if (!file.createNewFile()) { 83 | throw new IOException("Create new initAppender failed!"); 84 | } 85 | } 86 | instance.allSetting.Path3 = file.getAbsolutePath(); 87 | } catch (IOException e) { 88 | throw new RuntimeException(e); 89 | } 90 | } 91 | if (!instance.allSetting.Path4.equals("") && instance.consoleFileMasterCaution) { 92 | File file = new File(instance.allSetting.Path4 + File.separator + instance.allSetting.fileName); 93 | try { 94 | if (!file.isFile()) { 95 | if (!file.createNewFile()) { 96 | throw new IOException("Create new initAppender failed!"); 97 | } 98 | } 99 | instance.allSetting.Path4 = file.getAbsolutePath(); 100 | } catch (IOException e) { 101 | throw new RuntimeException(e); 102 | } 103 | } 104 | if (!instance.allSetting.Path5.equals("") && instance.consoleFileMasterCaution) { 105 | File file = new File(instance.allSetting.Path5 + File.separator + instance.allSetting.fileName); 106 | try { 107 | if (!file.isFile()) { 108 | if (!file.createNewFile()) { 109 | throw new IOException("Create new initAppender failed!"); 110 | } 111 | } 112 | instance.allSetting.Path5 = file.getAbsolutePath(); 113 | } catch (IOException e) { 114 | throw new RuntimeException(e); 115 | } 116 | } 117 | } 118 | 119 | if (instance.allSetting.infoPath.startsWith("%path") && instance.consoleFileMasterCaution) { 120 | try { 121 | if (instance.allSetting.infoPath.toLowerCase().replace("%path", "").equals("1")) { 122 | instance.info = instance.allSetting.Path1; 123 | } 124 | if (instance.allSetting.infoPath.toLowerCase().replace("%path", "").equals("2")) { 125 | instance.info = instance.allSetting.Path2; 126 | } 127 | if (instance.allSetting.infoPath.toLowerCase().replace("%path", "").equals("3")) { 128 | instance.info = instance.allSetting.Path3; 129 | } 130 | if (instance.allSetting.infoPath.toLowerCase().replace("%path", "").equals("4")) { 131 | instance.info = instance.allSetting.Path4; 132 | } 133 | if (instance.allSetting.infoPath.toLowerCase().replace("%path", "").equals("5")) { 134 | instance.info = instance.allSetting.Path5; 135 | } 136 | if (instance.info.equals("")) { 137 | System.err.println("Optilog Note: Unexpected error occur when parse infoPath"); 138 | instance.allSetting.consoleInfo = false; 139 | } 140 | } catch (NullPointerException e) { 141 | instance.consoleFileMasterCaution = false; 142 | System.err.println("Optilog Note: Unexpected error occur when parse infoPath"); 143 | e.printStackTrace(); 144 | } 145 | } 146 | if (instance.allSetting.errorPath.startsWith("%path") && instance.consoleFileMasterCaution) { 147 | try { 148 | if (instance.allSetting.errorPath.toLowerCase().replace("%path", "").equals("1")) { 149 | instance.error = instance.allSetting.Path1; 150 | } 151 | if (instance.allSetting.errorPath.toLowerCase().replace("%path", "").equals("2")) { 152 | instance.error = instance.allSetting.Path2; 153 | } 154 | if (instance.allSetting.errorPath.toLowerCase().replace("%path", "").equals("3")) { 155 | instance.error = instance.allSetting.Path3; 156 | } 157 | if (instance.allSetting.errorPath.toLowerCase().replace("%path", "").equals("4")) { 158 | instance.error = instance.allSetting.Path4; 159 | } 160 | if (instance.allSetting.errorPath.toLowerCase().replace("%path", "").equals("5")) { 161 | instance.error = instance.allSetting.Path5; 162 | } 163 | if (instance.error.equals("")) { 164 | instance.allSetting.consoleError = false; 165 | System.err.println("Optilog Note: Unexpected error occur when parse errorPath"); 166 | } 167 | } catch (NullPointerException e) { 168 | instance.consoleFileMasterCaution = false; 169 | System.err.println("Optilog Note: Unexpected error occur when parse errorPath"); 170 | e.printStackTrace(); 171 | } 172 | } 173 | if (instance.allSetting.warnPath.startsWith("%path") && instance.consoleFileMasterCaution) { 174 | try { 175 | if (instance.allSetting.warnPath.toLowerCase().replace("%path", "").equals("1")) { 176 | instance.warn = instance.allSetting.Path1; 177 | } 178 | if (instance.allSetting.warnPath.toLowerCase().replace("%path", "").equals("2")) { 179 | instance.warn = instance.allSetting.Path2; 180 | } 181 | if (instance.allSetting.warnPath.toLowerCase().replace("%path", "").equals("3")) { 182 | instance.warn = instance.allSetting.Path3; 183 | } 184 | if (instance.allSetting.warnPath.toLowerCase().replace("%path", "").equals("4")) { 185 | instance.warn = instance.allSetting.Path4; 186 | } 187 | if (instance.allSetting.warnPath.toLowerCase().replace("%path", "").equals("5")) { 188 | instance.warn = instance.allSetting.Path5; 189 | } 190 | if (instance.warn.equals("")) { 191 | instance.allSetting.consoleWarn = false; 192 | System.err.println("Optilog Note: Unexpected error occur when parse warnPath"); 193 | } 194 | } catch (NullPointerException e) { 195 | instance.consoleFileMasterCaution = false; 196 | System.err.println("Optilog Note: Unexpected error occur when parse warnPath"); 197 | } 198 | } 199 | if (instance.allSetting.debugPath.startsWith("%path") && instance.consoleFileMasterCaution) { 200 | try { 201 | if (instance.allSetting.debugPath.toLowerCase().replace("%path", "").equals("1")) { 202 | instance.debug = instance.allSetting.Path1; 203 | } 204 | if (instance.allSetting.debugPath.toLowerCase().replace("%path", "").equals("2")) { 205 | instance.debug = instance.allSetting.Path2; 206 | } 207 | if (instance.allSetting.debugPath.toLowerCase().replace("%path", "").equals("3")) { 208 | instance.debug = instance.allSetting.Path3; 209 | } 210 | if (instance.allSetting.debugPath.toLowerCase().replace("%path", "").equals("4")) { 211 | instance.debug = instance.allSetting.Path4; 212 | } 213 | if (instance.allSetting.debugPath.toLowerCase().replace("%path", "").equals("5")) { 214 | instance.debug = instance.allSetting.Path5; 215 | } 216 | if (instance.debug.equals("")) { 217 | instance.allSetting.consoleDebug = false; 218 | System.err.println("Optilog Note: Unexpected error occur when parse debugPath"); 219 | } 220 | } catch (NullPointerException e) { 221 | instance.consoleFileMasterCaution = false; 222 | System.err.println("Optilog Note: Unexpected error occur when parse debugPath"); 223 | } 224 | } 225 | if (instance.allSetting.fatalPath.startsWith("%path") && instance.consoleFileMasterCaution) { 226 | try { 227 | if (instance.allSetting.fatalPath.toLowerCase().replace("%path", "").equals("1")) { 228 | instance.fatal = instance.allSetting.Path1; 229 | } 230 | if (instance.allSetting.fatalPath.toLowerCase().replace("%path", "").equals("2")) { 231 | instance.fatal = instance.allSetting.Path2; 232 | } 233 | if (instance.allSetting.fatalPath.toLowerCase().replace("%path", "").equals("3")) { 234 | instance.fatal = instance.allSetting.Path3; 235 | } 236 | if (instance.allSetting.fatalPath.toLowerCase().replace("%path", "").equals("4")) { 237 | instance.fatal = instance.allSetting.Path4; 238 | } 239 | if (instance.allSetting.fatalPath.toLowerCase().replace("%path", "").equals("5")) { 240 | instance.fatal = instance.allSetting.Path5; 241 | } 242 | if (instance.fatal.equals("")) { 243 | instance.allSetting.consoleFatal = false; 244 | System.err.println("Optilog Note: Unexpected error occur when parse fatalPath"); 245 | } 246 | } catch (NullPointerException e) { 247 | instance.consoleFileMasterCaution = false; 248 | System.err.println("Optilog Note: Unexpected error occur when parse fatalPath"); 249 | } 250 | } 251 | 252 | } 253 | 254 | @OnlyInInit 255 | private static boolean checkFile(File f, Optilog instance) { 256 | try { 257 | return f.isDirectory() && f.canRead() && f.canWrite() && instance.consoleFileMasterCaution; 258 | } catch (NullPointerException npe) { 259 | npe.printStackTrace(); 260 | return false; 261 | } catch (Exception e) { 262 | try { 263 | throw new RuntimeException(e); 264 | } catch (Exception ex) { 265 | ex.printStackTrace(); 266 | return false; 267 | } 268 | } 269 | } 270 | } 271 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/log/console/ZipLog.java: -------------------------------------------------------------------------------- 1 | package com.optilog.log.console; 2 | 3 | import com.optilog.log.Optilog; 4 | import com.optilog.util.OnlyInLog; 5 | 6 | import java.io.File; 7 | import java.io.FileOutputStream; 8 | import java.io.IOException; 9 | import java.nio.file.Files; 10 | import java.time.LocalDateTime; 11 | import java.time.format.DateTimeFormatter; 12 | import java.util.zip.ZipEntry; 13 | import java.util.zip.ZipOutputStream; 14 | 15 | public class ZipLog { 16 | @OnlyInLog 17 | public static void zipAllLog(boolean delete, Optilog instance, String path) { 18 | File f = new File(path + File.separator + DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss(SS)").format(LocalDateTime.now()) + "LogPackage.zip"); 19 | try { 20 | if (!f.createNewFile()) { 21 | throw new IOException("Create file failed."); 22 | } 23 | } catch (IOException e) { 24 | instance.warn("Optilog Note: Failed to create log package zip.", e); 25 | return; 26 | } 27 | 28 | try (ZipOutputStream output = new ZipOutputStream(new FileOutputStream(f))) { 29 | File[] file = new File(path).listFiles(); 30 | if (file != null) { 31 | for (File fff : file) { 32 | if (fff.getName().endsWith(".log")) { 33 | output.putNextEntry(new ZipEntry(fff.getName())); 34 | output.write(Files.readAllBytes(fff.toPath())); 35 | output.closeEntry(); 36 | if (delete) { 37 | if (!fff.delete()) { 38 | System.err.println("Delete file failed."); 39 | } 40 | } 41 | } 42 | } 43 | } else { 44 | instance.info("Optilog Note:No log initAppender in fatal initAppender path."); 45 | } 46 | } catch (IOException e) { 47 | instance.error("Optilog Note:Failed to pack log initAppender.", e); 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/log/jdbc/MySQL.java: -------------------------------------------------------------------------------- 1 | package com.optilog.log.jdbc; 2 | 3 | import com.optilog.log.LogEvent; 4 | import com.optilog.log.Optilog; 5 | import com.optilog.util.OnlyInInit; 6 | import com.optilog.util.OnlyInLog; 7 | 8 | import java.sql.*; 9 | 10 | public class MySQL { 11 | public volatile Connection conn; 12 | 13 | public volatile boolean sendToJdbc = false; 14 | 15 | public volatile String dataBaseName; 16 | 17 | @OnlyInInit 18 | public static void initAppender(String url, String username, String password, String dataBaseName, Optilog instance) { 19 | instance.connection.dataBaseName = dataBaseName; 20 | try (Connection conn = DriverManager.getConnection(url, username, password)) { 21 | instance.connection.conn = conn; 22 | try (Statement statement = instance.connection.conn.createStatement()) { 23 | statement.execute("USE " + dataBaseName); 24 | statement.execute("CREATE TABLE IF NOT EXISTS logs (id BIGINT AUTO_INCREMENT NOT NULL, lvl VARCHAR(5) NOT NULL, class VARCHAR(20) NOT NULL, message VARCHAR(900) NOT NULL, AllMessage VARCHAR(2000) NOT NULL, PRIMARY KEY(id)) Engine=INNODB DEFAULT CHARSET=UTF8;"); 25 | instance.connection.conn = DriverManager.getConnection(url, username, password); 26 | } catch (SQLException e) { 27 | instance.connection = null; 28 | e.printStackTrace(); 29 | } 30 | } catch (SQLException e) { 31 | throw new RuntimeException(e); 32 | } 33 | } 34 | 35 | @OnlyInLog 36 | public static void logAppender(LogEvent logEvent, String clazz, String allMessage, Optilog instance) { 37 | try (Statement statement = instance.connection.conn.createStatement()) { 38 | statement.execute("USE " + instance.connection.dataBaseName); 39 | try (PreparedStatement ps = instance.connection.conn.prepareStatement("INSERT INTO logs (lvl, class, message, AllMessage) VALUES (?,?,?,?);")) { 40 | instance.connection.conn.setAutoCommit(false); 41 | ps.setObject(1, logEvent.level.getName()); 42 | ps.setObject(2, clazz); 43 | ps.setObject(3, logEvent.message); 44 | ps.setObject(4, allMessage); 45 | ps.executeUpdate(); 46 | } catch (SQLException e) { 47 | e.printStackTrace(); 48 | try { 49 | instance.connection.conn.rollback(); 50 | } catch (SQLException ex) { 51 | ex.printStackTrace(); 52 | } 53 | } finally { 54 | try { 55 | instance.connection.conn.setAutoCommit(true); 56 | } catch (SQLException e) { 57 | e.printStackTrace(); 58 | } 59 | } 60 | } catch (SQLException e) { 61 | e.printStackTrace(); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/setting/JsonSettingBean.java: -------------------------------------------------------------------------------- 1 | package com.optilog.setting; 2 | 3 | import java.util.Map; 4 | 5 | public class JsonSettingBean { 6 | public Map print; 7 | 8 | public Map file; 9 | 10 | public Map server; 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/setting/JsonSettings.java: -------------------------------------------------------------------------------- 1 | package com.optilog.setting; 2 | 3 | import com.google.gson.Gson; 4 | import com.optilog.log.Optilog; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.nio.charset.StandardCharsets; 10 | import java.nio.file.Files; 11 | import java.nio.file.Path; 12 | 13 | public class JsonSettings { 14 | public static void getJsonSettings(String path, boolean isClasspath, Optilog instance) { 15 | if (isClasspath && (!path.startsWith("/") && !path.startsWith("\\"))) { 16 | path = File.separator + path; 17 | } 18 | try { 19 | if (!isClasspath) { 20 | JsonSettingBean bean = new Gson().fromJson(Files.readString(Path.of(path), StandardCharsets.UTF_8), JsonSettingBean.class); 21 | parseSettings(instance, bean); 22 | } else { 23 | JsonSettingBean bean; 24 | try (InputStream inputStream = Optilog.class.getResourceAsStream(path)) { 25 | if (inputStream == null) { 26 | System.err.println("Optilog Note: Can't find file in classpath(" + path + ")"); 27 | instance.consoleFileMasterCaution = false; 28 | return; 29 | } 30 | bean = new Gson().fromJson(SettingFiles.readAsString(inputStream), JsonSettingBean.class); 31 | } 32 | 33 | parseSettings(instance, bean); 34 | } 35 | } catch (IOException e) { 36 | e.printStackTrace(); 37 | instance.consoleFileMasterCaution = false; 38 | } 39 | } 40 | 41 | private static void parseSettings(Optilog instance, JsonSettingBean bean) { 42 | final String INFO = "info"; 43 | final String ERROR = "error"; 44 | final String WARN = "warn"; 45 | final String DEBUG = "debug"; 46 | final String FATAL = "fatal"; 47 | 48 | final String PACKING_FORMAT = "packingFormat"; 49 | 50 | try { 51 | instance.allSetting.printInfo = Boolean.parseBoolean(bean.print.get(INFO)); 52 | instance.allSetting.printError = Boolean.parseBoolean(bean.print.get(ERROR)); 53 | instance.allSetting.printWarn = Boolean.parseBoolean(bean.print.get(WARN)); 54 | instance.allSetting.printDebug = Boolean.parseBoolean(bean.print.get(DEBUG)); 55 | instance.allSetting.printFatal = Boolean.parseBoolean(bean.print.get(FATAL)); 56 | String a = bean.print.get(PACKING_FORMAT); 57 | if (a != null) { 58 | instance.allSetting.defaultConsolePath = a.trim(); 59 | } 60 | } catch (NullPointerException ignored) { 61 | } 62 | 63 | // file 64 | try { 65 | instance.allSetting.consoleInfo = Boolean.parseBoolean(bean.file.get(INFO)); 66 | instance.allSetting.consoleError = Boolean.parseBoolean(bean.file.get(ERROR)); 67 | instance.allSetting.consoleWarn = Boolean.parseBoolean(bean.file.get(WARN)); 68 | instance.allSetting.consoleDebug = Boolean.parseBoolean(bean.file.get(DEBUG)); 69 | instance.allSetting.consoleFatal = Boolean.parseBoolean(bean.file.get(FATAL)); 70 | String b = bean.file.get("defaultConsolePath"); 71 | if (b != null) { 72 | instance.allSetting.defaultConsolePath = b.trim(); 73 | } 74 | String c1 = bean.file.get("Path1"); 75 | if (c1 != null) { 76 | instance.allSetting.Path1 = c1.trim(); 77 | } 78 | String c2 = bean.file.get("Path2"); 79 | if (c2 != null) { 80 | instance.allSetting.Path1 = c2.trim(); 81 | } 82 | String c3 = bean.file.get("Path3"); 83 | if (c3 != null) { 84 | instance.allSetting.Path1 = c3.trim(); 85 | } 86 | String c4 = bean.file.get("Path4"); 87 | if (c4 != null) { 88 | instance.allSetting.Path1 = c4.trim(); 89 | } 90 | String c5 = bean.file.get("Path5"); 91 | if (c5 != null) { 92 | instance.allSetting.Path1 = c5.trim(); 93 | } 94 | String di = bean.file.get("infoPath"); 95 | if (di != null) { 96 | instance.allSetting.infoPath = di.trim(); 97 | } 98 | String de = bean.file.get("errorPath"); 99 | if (de != null) { 100 | instance.allSetting.errorPath = de.trim(); 101 | } 102 | String dw = bean.file.get("warnPath"); 103 | if (dw != null) { 104 | instance.allSetting.warnPath = dw.trim(); 105 | } 106 | String dd = bean.file.get("debugPath"); 107 | if (dd != null) { 108 | instance.allSetting.debugPath = dd.trim(); 109 | } 110 | String df = bean.file.get("fatalPath"); 111 | if (df != null) { 112 | instance.allSetting.fatalPath = df.trim(); 113 | } 114 | String e = bean.file.get("fileName"); 115 | if (e != null) { 116 | instance.allSetting.fileName = e.trim(); 117 | } 118 | String f = bean.file.get(PACKING_FORMAT); 119 | if (f != null) { 120 | instance.allSetting.consolePackingFormat = f; 121 | } 122 | } catch (NullPointerException ignored) { 123 | } 124 | 125 | // server 126 | try { 127 | instance.allSetting.serverInfo = Boolean.parseBoolean(bean.server.get(INFO)); 128 | instance.allSetting.serverError = Boolean.parseBoolean(bean.server.get(ERROR)); 129 | instance.allSetting.serverWarn = Boolean.parseBoolean(bean.server.get(WARN)); 130 | instance.allSetting.serverDebug = Boolean.parseBoolean(bean.server.get(DEBUG)); 131 | instance.allSetting.serverFatal = Boolean.parseBoolean(bean.server.get(FATAL)); 132 | 133 | instance.allSetting.startClient = Boolean.parseBoolean(bean.server.get("startClient")); 134 | String a = bean.server.get("socketNumber"); 135 | if (a != null) { 136 | instance.allSetting.socketNumber = Integer.parseInt(a.trim()); 137 | } 138 | String b = bean.server.get("host"); 139 | if (b != null) { 140 | instance.allSetting.host = b.trim(); 141 | } 142 | String c = bean.server.get(PACKING_FORMAT); 143 | if (c != null) { 144 | instance.allSetting.serverPackingFormat = c; 145 | } 146 | String d = bean.server.get("forceDisableSocketWhenException"); 147 | if (d != null) { 148 | instance.allSetting.forceDisableSocketWhenException = Boolean.parseBoolean(d); 149 | } 150 | } catch (NullPointerException ignored) { 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/setting/PropSettings.java: -------------------------------------------------------------------------------- 1 | package com.optilog.setting; 2 | 3 | import com.optilog.log.Optilog; 4 | import com.optilog.util.OnlyInInit; 5 | import com.optilog.util.exception.ConfigureException; 6 | 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.util.Properties; 10 | 11 | public class PropSettings { 12 | @OnlyInInit 13 | static void properties(InputStream content, Optilog instance) { 14 | final Properties p = new Properties(); 15 | try { 16 | p.load(content); 17 | 18 | instance.allSetting.printInfo = Boolean.parseBoolean(p.getProperty("print.printInfo", Boolean.TRUE.toString())); 19 | instance.allSetting.printError = Boolean.parseBoolean(p.getProperty("print.printError", Boolean.TRUE.toString())); 20 | instance.allSetting.printWarn = Boolean.parseBoolean(p.getProperty("print.printWarn", Boolean.TRUE.toString())); 21 | instance.allSetting.printDebug = Boolean.parseBoolean(p.getProperty("print.printDebug", Boolean.TRUE.toString())); 22 | instance.allSetting.printFatal = Boolean.parseBoolean(p.getProperty("print.printFatal", Boolean.TRUE.toString())); 23 | 24 | instance.allSetting.consoleInfo = Boolean.parseBoolean(p.getProperty("file.consoleInfo", Boolean.FALSE.toString())); 25 | instance.allSetting.consoleError = Boolean.parseBoolean(p.getProperty("file.consoleError", Boolean.FALSE.toString())); 26 | instance.allSetting.consoleWarn = Boolean.parseBoolean(p.getProperty("file.consoleWarn", Boolean.FALSE.toString())); 27 | instance.allSetting.consoleDebug = Boolean.parseBoolean(p.getProperty("file.consoleDebug", Boolean.FALSE.toString())); 28 | instance.allSetting.consoleFatal = Boolean.parseBoolean(p.getProperty("file.consoleFatal", Boolean.FALSE.toString())); 29 | 30 | instance.allSetting.serverInfo = Boolean.parseBoolean(p.getProperty("server.infoSendToServer", Boolean.FALSE.toString())); 31 | instance.allSetting.serverError = Boolean.parseBoolean(p.getProperty("server.errorSendToServer", Boolean.FALSE.toString())); 32 | instance.allSetting.serverWarn = Boolean.parseBoolean(p.getProperty("server.warnSendToServer", Boolean.FALSE.toString())); 33 | instance.allSetting.serverDebug = Boolean.parseBoolean(p.getProperty("server.debugSendToServer", Boolean.FALSE.toString())); 34 | instance.allSetting.serverFatal = Boolean.parseBoolean(p.getProperty("server.fatalSendToServer", Boolean.FALSE.toString())); 35 | 36 | instance.allSetting.defaultConsolePath = p.getProperty("file.defaultConsolePath", ""); 37 | instance.allSetting.Path1 = p.getProperty("file.Path1", ""); 38 | instance.allSetting.Path2 = p.getProperty("file.Path2", ""); 39 | instance.allSetting.Path3 = p.getProperty("file.Path3", ""); 40 | instance.allSetting.Path4 = p.getProperty("file.Path4", ""); 41 | instance.allSetting.Path5 = p.getProperty("file.Path5", ""); 42 | 43 | instance.allSetting.infoPath = p.getProperty("file.infoPath", ""); 44 | instance.allSetting.errorPath = p.getProperty("file.errorPath", ""); 45 | instance.allSetting.warnPath = p.getProperty("file.warnPath", ""); 46 | instance.allSetting.debugPath = p.getProperty("file.debugPath", ""); 47 | instance.allSetting.fatalPath = p.getProperty("file.fatalPath", ""); 48 | 49 | instance.allSetting.host = p.getProperty("server.host", "localhost"); 50 | 51 | instance.allSetting.startClient = Boolean.parseBoolean(p.getProperty("server.startClient", Boolean.FALSE.toString())); 52 | 53 | String var1 = "[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS)][%class %method(%file:%line)/%thread] %level:%msg"; 54 | 55 | instance.allSetting.printPackingFormat = p.getProperty("print.packingFormat", var1); 56 | instance.allSetting.consolePackingFormat = p.getProperty("file.packingFormat", var1); 57 | instance.allSetting.serverPackingFormat = p.getProperty("server.packingFormat", var1); 58 | 59 | instance.allSetting.fileName = p.getProperty("file.fileName", "%time Log(Client).log"); 60 | 61 | instance.allSetting.forceDisableSocketWhenException = Boolean.parseBoolean(p.getProperty("server.forceDisableSocketWhenException", Boolean.TRUE.toString())); 62 | 63 | } catch (IOException e) { 64 | System.err.println("Optilog Note: Read file failed."); 65 | throw new ConfigureException("Can't find file.", e); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/setting/SettingFiles.java: -------------------------------------------------------------------------------- 1 | package com.optilog.setting; 2 | 3 | import com.optilog.log.Optilog; 4 | import com.optilog.util.OnlyInInit; 5 | import com.optilog.util.exception.ConfigureException; 6 | 7 | import java.io.File; 8 | import java.io.FileInputStream; 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | import java.nio.charset.StandardCharsets; 12 | import java.nio.file.Files; 13 | 14 | public class SettingFiles { 15 | public volatile boolean printError = true; 16 | public volatile boolean printInfo = true; 17 | public volatile boolean printDebug = true; 18 | public volatile boolean printWarn = true; 19 | public volatile boolean printFatal = true; 20 | public String defaultConsolePath = ""; 21 | public String Path1 = ""; 22 | public String Path2 = ""; 23 | public String Path3 = ""; 24 | public String Path4 = ""; 25 | public String Path5 = ""; 26 | public String infoPath = ""; 27 | public String errorPath = ""; 28 | public String warnPath = ""; 29 | public String debugPath = ""; 30 | public String fatalPath = ""; 31 | public boolean consoleInfo = true; 32 | public boolean consoleError = true; 33 | public boolean consoleDebug = true; 34 | public boolean consoleWarn = true; 35 | public boolean consoleFatal = true; 36 | public boolean serverInfo = false; 37 | public boolean serverError = false; 38 | public boolean serverDebug = false; 39 | public boolean serverWarn = false; 40 | public boolean serverFatal = false; 41 | public boolean startClient = false; 42 | public String host = "localhost"; // localhost 43 | public int socketNumber = 65535; 44 | public String printPackingFormat = "[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS)][%class %method(%file:%line)/%thread] %level:%msg"; 45 | public String consolePackingFormat = "[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS)][%class %method(%file:%line)/%thread] %level:%msg"; 46 | public String serverPackingFormat = "[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS)][%class %method(%file:%line)/%thread] %level:%msg"; 47 | 48 | public String fileName = "%time Log(Client).log"; 49 | 50 | public boolean forceDisableSocketWhenException = true; 51 | 52 | @OnlyInInit 53 | public static void check(String str, Optilog instance) throws IOException { 54 | if (!str.isBlank()) { 55 | if (str.startsWith("%json -cp")) { 56 | JsonSettings.getJsonSettings(str.substring(10), true, instance); 57 | return; 58 | } 59 | 60 | if (str.startsWith("%json ")) { 61 | JsonSettings.getJsonSettings(str.substring(6), false, instance); 62 | return; 63 | } 64 | if (str.startsWith("%xml -cp ")) { 65 | XmlSettings.xml(str.substring(9), true, instance); 66 | return; 67 | } 68 | if (str.startsWith("%xml ")) { 69 | XmlSettings.xml(str.substring(5), false, instance); 70 | return; 71 | } 72 | if (str.startsWith("%prop -cp ")) { 73 | String s = str.substring(10); 74 | if (!s.startsWith("/") && !s.startsWith("\\")) { 75 | s = "/" + s; 76 | } 77 | try (InputStream input = Optilog.class.getResourceAsStream(s)) { 78 | if (input == null) { 79 | instance.consoleFileMasterCaution = false; 80 | System.err.println("[Optilog-Client] Optilog Note: Can't find '" + s + "' in classpath."); 81 | throw new ConfigureException("[Optilog-Client] Can't find '" + s + "' in classpath."); 82 | } 83 | PropSettings.properties(input, instance); 84 | return; 85 | } 86 | } 87 | if (str.startsWith("%prop ")) { 88 | String s = str.substring(6); 89 | try (InputStream input = new FileInputStream(s)) { 90 | PropSettings.properties(input, instance); 91 | return; 92 | } 93 | } 94 | if (str.startsWith("%yaml -cp ")) { 95 | YamlSettings.yaml(str.substring(10), true, instance); 96 | return; 97 | } 98 | if (str.startsWith("%yaml ")) { 99 | YamlSettings.yaml(str.substring(6), false, instance); 100 | return; 101 | } 102 | instance.consoleFileMasterCaution = false; 103 | System.err.println("[Optilog-Client] Argument illegal or that Configure file not be supported"); 104 | } 105 | } 106 | 107 | @OnlyInInit 108 | public static String readAsString(InputStream input) throws IOException { 109 | int n; 110 | StringBuilder sb = new StringBuilder(); 111 | while ((n = input.read()) != -1) { 112 | sb.append((char) n); 113 | } 114 | return sb.toString(); 115 | } 116 | 117 | public static void generateJsonSettings(String path) { 118 | File f = new File(path + "//Setting.json"); 119 | try { 120 | if (!f.createNewFile()) { 121 | throw new IOException(); 122 | } 123 | } catch (IOException e) { 124 | e.printStackTrace(); 125 | } 126 | try { 127 | Files.writeString(f.toPath(), "{\n" + 128 | " \"print\": {\n" + 129 | " \"info\": \"true\",\n" + 130 | " \"error\": \"true\",\n" + 131 | " \"warn\": \"true\",\n" + 132 | " \"debug\": \"true\",\n" + 133 | " \"fatal\": \"true\",\n" + 134 | " \"packingFormat\": \"[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg\"\n" + 135 | " },\n" + 136 | " \"file\": {\n" + 137 | " \"info\": \"true\",\n" + 138 | " \"error\": \"true\",\n" + 139 | " \"warn\": \"true\",\n" + 140 | " \"debug\": \"true\",\n" + 141 | " \"fatal\": \"true\",\n" + 142 | " \"defaultConsolePath\": \"./src/test/resources/logs\",\n" + 143 | " \"fileName\": \"%time-Log(Json).log\",\n" + 144 | " \"packingFormat\": \"[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg\"\n" + 145 | " },\n" + 146 | " \"server\": {\n" + 147 | " \"info\": \"true\",\n" + 148 | " \"error\": \"true\",\n" + 149 | " \"warn\": \"true\",\n" + 150 | " \"debug\": \"true\",\n" + 151 | " \"fatal\": \"true\",\n" + 152 | " \"startClient\": \"false\",\n" + 153 | " \"socketNumber\": \"65535\",\n" + 154 | " \"host\": \"localhost\",\n" + 155 | " \"packingFormat\": \"[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg\",\n" + 156 | " \"forceDisableSocketWhenException\": \"true\"\n" + 157 | " }\n" + 158 | "}", StandardCharsets.UTF_8); 159 | } catch (IOException e) { 160 | e.printStackTrace(); 161 | } 162 | } 163 | 164 | public static void generatePropertiesSettings(String path) { 165 | File f = new File(path + "//Setting.properties"); 166 | try { 167 | if (!f.createNewFile()) { 168 | throw new IOException(); 169 | } 170 | } catch (IOException e) { 171 | e.printStackTrace(); 172 | } 173 | try { 174 | Files.writeString(f.toPath(), "# print\n" + 175 | "print.info=true\n" + 176 | "print.error=true\n" + 177 | "print.warn=true\n" + 178 | "print.debug=true\n" + 179 | "print.fatal=true\n" + 180 | "print.packingFormat=[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg\n" + 181 | "# file\n" + 182 | "file.defaultConsolePath=./src/test/resources/logs\n" + 183 | "#file.Path1=D:\\\\Program\\\\Project\\\\resources\\\\app\\\\Git\\\\Projects\\\\Optilog-Client\\\\src\\\\test\\\\resources\n" + 184 | "#file.infoPath=%path1\n" + 185 | "#file.debugPath=%path1\n" + 186 | "#file.warnPath=%path1\n" + 187 | "file.consoleInfo=true\n" + 188 | "file.consoleDebug=true\n" + 189 | "file.consoleError=true\n" + 190 | "file.consoleWarn=true\n" + 191 | "file.consoleFatal=true\n" + 192 | "file.fileName=%time-Log(Properties).log\n" + 193 | "file.packingFormat=[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg\n" + 194 | "# server\n" + 195 | "server.infoSendToServer=true\n" + 196 | "server.errorSendToServer=true\n" + 197 | "server.warnSendToServer=true\n" + 198 | "server.debugSendToServer=true\n" + 199 | "server.fatalSendToServer=true\n" + 200 | "server.startClient=false\n" + 201 | "server.socketNumber=65535\n" + 202 | "server.packingFormat=[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg\n" + 203 | "server.host=localhost\n" + 204 | "server.forceDisableSocketWhenException=true", StandardCharsets.UTF_8); 205 | } catch (IOException e) { 206 | e.printStackTrace(); 207 | } 208 | } 209 | 210 | public static void generateXmlSettings(String path) { 211 | File f = new File(path + "//Setting.xml"); 212 | try { 213 | if (!f.createNewFile()) { 214 | throw new IOException(); 215 | } 216 | } catch (IOException e) { 217 | e.printStackTrace(); 218 | } 219 | try { 220 | Files.writeString(f.toPath(), "\n" + 221 | "\n" + 222 | " \n" + 223 | " true\n" + 224 | " true\n" + 225 | " true\n" + 226 | " true\n" + 227 | " true\n" + 228 | "\n" + 229 | " \n" + 230 | " [%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg\n" + 231 | " \n" + 232 | " \n" + 233 | "\n" + 234 | " \n" + 235 | " true\n" + 236 | " true\n" + 237 | " true\n" + 238 | " true\n" + 239 | " true\n" + 240 | "\n" + 241 | " \n" + 242 | " ./src/test/resources/logs\n" + 243 | " \n" + 244 | "\n" + 245 | " %time-Log(Xml).log\n" + 246 | " \n" + 247 | " [%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg\n" + 248 | " \n" + 249 | " \n" + 250 | "\n" + 251 | " \n" + 252 | " true\n" + 253 | " true\n" + 254 | " true\n" + 255 | " true\n" + 256 | " true\n" + 257 | "\n" + 258 | " false\n" + 259 | " localhost\n" + 260 | " 65535\n" + 261 | " \n" + 262 | " [%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg\n" + 263 | " \n" + 264 | " true\n" + 265 | " \n" + 266 | "", StandardCharsets.UTF_8); 267 | } catch (IOException e) { 268 | e.printStackTrace(); 269 | } 270 | } 271 | 272 | public static void generateYamlSettings(String path) { 273 | File f = new File(path + "//Setting.yaml"); 274 | try { 275 | if (!f.createNewFile()) { 276 | throw new IOException(); 277 | } 278 | } catch (IOException e) { 279 | e.printStackTrace(); 280 | } 281 | try { 282 | Files.writeString(f.toPath(), "info:\n" + 283 | " print: \"true\"\n" + 284 | " console: \"true\"\n" + 285 | " server: \"true\"\n" + 286 | "error:\n" + 287 | " print: \"true\"\n" + 288 | " console: \"true\"\n" + 289 | " server: \"true\"\n" + 290 | "warn:\n" + 291 | " print: \"true\"\n" + 292 | " console: \"true\"\n" + 293 | " server: \"true\"\n" + 294 | "debug:\n" + 295 | " print: \"true\"\n" + 296 | " console: \"true\"\n" + 297 | " server: \"true\"\n" + 298 | "fatal:\n" + 299 | " print: \"true\"\n" + 300 | " console: \"true\"\n" + 301 | " server: \"true\"\n" + 302 | "print:\n" + 303 | " packingFormat: \"[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg\"\n" + 304 | "file:\n" + 305 | " defaultConsolePath: \"./src/test/resources/logs\"\n" + 306 | " fileName: \"%time-Log(Yaml).log\"\n" + 307 | " packingFormat: \"[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg\"\n" + 308 | "server:\n" + 309 | " startClient: \"false\"\n" + 310 | " socketNumber: \"65535\"\n" + 311 | " host: \"localhost\"\n" + 312 | " packingFormat: \"[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg\"\n" + 313 | " forceDisableSocketWhenException: \"true\"", StandardCharsets.UTF_8); 314 | } catch (IOException e) { 315 | e.printStackTrace(); 316 | } 317 | } 318 | } 319 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/setting/XmlSettingBean.java: -------------------------------------------------------------------------------- 1 | package com.optilog.setting; 2 | 3 | import com.optilog.util.OnlyInInit; 4 | 5 | import java.util.Map; 6 | 7 | public class XmlSettingBean { 8 | public Map print; 9 | 10 | public Map file; 11 | 12 | public Map server; 13 | 14 | @OnlyInInit 15 | public XmlSettingBean() { 16 | 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/setting/XmlSettings.java: -------------------------------------------------------------------------------- 1 | package com.optilog.setting; 2 | 3 | import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; 4 | import com.fasterxml.jackson.dataformat.xml.XmlMapper; 5 | import com.optilog.log.Optilog; 6 | import com.optilog.util.OnlyInInit; 7 | 8 | import java.io.File; 9 | import java.io.FileInputStream; 10 | import java.io.IOException; 11 | import java.io.InputStream; 12 | 13 | public class XmlSettings { 14 | /** 15 | * Parse XML file to JavaBean use Jackson-fasterxml 16 | */ 17 | @OnlyInInit 18 | static void xml(String path, boolean isClasspath, Optilog instance) { 19 | if (isClasspath && (!path.startsWith("/") && !path.startsWith("\\"))) { 20 | path = File.separator + path; 21 | } 22 | if (isClasspath) { 23 | // read in classpath 24 | try (InputStream input = Optilog.class.getResourceAsStream(path)) { 25 | parseSettings(instance, input); 26 | } catch (IOException e) { 27 | System.err.println("Optilog Note: Failed to read xml setting file!"); 28 | instance.consoleFileMasterCaution = false; 29 | e.printStackTrace(); 30 | } 31 | } else { 32 | try (InputStream input = new FileInputStream(path)) { 33 | parseSettings(instance, input); 34 | } catch (IOException e) { 35 | System.err.println("Optilog Note: Failed to read xml setting file!"); 36 | instance.consoleFileMasterCaution = false; 37 | e.printStackTrace(); 38 | } 39 | } 40 | } 41 | 42 | private static void parseSettings(Optilog instance, InputStream input) throws IOException { 43 | XmlSettingBean object = new XmlMapper(new JacksonXmlModule()).readValue(input, XmlSettingBean.class); 44 | try { 45 | // config print 46 | String a = object.print.get("packingFormat"); 47 | if (a != null) { 48 | instance.allSetting.printPackingFormat = a.trim(); 49 | } 50 | instance.allSetting.printInfo = Boolean.parseBoolean(object.print.get("printInfo").trim()); 51 | instance.allSetting.printError = Boolean.parseBoolean(object.print.get("printError").trim()); 52 | instance.allSetting.printWarn = Boolean.parseBoolean(object.print.get("printWarn").trim()); 53 | instance.allSetting.printDebug = Boolean.parseBoolean(object.print.get("printDebug").trim()); 54 | instance.allSetting.printFatal = Boolean.parseBoolean(object.print.get("printFatal").trim()); 55 | } catch (NullPointerException ignored) { 56 | } 57 | 58 | try { 59 | // config file 60 | String b = object.file.get("packingFormat"); 61 | if (b != null) { 62 | instance.allSetting.consolePackingFormat = b.trim(); 63 | } 64 | String c = object.file.get("defaultConsolePath"); 65 | if (c != null) { 66 | instance.allSetting.defaultConsolePath = c.trim(); 67 | } 68 | String d = object.file.get("Path1"); 69 | if (d != null) { 70 | instance.allSetting.Path1 = d.trim(); 71 | } 72 | String e = object.file.get("Path2"); 73 | if (e != null) { 74 | instance.allSetting.Path2 = e.trim(); 75 | } 76 | String f = object.file.get("Path3"); 77 | if (f != null) { 78 | instance.allSetting.Path3 = f.trim(); 79 | } 80 | String g = object.file.get("Path4"); 81 | if (g != null) { 82 | instance.allSetting.Path4 = g.trim(); 83 | } 84 | String h = object.file.get("Path5"); 85 | if (h != null) { 86 | instance.allSetting.Path5 = h.trim(); 87 | } 88 | String i = object.file.get("infoPath"); 89 | if (i != null) { 90 | instance.allSetting.infoPath = i.trim(); 91 | } 92 | String j = object.file.get("errorPath"); 93 | if (j != null) { 94 | instance.allSetting.errorPath = j.trim(); 95 | } 96 | String k = object.file.get("warnPath"); 97 | if (k != null) { 98 | instance.allSetting.warnPath = k.trim(); 99 | } 100 | String l = object.file.get("debugPath"); 101 | if (l != null) { 102 | instance.allSetting.debugPath = l.trim(); 103 | } 104 | String m = object.file.get("fatalPath"); 105 | if (m != null) { 106 | instance.allSetting.fatalPath = m.trim(); 107 | } 108 | String n = (object.file.get("fileName")); 109 | if (n != null) { 110 | instance.allSetting.fileName = n.trim(); 111 | } 112 | instance.allSetting.consoleInfo = Boolean.parseBoolean(object.file.get("consoleInfo").trim()); 113 | instance.allSetting.consoleError = Boolean.parseBoolean(object.file.get("consoleError").trim()); 114 | instance.allSetting.consoleWarn = Boolean.parseBoolean(object.file.get("consoleWarn").trim()); 115 | instance.allSetting.consoleDebug = Boolean.parseBoolean(object.file.get("consoleDebug").trim()); 116 | instance.allSetting.consoleFatal = Boolean.parseBoolean(object.file.get("consoleFatal").trim()); 117 | } catch (NullPointerException ignored) { 118 | } 119 | 120 | try { 121 | // config server 122 | String o = object.server.get("packingFormat"); 123 | if (o != null) { 124 | instance.allSetting.serverPackingFormat = o.trim(); 125 | } 126 | instance.allSetting.serverInfo = Boolean.parseBoolean(object.server.get("serverInfo").trim()); 127 | instance.allSetting.serverError = Boolean.parseBoolean(object.server.get("serverError").trim()); 128 | instance.allSetting.serverWarn = Boolean.parseBoolean(object.server.get("serverWarn").trim()); 129 | instance.allSetting.serverDebug = Boolean.parseBoolean(object.server.get("serverDebug").trim()); 130 | instance.allSetting.serverFatal = Boolean.parseBoolean(object.server.get("serverFatal").trim()); 131 | instance.allSetting.startClient = Boolean.parseBoolean(object.server.get("startClient").trim()); 132 | String p = object.server.get("host"); 133 | if (p != null) { 134 | instance.allSetting.host = p.trim(); 135 | } 136 | String q = object.server.get("socketNumber"); 137 | if (q != null) { 138 | try { 139 | instance.allSetting.socketNumber = Integer.parseInt(q.trim()); 140 | } catch (NumberFormatException e) { 141 | System.err.println("Optilog Note: NumberFormatException"); 142 | e.printStackTrace(); 143 | } 144 | } 145 | String r = object.server.get("forceDisableSocketWhenException"); 146 | if (q != null) { 147 | try { 148 | instance.allSetting.forceDisableSocketWhenException = Boolean.parseBoolean(r); 149 | } catch (NumberFormatException e) { 150 | System.err.println("Optilog Note: NumberFormatException"); 151 | e.printStackTrace(); 152 | } 153 | } 154 | } catch (NullPointerException ignored) { 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/setting/YamlSettings.java: -------------------------------------------------------------------------------- 1 | package com.optilog.setting; 2 | 3 | import com.optilog.log.Optilog; 4 | import com.optilog.util.exception.ConfigureException; 5 | import org.yaml.snakeyaml.Yaml; 6 | 7 | import java.io.File; 8 | import java.io.FileInputStream; 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | import java.util.LinkedHashMap; 12 | import java.util.Map; 13 | 14 | public class YamlSettings { 15 | public static void yaml(String path, boolean isClasspath, Optilog instance) { 16 | if (isClasspath && (!path.startsWith("/") && !path.startsWith("\\"))) { 17 | path = File.separator + path; 18 | } 19 | 20 | final String PRINT = "print"; 21 | final String CONSOLE = "console"; 22 | final String FILE = "file"; 23 | final String SERVER = "server"; 24 | final String PACKING_FORMAT = "packingFormat"; 25 | 26 | Map> map; 27 | if (!isClasspath) { 28 | try (InputStream input = new FileInputStream(path)) { 29 | Yaml yaml = new Yaml(); 30 | map = yaml.load(input); 31 | } catch (IOException e) { 32 | instance.consoleFileMasterCaution = false; 33 | throw new ConfigureException("Can't find'" + path + "'.", e); 34 | } 35 | 36 | } else { 37 | try (InputStream input = Optilog.class.getResourceAsStream(path)) { 38 | Yaml yaml = new Yaml(); 39 | map = yaml.load(input); 40 | } catch (IOException e) { 41 | instance.consoleFileMasterCaution = false; 42 | throw new ConfigureException("Can't find'" + path + "'.", e); 43 | } 44 | } 45 | 46 | LinkedHashMap lInfo = map.get("info"); 47 | LinkedHashMap lError = map.get("error"); 48 | LinkedHashMap lDebug = map.get("debug"); 49 | LinkedHashMap lFatal = map.get("fatal"); 50 | LinkedHashMap lWarn = map.get("warn"); 51 | try { 52 | instance.allSetting.printInfo = Boolean.parseBoolean(lInfo.get(PRINT)); 53 | instance.allSetting.printError = Boolean.parseBoolean(lError.get(PRINT)); 54 | instance.allSetting.printWarn = Boolean.parseBoolean(lWarn.get(PRINT)); 55 | instance.allSetting.printDebug = Boolean.parseBoolean(lDebug.get(PRINT)); 56 | instance.allSetting.printFatal = Boolean.parseBoolean(lFatal.get(PRINT)); 57 | String print$packingFormat = map.get(PRINT).get(PACKING_FORMAT); 58 | if (print$packingFormat != null) { 59 | instance.allSetting.printPackingFormat = print$packingFormat; 60 | } 61 | } catch (NullPointerException ignored) { 62 | } 63 | 64 | try { 65 | instance.allSetting.consoleInfo = Boolean.parseBoolean(lInfo.get(CONSOLE)); 66 | instance.allSetting.consoleError = Boolean.parseBoolean(lError.get(CONSOLE)); 67 | instance.allSetting.consoleDebug = Boolean.parseBoolean(lDebug.get(CONSOLE)); 68 | instance.allSetting.consoleWarn = Boolean.parseBoolean(lWarn.get(CONSOLE)); 69 | instance.allSetting.consoleFatal = Boolean.parseBoolean(lFatal.get(CONSOLE)); 70 | String file$defaultConsolePath = map.get(FILE).get("defaultConsolePath"); 71 | if (file$defaultConsolePath != null) { 72 | instance.allSetting.defaultConsolePath = file$defaultConsolePath; 73 | } 74 | String file$Path1 = map.get(FILE).get("Path1"); 75 | if (file$Path1 != null) { 76 | instance.allSetting.Path1 = file$Path1; 77 | } 78 | String file$Path2 = map.get(FILE).get("Path2"); 79 | if (file$Path2 != null) { 80 | instance.allSetting.Path2 = file$Path2; 81 | } 82 | String file$Path3 = map.get(FILE).get("Path3"); 83 | if (file$Path3 != null) { 84 | instance.allSetting.Path3 = file$Path3; 85 | } 86 | String file$Path4 = map.get(FILE).get("Path4"); 87 | if (file$Path4 != null) { 88 | instance.allSetting.Path4 = file$Path4; 89 | } 90 | String file$Path5 = map.get(FILE).get("Path5"); 91 | if (file$Path5 != null) { 92 | instance.allSetting.Path5 = file$Path5; 93 | } 94 | String file$packingFormat = map.get(FILE).get(PACKING_FORMAT); 95 | if (file$packingFormat != null) { 96 | instance.allSetting.consolePackingFormat = file$packingFormat; 97 | } 98 | String file$infoPath = map.get(FILE).get("infoPath"); 99 | if (file$infoPath != null) { 100 | instance.allSetting.infoPath = file$infoPath; 101 | } 102 | String file$errorPath = map.get(FILE).get("errorPath"); 103 | if (file$errorPath != null) { 104 | instance.allSetting.errorPath = file$errorPath; 105 | } 106 | String file$warnPath = map.get(FILE).get("warnPath"); 107 | if (file$warnPath != null) { 108 | instance.allSetting.warnPath = file$warnPath; 109 | } 110 | String file$debugPath = map.get(FILE).get("debugPath"); 111 | if (file$debugPath != null) { 112 | instance.allSetting.debugPath = file$debugPath; 113 | } 114 | String file$fatalPath = map.get(FILE).get("fatalPath"); 115 | if (file$fatalPath != null) { 116 | instance.allSetting.fatalPath = file$fatalPath; 117 | } 118 | String file$fileName = map.get(FILE).get("fileName"); 119 | if (file$fileName != null) { 120 | instance.allSetting.fileName = file$fileName; 121 | } 122 | } catch (NullPointerException ignored) { 123 | } 124 | 125 | try { 126 | instance.allSetting.serverInfo = Boolean.parseBoolean(lInfo.get(SERVER)); 127 | instance.allSetting.serverError = Boolean.parseBoolean(lError.get(SERVER)); 128 | instance.allSetting.serverWarn = Boolean.parseBoolean(lWarn.get(SERVER)); 129 | instance.allSetting.serverDebug = Boolean.parseBoolean(lDebug.get(SERVER)); 130 | instance.allSetting.serverFatal = Boolean.parseBoolean(lFatal.get(SERVER)); 131 | String server$packingFormat = map.get(SERVER).get(PACKING_FORMAT); 132 | if (server$packingFormat != null) { 133 | instance.allSetting.serverPackingFormat = server$packingFormat; 134 | } 135 | instance.allSetting.startClient = Boolean.parseBoolean(map.get(SERVER).get("startClient")); 136 | 137 | String server$host = map.get(SERVER).get("host"); 138 | if (server$host != null) { 139 | instance.allSetting.host = server$host; 140 | } 141 | 142 | try { 143 | int server$socketNumber = Integer.parseInt(map.get(SERVER).get("socketNumber")); 144 | if (server$socketNumber != 0) { 145 | instance.allSetting.socketNumber = server$socketNumber; 146 | } 147 | } catch (NullPointerException ignored) { 148 | } 149 | instance.allSetting.forceDisableSocketWhenException = Boolean.parseBoolean(map.get(SERVER).get("forceDisableSocketWhenException")); 150 | } catch (NullPointerException ignored) { 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/util/LambdaExecute.java: -------------------------------------------------------------------------------- 1 | package com.optilog.util; 2 | 3 | @FunctionalInterface 4 | public interface LambdaExecute { 5 | Object execute(); 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/util/OnlyInInit.java: -------------------------------------------------------------------------------- 1 | package com.optilog.util; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Documented 6 | @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) 7 | @Retention(RetentionPolicy.SOURCE) 8 | public @interface OnlyInInit { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/util/OnlyInLog.java: -------------------------------------------------------------------------------- 1 | package com.optilog.util; 2 | 3 | import java.lang.annotation.*; 4 | 5 | @Documented 6 | @Target({ElementType.METHOD, ElementType.CONSTRUCTOR}) 7 | @Retention(RetentionPolicy.SOURCE) 8 | public @interface OnlyInLog { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/util/Util.java: -------------------------------------------------------------------------------- 1 | package com.optilog.util; 2 | 3 | import java.io.PrintStream; 4 | 5 | public class Util { 6 | private static final PrintStream output = System.out; 7 | 8 | @OnlyInInit 9 | @OnlyInLog 10 | public static PrintStream getOutput() { 11 | return output; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/util/exception/ConfigureException.java: -------------------------------------------------------------------------------- 1 | package com.optilog.util.exception; 2 | 3 | public final class ConfigureException extends OptilogException { 4 | public ConfigureException() { 5 | super(); 6 | } 7 | 8 | public ConfigureException(String msg) { 9 | super(msg); 10 | } 11 | 12 | public ConfigureException(Throwable th) { 13 | super(th); 14 | } 15 | 16 | public ConfigureException(String msg, Throwable th) { 17 | super(msg, th); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/util/exception/InvalidCommandException.java: -------------------------------------------------------------------------------- 1 | package com.optilog.util.exception; 2 | 3 | public final class InvalidCommandException extends OptilogException { 4 | public InvalidCommandException() { 5 | } 6 | 7 | public InvalidCommandException(String message, Throwable cause) { 8 | super(message, cause); 9 | } 10 | 11 | public InvalidCommandException(String message) { 12 | super(message); 13 | } 14 | 15 | public InvalidCommandException(Throwable cause) { 16 | super(cause); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/util/exception/OptilogException.java: -------------------------------------------------------------------------------- 1 | package com.optilog.util.exception; 2 | 3 | public class OptilogException extends RuntimeException { 4 | public OptilogException() { 5 | } 6 | 7 | public OptilogException(String message, Throwable cause) { 8 | super(message, cause); 9 | } 10 | 11 | public OptilogException(String message) { 12 | super(message); 13 | } 14 | 15 | public OptilogException(Throwable cause) { 16 | super(cause); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/util/tools/Assert.java: -------------------------------------------------------------------------------- 1 | package com.optilog.util.tools; 2 | 3 | import java.util.Objects; 4 | 5 | public class Assert { 6 | public static void assertTrue(boolean astTrue) { 7 | if (!astTrue) { 8 | throw new AssertionError("Assert failed:" + false); 9 | } 10 | } 11 | 12 | public static void assertFalse(boolean astFalse) { 13 | if (astFalse) { 14 | throw new AssertionError("Assert failed:" + true); 15 | } 16 | } 17 | 18 | public static void assertEquals(Object value, Object assertValue) { 19 | if (!Objects.equals(value, assertValue)) { 20 | throw new AssertionError("Assert failed:expect " + assertValue + " but actually " + value); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/com/optilog/util/tools/LocalField.java: -------------------------------------------------------------------------------- 1 | package com.optilog.util.tools; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class LocalField { 7 | private static final Map map = new HashMap<>(); 8 | 9 | public static void addField(Object fieldName, Object value) { 10 | LocalField.map.put(fieldName, value); 11 | } 12 | 13 | public static Object getField(Object fieldName) { 14 | return LocalField.map.get(fieldName); 15 | } 16 | 17 | public static void removeField(Object key) { 18 | LocalField.map.remove(key); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/module-info.java: -------------------------------------------------------------------------------- 1 | module com.optilog { 2 | exports com.optilog.log; 3 | exports com.optilog.util; 4 | exports com.optilog.log.jdbc; 5 | exports com.optilog.setting; 6 | 7 | requires java.sql; 8 | requires com.google.gson; 9 | requires com.fasterxml.jackson.dataformat.xml; 10 | requires org.yaml.snakeyaml; 11 | } -------------------------------------------------------------------------------- /src/test/java/com/optilog/JsonClassPathOptilogTest.java: -------------------------------------------------------------------------------- 1 | package com.optilog; 2 | 3 | import com.optilog.log.Log; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.File; 7 | 8 | /** 9 | * Optilog测试类 10 | */ 11 | public class JsonClassPathOptilogTest { 12 | @Test 13 | void test() { 14 | Log log = Log.initLog("%json -cp /Settings.json"); 15 | 16 | log.info("========测试开始========"); 17 | 18 | // info常规测试 19 | log.info("info常规测试:"); 20 | log.info(); 21 | log.info(new Object()); 22 | log.info("String Test"); 23 | log.info((char[]) null); 24 | log.info((Object) null); 25 | log.info((String) null); 26 | log.info(new char['a']); 27 | log.info(2324); 28 | log.info(382845 * (32 + 444)); 29 | log.info(Float.MAX_VALUE); 30 | log.info(Double.MAX_VALUE); 31 | log.info(Long.MAX_VALUE); 32 | 33 | // error常规测试 34 | log.error("error常规测试:"); 35 | log.error(); 36 | log.error(new Object()); 37 | log.error("String Test"); 38 | log.error((char[]) null); 39 | log.error((Object) null); 40 | log.error((String) null); 41 | log.error(new char['a']); 42 | log.error(2324); 43 | log.error(6624224 * 42); 44 | log.error(Float.MAX_VALUE); 45 | log.error(Double.MAX_VALUE); 46 | log.error(Long.MAX_VALUE); 47 | 48 | // warn常规测试 49 | log.warn("warn常规测试:"); 50 | log.warn(); 51 | log.warn(new Object()); 52 | log.warn("String Test"); 53 | log.warn((char[]) null); 54 | log.warn((Object) null); 55 | log.warn((String) null); 56 | log.warn(new char['a']); 57 | log.warn(2324); 58 | log.warn(6624224 * 42); 59 | log.warn(Float.MAX_VALUE); 60 | log.warn(Double.MAX_VALUE); 61 | log.warn(Long.MAX_VALUE); 62 | 63 | // fatal常规测试 64 | log.fatal("fatal常规测试:"); 65 | log.fatal(); 66 | log.fatal(new Object()); 67 | log.fatal("String Test"); 68 | log.fatal((char[]) null); 69 | log.fatal((Object) null); 70 | log.fatal((String) null); 71 | log.fatal(new char['a']); 72 | log.fatal(2324); 73 | log.fatal(6624224 * 42); 74 | log.fatal(Float.MAX_VALUE); 75 | log.fatal(Double.MAX_VALUE); 76 | log.fatal(Long.MAX_VALUE); 77 | 78 | // debug常规测试 79 | log.debug("debug常规测试:"); 80 | log.debug(); 81 | log.debug(new Object()); 82 | log.debug("String Test"); 83 | log.debug((char[]) null); 84 | log.debug((Object) null); 85 | log.debug((String) null); 86 | log.debug(new char['a']); 87 | log.debug(2324); 88 | log.debug(6624224 * 42); 89 | log.debug(Float.MAX_VALUE); 90 | log.debug(Double.MAX_VALUE); 91 | log.debug(Long.MAX_VALUE); 92 | 93 | // 变化栈测试 94 | log.info("变化栈信息测试:"); 95 | stackTest(log); 96 | 97 | // 变化线程测试 98 | log.info("变化线程测试:"); 99 | new Thread(() -> { 100 | log.info("1"); 101 | log.error("2"); 102 | log.warn("3"); 103 | log.debug("4"); 104 | log.fatal("5"); 105 | log.info("6"); 106 | log.error("7"); 107 | log.warn("8"); 108 | log.debug("9"); 109 | log.fatal("10"); 110 | }).start(); 111 | log.info("1(N)"); 112 | log.error("2(N)"); 113 | log.warn("3(N)"); 114 | log.debug("4(N)"); 115 | log.fatal("5(N)"); 116 | log.info("6(N)"); 117 | log.error("7(N)"); 118 | log.warn("8(N)"); 119 | log.debug("9(N)"); 120 | log.fatal("10(N)"); 121 | 122 | // 运行期配置变化测试 123 | log.info("运行期配置文件变化测试:"); 124 | log.setPrintInfo(false); 125 | log.info("This log will not be print."); 126 | log.setPrintInfo(true); 127 | log.setConsoleInfo(false); 128 | log.info("This log will not be console."); 129 | log.setConsoleInfo(true); 130 | 131 | log.info(new File(".").getAbsolutePath()); 132 | } 133 | 134 | public static void stackTest(Log log) { 135 | log.info("Stack Test"); 136 | log.error("Stack Test"); 137 | log.warn("Stack Test"); 138 | log.debug("Stack Test"); 139 | log.fatal("Stack Test"); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/test/java/com/optilog/JsonPathOptilogTest.java: -------------------------------------------------------------------------------- 1 | package com.optilog; 2 | 3 | import com.optilog.log.Log; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.File; 7 | 8 | public class JsonPathOptilogTest { 9 | @Test 10 | void test() { 11 | Log log = Log.initLog("%json ./src/test/resources/Settings.json"); 12 | 13 | log.info("========测试开始========"); 14 | 15 | // info常规测试 16 | log.info("info常规测试:"); 17 | log.info(); 18 | log.info(new Object()); 19 | log.info("String Test"); 20 | log.info((char[]) null); 21 | log.info((Object) null); 22 | log.info((String) null); 23 | log.info(new char['a']); 24 | log.info(2324); 25 | log.info(382845 * (32 + 444)); 26 | log.info(Float.MAX_VALUE); 27 | log.info(Double.MAX_VALUE); 28 | log.info(Long.MAX_VALUE); 29 | 30 | // error常规测试 31 | log.error("error常规测试:"); 32 | log.error(); 33 | log.error(new Object()); 34 | log.error("String Test"); 35 | log.error((char[]) null); 36 | log.error((Object) null); 37 | log.error((String) null); 38 | log.error(new char['a']); 39 | log.error(2324); 40 | log.error(6624224 * 42); 41 | log.error(Float.MAX_VALUE); 42 | log.error(Double.MAX_VALUE); 43 | log.error(Long.MAX_VALUE); 44 | 45 | // warn常规测试 46 | log.warn("warn常规测试:"); 47 | log.warn(); 48 | log.warn(new Object()); 49 | log.warn("String Test"); 50 | log.warn((char[]) null); 51 | log.warn((Object) null); 52 | log.warn((String) null); 53 | log.warn(new char['a']); 54 | log.warn(2324); 55 | log.warn(6624224 * 42); 56 | log.warn(Float.MAX_VALUE); 57 | log.warn(Double.MAX_VALUE); 58 | log.warn(Long.MAX_VALUE); 59 | 60 | // fatal常规测试 61 | log.fatal("fatal常规测试:"); 62 | log.fatal(); 63 | log.fatal(new Object()); 64 | log.fatal("String Test"); 65 | log.fatal((char[]) null); 66 | log.fatal((Object) null); 67 | log.fatal((String) null); 68 | log.fatal(new char['a']); 69 | log.fatal(2324); 70 | log.fatal(6624224 * 42); 71 | log.fatal(Float.MAX_VALUE); 72 | log.fatal(Double.MAX_VALUE); 73 | log.fatal(Long.MAX_VALUE); 74 | 75 | // debug常规测试 76 | log.debug("debug常规测试:"); 77 | log.debug(); 78 | log.debug(new Object()); 79 | log.debug("String Test"); 80 | log.debug((char[]) null); 81 | log.debug((Object) null); 82 | log.debug((String) null); 83 | log.debug(new char['a']); 84 | log.debug(2324); 85 | log.debug(6624224 * 42); 86 | log.debug(Float.MAX_VALUE); 87 | log.debug(Double.MAX_VALUE); 88 | log.debug(Long.MAX_VALUE); 89 | 90 | // 变化栈测试 91 | log.info("变化栈信息测试:"); 92 | stackTest(log); 93 | 94 | // 变化线程测试 95 | log.info("变化线程测试:"); 96 | new Thread(() -> { 97 | log.info("1"); 98 | log.error("2"); 99 | log.warn("3"); 100 | log.debug("4"); 101 | log.fatal("5"); 102 | log.info("6"); 103 | log.error("7"); 104 | log.warn("8"); 105 | log.debug("9"); 106 | log.fatal("10"); 107 | }).start(); 108 | log.info("1(N)"); 109 | log.error("2(N)"); 110 | log.warn("3(N)"); 111 | log.debug("4(N)"); 112 | log.fatal("5(N)"); 113 | log.info("6(N)"); 114 | log.error("7(N)"); 115 | log.warn("8(N)"); 116 | log.debug("9(N)"); 117 | log.fatal("10(N)"); 118 | 119 | // 运行期配置变化测试 120 | log.info("运行期配置文件变化测试:"); 121 | log.setPrintInfo(false); 122 | log.info("This log will not be print."); 123 | log.setPrintInfo(true); 124 | log.setConsoleInfo(false); 125 | log.info("This log will not be console."); 126 | log.setConsoleInfo(true); 127 | 128 | log.info(new File(".").getAbsolutePath()); 129 | } 130 | 131 | public static void stackTest(Log log) { 132 | log.info("Stack Test"); 133 | log.error("Stack Test"); 134 | log.warn("Stack Test"); 135 | log.debug("Stack Test"); 136 | log.fatal("Stack Test"); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/test/java/com/optilog/PerformanceTester.java: -------------------------------------------------------------------------------- 1 | package com.optilog; 2 | 3 | import com.optilog.log.Log; 4 | 5 | public class PerformanceTester { 6 | private static final Log LOGGER = Log.initLog("%yaml -cp /Settings.yaml"); 7 | 8 | public static void main(String[] args) { 9 | long startTime = System.currentTimeMillis(); 10 | LOGGER.info(); 11 | long stopTime = System.currentTimeMillis(); 12 | System.out.println(stopTime - startTime); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/com/optilog/PropertiesClassPathOptilogTest.java: -------------------------------------------------------------------------------- 1 | package com.optilog; 2 | 3 | import com.optilog.log.Log; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.File; 7 | 8 | public class PropertiesClassPathOptilogTest { 9 | @Test 10 | void test() { 11 | Log log = Log.initLog("%prop -cp /Settings.properties"); 12 | 13 | log.info("========测试开始========"); 14 | 15 | // info常规测试 16 | log.info("info常规测试:"); 17 | log.info(); 18 | log.info(new Object()); 19 | log.info("String Test"); 20 | log.info((char[]) null); 21 | log.info((Object) null); 22 | log.info((String) null); 23 | log.info(new char['a']); 24 | log.info(2324); 25 | log.info(382845 * (32 + 444)); 26 | log.info(Float.MAX_VALUE); 27 | log.info(Double.MAX_VALUE); 28 | log.info(Long.MAX_VALUE); 29 | 30 | // error常规测试 31 | log.error("error常规测试:"); 32 | log.error(); 33 | log.error(new Object()); 34 | log.error("String Test"); 35 | log.error((char[]) null); 36 | log.error((Object) null); 37 | log.error((String) null); 38 | log.error(new char['a']); 39 | log.error(2324); 40 | log.error(6624224 * 42); 41 | log.error(Float.MAX_VALUE); 42 | log.error(Double.MAX_VALUE); 43 | log.error(Long.MAX_VALUE); 44 | 45 | // warn常规测试 46 | log.warn("warn常规测试:"); 47 | log.warn(); 48 | log.warn(new Object()); 49 | log.warn("String Test"); 50 | log.warn((char[]) null); 51 | log.warn((Object) null); 52 | log.warn((String) null); 53 | log.warn(new char['a']); 54 | log.warn(2324); 55 | log.warn(6624224 * 42); 56 | log.warn(Float.MAX_VALUE); 57 | log.warn(Double.MAX_VALUE); 58 | log.warn(Long.MAX_VALUE); 59 | 60 | // fatal常规测试 61 | log.fatal("fatal常规测试:"); 62 | log.fatal(); 63 | log.fatal(new Object()); 64 | log.fatal("String Test"); 65 | log.fatal((char[]) null); 66 | log.fatal((Object) null); 67 | log.fatal((String) null); 68 | log.fatal(new char['a']); 69 | log.fatal(2324); 70 | log.fatal(6624224 * 42); 71 | log.fatal(Float.MAX_VALUE); 72 | log.fatal(Double.MAX_VALUE); 73 | log.fatal(Long.MAX_VALUE); 74 | 75 | // debug常规测试 76 | log.debug("debug常规测试:"); 77 | log.debug(); 78 | log.debug(new Object()); 79 | log.debug("String Test"); 80 | log.debug((char[]) null); 81 | log.debug((Object) null); 82 | log.debug((String) null); 83 | log.debug(new char['a']); 84 | log.debug(2324); 85 | log.debug(6624224 * 42); 86 | log.debug(Float.MAX_VALUE); 87 | log.debug(Double.MAX_VALUE); 88 | log.debug(Long.MAX_VALUE); 89 | 90 | // 变化栈测试 91 | log.info("变化栈信息测试:"); 92 | stackTest(log); 93 | 94 | // 变化线程测试 95 | log.info("变化线程测试:"); 96 | new Thread(() -> { 97 | log.info("1"); 98 | log.error("2"); 99 | log.warn("3"); 100 | log.debug("4"); 101 | log.fatal("5"); 102 | log.info("6"); 103 | log.error("7"); 104 | log.warn("8"); 105 | log.debug("9"); 106 | log.fatal("10"); 107 | }).start(); 108 | log.info("1(N)"); 109 | log.error("2(N)"); 110 | log.warn("3(N)"); 111 | log.debug("4(N)"); 112 | log.fatal("5(N)"); 113 | log.info("6(N)"); 114 | log.error("7(N)"); 115 | log.warn("8(N)"); 116 | log.debug("9(N)"); 117 | log.fatal("10(N)"); 118 | 119 | // 运行期配置变化测试 120 | log.info("运行期配置文件变化测试:"); 121 | log.setPrintInfo(false); 122 | log.info("This log will not be print."); 123 | log.setPrintInfo(true); 124 | log.setConsoleInfo(false); 125 | log.info("This log will not be console."); 126 | log.setConsoleInfo(true); 127 | 128 | log.info(new File(".").getAbsolutePath()); 129 | } 130 | 131 | public static void stackTest(Log log) { 132 | log.info("Stack Test"); 133 | log.error("Stack Test"); 134 | log.warn("Stack Test"); 135 | log.debug("Stack Test"); 136 | log.fatal("Stack Test"); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/test/java/com/optilog/PropertiesPathOptilogTest.java: -------------------------------------------------------------------------------- 1 | package com.optilog; 2 | 3 | import com.optilog.log.Log; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.File; 7 | 8 | public class PropertiesPathOptilogTest { 9 | @Test 10 | void test() { 11 | Log log = Log.initLog("%prop ./src/test/resources/Settings.properties"); 12 | 13 | log.info("========测试开始========"); 14 | 15 | // info常规测试 16 | log.info("info常规测试:"); 17 | log.info(); 18 | log.info(new Object()); 19 | log.info("String Test"); 20 | log.info((char[]) null); 21 | log.info((Object) null); 22 | log.info((String) null); 23 | log.info(new char['a']); 24 | log.info(2324); 25 | log.info(382845 * (32 + 444)); 26 | log.info(Float.MAX_VALUE); 27 | log.info(Double.MAX_VALUE); 28 | log.info(Long.MAX_VALUE); 29 | 30 | // error常规测试 31 | log.error("error常规测试:"); 32 | log.error(); 33 | log.error(new Object()); 34 | log.error("String Test"); 35 | log.error((char[]) null); 36 | log.error((Object) null); 37 | log.error((String) null); 38 | log.error(new char['a']); 39 | log.error(2324); 40 | log.error(6624224 * 42); 41 | log.error(Float.MAX_VALUE); 42 | log.error(Double.MAX_VALUE); 43 | log.error(Long.MAX_VALUE); 44 | 45 | // warn常规测试 46 | log.warn("warn常规测试:"); 47 | log.warn(); 48 | log.warn(new Object()); 49 | log.warn("String Test"); 50 | log.warn((char[]) null); 51 | log.warn((Object) null); 52 | log.warn((String) null); 53 | log.warn(new char['a']); 54 | log.warn(2324); 55 | log.warn(6624224 * 42); 56 | log.warn(Float.MAX_VALUE); 57 | log.warn(Double.MAX_VALUE); 58 | log.warn(Long.MAX_VALUE); 59 | 60 | // fatal常规测试 61 | log.fatal("fatal常规测试:"); 62 | log.fatal(); 63 | log.fatal(new Object()); 64 | log.fatal("String Test"); 65 | log.fatal((char[]) null); 66 | log.fatal((Object) null); 67 | log.fatal((String) null); 68 | log.fatal(new char['a']); 69 | log.fatal(2324); 70 | log.fatal(6624224 * 42); 71 | log.fatal(Float.MAX_VALUE); 72 | log.fatal(Double.MAX_VALUE); 73 | log.fatal(Long.MAX_VALUE); 74 | 75 | // debug常规测试 76 | log.debug("debug常规测试:"); 77 | log.debug(); 78 | log.debug(new Object()); 79 | log.debug("String Test"); 80 | log.debug((char[]) null); 81 | log.debug((Object) null); 82 | log.debug((String) null); 83 | log.debug(new char['a']); 84 | log.debug(2324); 85 | log.debug(6624224 * 42); 86 | log.debug(Float.MAX_VALUE); 87 | log.debug(Double.MAX_VALUE); 88 | log.debug(Long.MAX_VALUE); 89 | 90 | // 变化栈测试 91 | log.info("变化栈信息测试:"); 92 | stackTest(log); 93 | 94 | // 变化线程测试 95 | log.info("变化线程测试:"); 96 | new Thread(() -> { 97 | log.info("1"); 98 | log.error("2"); 99 | log.warn("3"); 100 | log.debug("4"); 101 | log.fatal("5"); 102 | log.info("6"); 103 | log.error("7"); 104 | log.warn("8"); 105 | log.debug("9"); 106 | log.fatal("10"); 107 | }).start(); 108 | log.info("1(N)"); 109 | log.error("2(N)"); 110 | log.warn("3(N)"); 111 | log.debug("4(N)"); 112 | log.fatal("5(N)"); 113 | log.info("6(N)"); 114 | log.error("7(N)"); 115 | log.warn("8(N)"); 116 | log.debug("9(N)"); 117 | log.fatal("10(N)"); 118 | 119 | // 运行期配置变化测试 120 | log.info("运行期配置文件变化测试:"); 121 | log.setPrintInfo(false); 122 | log.info("This log will not be print."); 123 | log.setPrintInfo(true); 124 | log.setConsoleInfo(false); 125 | log.info("This log will not be console."); 126 | log.setConsoleInfo(true); 127 | 128 | log.info(new File(".").getAbsolutePath()); 129 | } 130 | 131 | public static void stackTest(Log log) { 132 | log.info("Stack Test"); 133 | log.error("Stack Test"); 134 | log.warn("Stack Test"); 135 | log.debug("Stack Test"); 136 | log.fatal("Stack Test"); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/test/java/com/optilog/XmlClassPathOptilogTest.java: -------------------------------------------------------------------------------- 1 | package com.optilog; 2 | 3 | import com.optilog.log.Log; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.File; 7 | 8 | public class XmlClassPathOptilogTest { 9 | @Test 10 | void test() { 11 | Log log = Log.initLog("%xml -cp /Settings.xml"); 12 | 13 | log.info("========测试开始========"); 14 | 15 | // info常规测试 16 | log.info("info常规测试:"); 17 | log.info(); 18 | log.info(new Object()); 19 | log.info("String Test"); 20 | log.info((char[]) null); 21 | log.info((Object) null); 22 | log.info((String) null); 23 | log.info(new char['a']); 24 | log.info(2324); 25 | log.info(382845 * (32 + 444)); 26 | log.info(Float.MAX_VALUE); 27 | log.info(Double.MAX_VALUE); 28 | log.info(Long.MAX_VALUE); 29 | 30 | // error常规测试 31 | log.error("error常规测试:"); 32 | log.error(); 33 | log.error(new Object()); 34 | log.error("String Test"); 35 | log.error((char[]) null); 36 | log.error((Object) null); 37 | log.error((String) null); 38 | log.error(new char['a']); 39 | log.error(2324); 40 | log.error(6624224 * 42); 41 | log.error(Float.MAX_VALUE); 42 | log.error(Double.MAX_VALUE); 43 | log.error(Long.MAX_VALUE); 44 | 45 | // warn常规测试 46 | log.warn("warn常规测试:"); 47 | log.warn(); 48 | log.warn(new Object()); 49 | log.warn("String Test"); 50 | log.warn((char[]) null); 51 | log.warn((Object) null); 52 | log.warn((String) null); 53 | log.warn(new char['a']); 54 | log.warn(2324); 55 | log.warn(6624224 * 42); 56 | log.warn(Float.MAX_VALUE); 57 | log.warn(Double.MAX_VALUE); 58 | log.warn(Long.MAX_VALUE); 59 | 60 | // fatal常规测试 61 | log.fatal("fatal常规测试:"); 62 | log.fatal(); 63 | log.fatal(new Object()); 64 | log.fatal("String Test"); 65 | log.fatal((char[]) null); 66 | log.fatal((Object) null); 67 | log.fatal((String) null); 68 | log.fatal(new char['a']); 69 | log.fatal(2324); 70 | log.fatal(6624224 * 42); 71 | log.fatal(Float.MAX_VALUE); 72 | log.fatal(Double.MAX_VALUE); 73 | log.fatal(Long.MAX_VALUE); 74 | 75 | // debug常规测试 76 | log.debug("debug常规测试:"); 77 | log.debug(); 78 | log.debug(new Object()); 79 | log.debug("String Test"); 80 | log.debug((char[]) null); 81 | log.debug((Object) null); 82 | log.debug((String) null); 83 | log.debug(new char['a']); 84 | log.debug(2324); 85 | log.debug(6624224 * 42); 86 | log.debug(Float.MAX_VALUE); 87 | log.debug(Double.MAX_VALUE); 88 | log.debug(Long.MAX_VALUE); 89 | 90 | // 变化栈测试 91 | log.info("变化栈信息测试:"); 92 | stackTest(log); 93 | 94 | // 变化线程测试 95 | log.info("变化线程测试:"); 96 | new Thread(() -> { 97 | log.info("1"); 98 | log.error("2"); 99 | log.warn("3"); 100 | log.debug("4"); 101 | log.fatal("5"); 102 | log.info("6"); 103 | log.error("7"); 104 | log.warn("8"); 105 | log.debug("9"); 106 | log.fatal("10"); 107 | }).start(); 108 | log.info("1(N)"); 109 | log.error("2(N)"); 110 | log.warn("3(N)"); 111 | log.debug("4(N)"); 112 | log.fatal("5(N)"); 113 | log.info("6(N)"); 114 | log.error("7(N)"); 115 | log.warn("8(N)"); 116 | log.debug("9(N)"); 117 | log.fatal("10(N)"); 118 | 119 | // 运行期配置变化测试 120 | log.info("运行期配置文件变化测试:"); 121 | log.setPrintInfo(false); 122 | log.info("This log will not be print."); 123 | log.setPrintInfo(true); 124 | log.setConsoleInfo(false); 125 | log.info("This log will not be console."); 126 | log.setConsoleInfo(true); 127 | 128 | log.info(new File(".").getAbsolutePath()); 129 | } 130 | 131 | public static void stackTest(Log log) { 132 | log.info("Stack Test"); 133 | log.error("Stack Test"); 134 | log.warn("Stack Test"); 135 | log.debug("Stack Test"); 136 | log.fatal("Stack Test"); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/test/java/com/optilog/XmlPathOptilogTest.java: -------------------------------------------------------------------------------- 1 | package com.optilog; 2 | 3 | import com.optilog.log.Log; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.File; 7 | 8 | public class XmlPathOptilogTest { 9 | @Test 10 | void test() { 11 | Log log = Log.initLog("%xml ./src/test/resources/Settings.xml"); 12 | 13 | log.info("========测试开始========"); 14 | 15 | // info常规测试 16 | log.info("info常规测试:"); 17 | log.info(); 18 | log.info(new Object()); 19 | log.info("String Test"); 20 | log.info((char[]) null); 21 | log.info((Object) null); 22 | log.info((String) null); 23 | log.info(new char['a']); 24 | log.info(2324); 25 | log.info(382845 * (32 + 444)); 26 | log.info(Float.MAX_VALUE); 27 | log.info(Double.MAX_VALUE); 28 | log.info(Long.MAX_VALUE); 29 | 30 | // error常规测试 31 | log.error("error常规测试:"); 32 | log.error(); 33 | log.error(new Object()); 34 | log.error("String Test"); 35 | log.error((char[]) null); 36 | log.error((Object) null); 37 | log.error((String) null); 38 | log.error(new char['a']); 39 | log.error(2324); 40 | log.error(6624224 * 42); 41 | log.error(Float.MAX_VALUE); 42 | log.error(Double.MAX_VALUE); 43 | log.error(Long.MAX_VALUE); 44 | 45 | // warn常规测试 46 | log.warn("warn常规测试:"); 47 | log.warn(); 48 | log.warn(new Object()); 49 | log.warn("String Test"); 50 | log.warn((char[]) null); 51 | log.warn((Object) null); 52 | log.warn((String) null); 53 | log.warn(new char['a']); 54 | log.warn(2324); 55 | log.warn(6624224 * 42); 56 | log.warn(Float.MAX_VALUE); 57 | log.warn(Double.MAX_VALUE); 58 | log.warn(Long.MAX_VALUE); 59 | 60 | // fatal常规测试 61 | log.fatal("fatal常规测试:"); 62 | log.fatal(); 63 | log.fatal(new Object()); 64 | log.fatal("String Test"); 65 | log.fatal((char[]) null); 66 | log.fatal((Object) null); 67 | log.fatal((String) null); 68 | log.fatal(new char['a']); 69 | log.fatal(2324); 70 | log.fatal(6624224 * 42); 71 | log.fatal(Float.MAX_VALUE); 72 | log.fatal(Double.MAX_VALUE); 73 | log.fatal(Long.MAX_VALUE); 74 | 75 | // debug常规测试 76 | log.debug("debug常规测试:"); 77 | log.debug(); 78 | log.debug(new Object()); 79 | log.debug("String Test"); 80 | log.debug((char[]) null); 81 | log.debug((Object) null); 82 | log.debug((String) null); 83 | log.debug(new char['a']); 84 | log.debug(2324); 85 | log.debug(6624224 * 42); 86 | log.debug(Float.MAX_VALUE); 87 | log.debug(Double.MAX_VALUE); 88 | log.debug(Long.MAX_VALUE); 89 | 90 | // 变化栈测试 91 | log.info("变化栈信息测试:"); 92 | stackTest(log); 93 | 94 | // 变化线程测试 95 | log.info("变化线程测试:"); 96 | new Thread(() -> { 97 | log.info("1"); 98 | log.error("2"); 99 | log.warn("3"); 100 | log.debug("4"); 101 | log.fatal("5"); 102 | log.info("6"); 103 | log.error("7"); 104 | log.warn("8"); 105 | log.debug("9"); 106 | log.fatal("10"); 107 | }).start(); 108 | log.info("1(N)"); 109 | log.error("2(N)"); 110 | log.warn("3(N)"); 111 | log.debug("4(N)"); 112 | log.fatal("5(N)"); 113 | log.info("6(N)"); 114 | log.error("7(N)"); 115 | log.warn("8(N)"); 116 | log.debug("9(N)"); 117 | log.fatal("10(N)"); 118 | 119 | // 运行期配置变化测试 120 | log.info("运行期配置文件变化测试:"); 121 | log.setPrintInfo(false); 122 | log.info("This log will not be print."); 123 | log.setPrintInfo(true); 124 | log.setConsoleInfo(false); 125 | log.info("This log will not be console."); 126 | log.setConsoleInfo(true); 127 | 128 | log.info(new File(".").getAbsolutePath()); 129 | } 130 | 131 | public static void stackTest(Log log) { 132 | log.info("Stack Test"); 133 | log.error("Stack Test"); 134 | log.warn("Stack Test"); 135 | log.debug("Stack Test"); 136 | log.fatal("Stack Test"); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/test/java/com/optilog/YamlClassPathOptilogTest.java: -------------------------------------------------------------------------------- 1 | package com.optilog; 2 | 3 | import com.optilog.log.Log; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.File; 7 | 8 | public class YamlClassPathOptilogTest { 9 | @Test 10 | void test() { 11 | Log log = Log.initLog("%yaml -cp /Settings.yaml"); 12 | 13 | log.info("========测试开始========"); 14 | 15 | // info常规测试 16 | log.info("info常规测试:"); 17 | log.info(); 18 | log.info(new Object()); 19 | log.info("String Test"); 20 | log.info((char[]) null); 21 | log.info((Object) null); 22 | log.info((String) null); 23 | log.info(new char['a']); 24 | log.info(2324); 25 | log.info(382845 * (32 + 444)); 26 | log.info(Float.MAX_VALUE); 27 | log.info(Double.MAX_VALUE); 28 | log.info(Long.MAX_VALUE); 29 | 30 | // error常规测试 31 | log.error("error常规测试:"); 32 | log.error(); 33 | log.error(new Object()); 34 | log.error("String Test"); 35 | log.error((char[]) null); 36 | log.error((Object) null); 37 | log.error((String) null); 38 | log.error(new char['a']); 39 | log.error(2324); 40 | log.error(6624224 * 42); 41 | log.error(Float.MAX_VALUE); 42 | log.error(Double.MAX_VALUE); 43 | log.error(Long.MAX_VALUE); 44 | 45 | // warn常规测试 46 | log.warn("warn常规测试:"); 47 | log.warn(); 48 | log.warn(new Object()); 49 | log.warn("String Test"); 50 | log.warn((char[]) null); 51 | log.warn((Object) null); 52 | log.warn((String) null); 53 | log.warn(new char['a']); 54 | log.warn(2324); 55 | log.warn(6624224 * 42); 56 | log.warn(Float.MAX_VALUE); 57 | log.warn(Double.MAX_VALUE); 58 | log.warn(Long.MAX_VALUE); 59 | 60 | // fatal常规测试 61 | log.fatal("fatal常规测试:"); 62 | log.fatal(); 63 | log.fatal(new Object()); 64 | log.fatal("String Test"); 65 | log.fatal((char[]) null); 66 | log.fatal((Object) null); 67 | log.fatal((String) null); 68 | log.fatal(new char['a']); 69 | log.fatal(2324); 70 | log.fatal(6624224 * 42); 71 | log.fatal(Float.MAX_VALUE); 72 | log.fatal(Double.MAX_VALUE); 73 | log.fatal(Long.MAX_VALUE); 74 | 75 | // debug常规测试 76 | log.debug("debug常规测试:"); 77 | log.debug(); 78 | log.debug(new Object()); 79 | log.debug("String Test"); 80 | log.debug((char[]) null); 81 | log.debug((Object) null); 82 | log.debug((String) null); 83 | log.debug(new char['a']); 84 | log.debug(2324); 85 | log.debug(6624224 * 42); 86 | log.debug(Float.MAX_VALUE); 87 | log.debug(Double.MAX_VALUE); 88 | log.debug(Long.MAX_VALUE); 89 | 90 | // 变化栈测试 91 | log.info("变化栈信息测试:"); 92 | stackTest(log); 93 | 94 | // 变化线程测试 95 | log.info("变化线程测试:"); 96 | new Thread(() -> { 97 | log.info("1"); 98 | log.error("2"); 99 | log.warn("3"); 100 | log.debug("4"); 101 | log.fatal("5"); 102 | log.info("6"); 103 | log.error("7"); 104 | log.warn("8"); 105 | log.debug("9"); 106 | log.fatal("10"); 107 | }).start(); 108 | log.info("1(N)"); 109 | log.error("2(N)"); 110 | log.warn("3(N)"); 111 | log.debug("4(N)"); 112 | log.fatal("5(N)"); 113 | log.info("6(N)"); 114 | log.error("7(N)"); 115 | log.warn("8(N)"); 116 | log.debug("9(N)"); 117 | log.fatal("10(N)"); 118 | 119 | // 运行期配置变化测试 120 | log.info("运行期配置文件变化测试:"); 121 | log.setPrintInfo(false); 122 | log.info("This log will not be print."); 123 | log.setPrintInfo(true); 124 | log.setConsoleInfo(false); 125 | log.info("This log will not be console."); 126 | log.setConsoleInfo(true); 127 | 128 | log.info(new File(".").getAbsolutePath()); 129 | } 130 | 131 | public static void stackTest(Log log) { 132 | log.info("Stack Test"); 133 | log.error("Stack Test"); 134 | log.warn("Stack Test"); 135 | log.debug("Stack Test"); 136 | log.fatal("Stack Test"); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/test/java/com/optilog/YamlPathOptilogTest.java: -------------------------------------------------------------------------------- 1 | package com.optilog; 2 | 3 | import com.optilog.log.Log; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.io.File; 7 | 8 | public class YamlPathOptilogTest { 9 | @Test 10 | void test() { 11 | Log log = Log.initLog("%yaml ./src/test/resources/Settings.yaml"); 12 | 13 | log.info("========测试开始========"); 14 | 15 | // info常规测试 16 | log.info("info常规测试:"); 17 | log.info(); 18 | log.info(new Object()); 19 | log.info("String Test"); 20 | log.info((char[]) null); 21 | log.info((Object) null); 22 | log.info((String) null); 23 | log.info(new char['a']); 24 | log.info(2324); 25 | log.info(382845 * (32 + 444)); 26 | log.info(Float.MAX_VALUE); 27 | log.info(Double.MAX_VALUE); 28 | log.info(Long.MAX_VALUE); 29 | 30 | // error常规测试 31 | log.error("error常规测试:"); 32 | log.error(); 33 | log.error(new Object()); 34 | log.error("String Test"); 35 | log.error((char[]) null); 36 | log.error((Object) null); 37 | log.error((String) null); 38 | log.error(new char['a']); 39 | log.error(2324); 40 | log.error(6624224 * 42); 41 | log.error(Float.MAX_VALUE); 42 | log.error(Double.MAX_VALUE); 43 | log.error(Long.MAX_VALUE); 44 | 45 | // warn常规测试 46 | log.warn("warn常规测试:"); 47 | log.warn(); 48 | log.warn(new Object()); 49 | log.warn("String Test"); 50 | log.warn((char[]) null); 51 | log.warn((Object) null); 52 | log.warn((String) null); 53 | log.warn(new char['a']); 54 | log.warn(2324); 55 | log.warn(6624224 * 42); 56 | log.warn(Float.MAX_VALUE); 57 | log.warn(Double.MAX_VALUE); 58 | log.warn(Long.MAX_VALUE); 59 | 60 | // fatal常规测试 61 | log.fatal("fatal常规测试:"); 62 | log.fatal(); 63 | log.fatal(new Object()); 64 | log.fatal("String Test"); 65 | log.fatal((char[]) null); 66 | log.fatal((Object) null); 67 | log.fatal((String) null); 68 | log.fatal(new char['a']); 69 | log.fatal(2324); 70 | log.fatal(6624224 * 42); 71 | log.fatal(Float.MAX_VALUE); 72 | log.fatal(Double.MAX_VALUE); 73 | log.fatal(Long.MAX_VALUE); 74 | 75 | // debug常规测试 76 | log.debug("debug常规测试:"); 77 | log.debug(); 78 | log.debug(new Object()); 79 | log.debug("String Test"); 80 | log.debug((char[]) null); 81 | log.debug((Object) null); 82 | log.debug((String) null); 83 | log.debug(new char['a']); 84 | log.debug(2324); 85 | log.debug(6624224 * 42); 86 | log.debug(Float.MAX_VALUE); 87 | log.debug(Double.MAX_VALUE); 88 | log.debug(Long.MAX_VALUE); 89 | 90 | // 变化栈测试 91 | log.info("变化栈信息测试:"); 92 | stackTest(log); 93 | 94 | // 变化线程测试 95 | log.info("变化线程测试:"); 96 | new Thread(() -> { 97 | log.info("1"); 98 | log.error("2"); 99 | log.warn("3"); 100 | log.debug("4"); 101 | log.fatal("5"); 102 | log.info("6"); 103 | log.error("7"); 104 | log.warn("8"); 105 | log.debug("9"); 106 | log.fatal("10"); 107 | }).start(); 108 | log.info("1(N)"); 109 | log.error("2(N)"); 110 | log.warn("3(N)"); 111 | log.debug("4(N)"); 112 | log.fatal("5(N)"); 113 | log.info("6(N)"); 114 | log.error("7(N)"); 115 | log.warn("8(N)"); 116 | log.debug("9(N)"); 117 | log.fatal("10(N)"); 118 | 119 | // 运行期配置变化测试 120 | log.info("运行期配置文件变化测试:"); 121 | log.setPrintInfo(false); 122 | log.info("This log will not be print."); 123 | log.setPrintInfo(true); 124 | log.setConsoleInfo(false); 125 | log.info("This log will not be console."); 126 | log.setConsoleInfo(true); 127 | 128 | log.info(new File(".").getAbsolutePath()); 129 | } 130 | 131 | public static void stackTest(Log log) { 132 | log.info("Stack Test"); 133 | log.error("Stack Test"); 134 | log.warn("Stack Test"); 135 | log.debug("Stack Test"); 136 | log.fatal("Stack Test"); 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/test/resources/Settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "print": { 3 | "info": "true", 4 | "error": "true", 5 | "warn": "true", 6 | "debug": "true", 7 | "fatal": "true", 8 | "packingFormat": "[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg" 9 | }, 10 | "file": { 11 | "info": "true", 12 | "error": "true", 13 | "warn": "true", 14 | "debug": "true", 15 | "fatal": "true", 16 | "defaultConsolePath": "./logs", 17 | "fileName": "%time-Log(Json).log", 18 | "packingFormat": "[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg" 19 | }, 20 | "server": { 21 | "info": "true", 22 | "error": "true", 23 | "warn": "true", 24 | "debug": "true", 25 | "fatal": "true", 26 | "startClient": "false", 27 | "socketNumber": "65535", 28 | "host": "localhost", 29 | "packingFormat": "[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg", 30 | "forceDisableSocketWhenException": "true" 31 | } 32 | } -------------------------------------------------------------------------------- /src/test/resources/Settings.properties: -------------------------------------------------------------------------------- 1 | # print 2 | print.info=true 3 | print.error=true 4 | print.warn=true 5 | print.debug=true 6 | print.fatal=true 7 | print.packingFormat=[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg 8 | # file 9 | file.defaultConsolePath=./logs 10 | #file.Path1=D:\\Program\\Project\\resources\\app\\Git\\Projects\\Optilog-Client\\src\\test\\resources 11 | #file.infoPath=%path1 12 | #file.debugPath=%path1 13 | #file.warnPath=%path1 14 | file.consoleInfo=true 15 | file.consoleDebug=true 16 | file.consoleError=true 17 | file.consoleWarn=true 18 | file.consoleFatal=true 19 | file.fileName=%time-Log(Properties).log 20 | file.packingFormat=[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg 21 | # server 22 | server.infoSendToServer=true 23 | server.errorSendToServer=true 24 | server.warnSendToServer=true 25 | server.debugSendToServer=true 26 | server.fatalSendToServer=true 27 | server.startClient=false 28 | server.socketNumber=65535 29 | server.packingFormat=[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg 30 | server.host=localhost 31 | server.forceDisableSocketWhenException=true -------------------------------------------------------------------------------- /src/test/resources/Settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | true 6 | true 7 | true 8 | true 9 | 10 | 11 | [%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg 12 | 13 | 14 | 15 | 16 | true 17 | true 18 | true 19 | true 20 | true 21 | 22 | 23 | ./logs 24 | 25 | 26 | %time-Log(Xml).log 27 | 28 | [%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg 29 | 30 | 31 | 32 | 33 | true 34 | true 35 | true 36 | true 37 | true 38 | 39 | false 40 | localhost 41 | 65535 42 | 43 | [%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg 44 | 45 | true 46 | 47 | -------------------------------------------------------------------------------- /src/test/resources/Settings.yaml: -------------------------------------------------------------------------------- 1 | info: 2 | print: "true" 3 | console: "true" 4 | server: "true" 5 | error: 6 | print: "true" 7 | console: "true" 8 | server: "true" 9 | warn: 10 | print: "true" 11 | console: "true" 12 | server: "true" 13 | debug: 14 | print: "true" 15 | console: "true" 16 | server: "true" 17 | fatal: 18 | print: "true" 19 | console: "true" 20 | server: "true" 21 | print: 22 | packingFormat: "[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg" 23 | file: 24 | defaultConsolePath: "./logs" 25 | fileName: "%time-Log(Yaml).log" 26 | packingFormat: "[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg" 27 | server: 28 | startClient: "false" 29 | socketNumber: "65535" 30 | host: "localhost" 31 | packingFormat: "[%yyyy-%MM-%dd|%HH:%mm:%ss(%SS))][%class %method(%file:%line)/%thread] %level:%msg" 32 | forceDisableSocketWhenException: "true" 33 | --------------------------------------------------------------------------------