├── .github └── workflows │ └── simple-socket-fn-logger.yaml ├── .gitignore ├── LICENSE ├── META-INF └── native-image │ ├── jni-config.json │ ├── proxy-config.json │ ├── reflect-config.json │ └── resource-config.json ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── src └── main ├── java └── codes │ └── recursive │ ├── Main.java │ └── MessageHandler.java └── resources ├── logback.xml └── reflection-config.json /.github/workflows/simple-socket-fn-logger.yaml: -------------------------------------------------------------------------------- 1 | name: simple-socket-fn-logger 2 | on: 3 | push: 4 | tags: 5 | - "v*" 6 | branches: 7 | - 'master' 8 | 9 | jobs: 10 | build-jar-job: 11 | name: 'Build JAR' 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | 16 | - name: 'Checkout' 17 | uses: actions/checkout@v2 18 | 19 | - name: 'Setup Java 11' 20 | uses: actions/setup-java@v1 21 | with: 22 | java-version: 11 23 | 24 | - name: 'Build JAR' 25 | run: | 26 | ./gradlew shadowJar 27 | 28 | - name: 'Get Version Number' 29 | run: | 30 | echo "::set-env name=VERSION::$(./gradlew properties -q | grep "version:" | awk '{print $2}')" 31 | 32 | - name: 'Publish JAR' 33 | uses: actions/upload-artifact@v2-preview 34 | with: 35 | name: 'simple-socket-fn-logger-${{env.VERSION}}-all.jar' 36 | path: build/libs/*-all.jar 37 | 38 | - name: 'Create Release' 39 | if: contains(github.ref, 'v') 40 | id: create_release 41 | uses: actions/create-release@v1 42 | env: 43 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 44 | with: 45 | tag_name: ${{github.ref}} 46 | release_name: Release ${{github.ref}} 47 | body: | 48 | Initial release 49 | draft: false 50 | prerelease: false 51 | 52 | - name: 'Upload Release Asset' 53 | if: contains(github.ref, 'v') 54 | id: upload-release-asset 55 | uses: actions/upload-release-asset@v1 56 | env: 57 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 58 | with: 59 | upload_url: ${{steps.create_release.outputs.upload_url}} 60 | asset_path: build/libs/simple-socket-fn-logger-${{env.VERSION}}-all.jar 61 | asset_name: simple-socket-fn-logger-${{env.VERSION}}-all.jar 62 | asset_content_type: application/java-archive 63 | 64 | 65 | - name: 'Write Upload URL To File' 66 | if: contains(github.ref, 'v') 67 | run: | 68 | echo "${{steps.create_release.outputs.upload_url}}" > upload_url.txt 69 | 70 | - name: 'Publish Upload URL' 71 | if: contains(github.ref, 'v') 72 | uses: actions/upload-artifact@v2-preview 73 | with: 74 | name: 'upload_url.txt' 75 | path: 'upload_url.txt' 76 | 77 | build-non-windows-image: 78 | name: 'Build Non-Windows Image' 79 | needs: [build-jar-job] 80 | strategy: 81 | matrix: 82 | os: ['ubuntu-latest', 'macos-latest'] 83 | include: 84 | - os: 'ubuntu-latest' 85 | label: 'linux' 86 | - os: 'macos-latest' 87 | label: 'mac' 88 | runs-on: ${{matrix.os}} 89 | 90 | steps: 91 | - name: 'Checkout' 92 | uses: actions/checkout@v2 93 | 94 | - name: 'Setup Java 11' 95 | uses: actions/setup-java@v1 96 | with: 97 | java-version: 11 98 | 99 | - name: 'Setup GraalVM Environment' 100 | uses: DeLaGuardo/setup-graalvm@2.0 101 | with: 102 | graalvm-version: '20.1.0.java11' 103 | 104 | - name: 'Install Native Image Plugin' 105 | run: | 106 | gu install native-image 107 | 108 | - name: 'Get Version Number' 109 | run: | 110 | echo "::set-env name=VERSION::$(./gradlew properties -q | grep "version:" | awk '{print $2}')" 111 | 112 | - name: 'Get JAR Artifact' 113 | uses: actions/download-artifact@v2-preview 114 | with: 115 | name: 'simple-socket-fn-logger-${{env.VERSION}}-all.jar' 116 | 117 | - name: 'Get Release URL' 118 | if: contains(github.ref, 'v') 119 | uses: actions/download-artifact@v2-preview 120 | with: 121 | name: 'upload_url.txt' 122 | 123 | - name: 'Get Upload URL' 124 | if: contains(github.ref, 'v') 125 | run: | 126 | echo "::set-env name=UPLOAD_URL::$(cat upload_url.txt)" 127 | 128 | - name: 'Build Native Image' 129 | run: | 130 | native-image --no-server --no-fallback -H:ReflectionConfigurationResources=reflection-config.json -H:IncludeResources=logback.xml --allow-incomplete-classpath -jar simple-socket-fn-logger-${{env.VERSION}}-all.jar 131 | 132 | - name: 'Publish Native Image' 133 | if: success() 134 | uses: actions/upload-artifact@v2-preview 135 | with: 136 | name: 'simple-socket-fn-logger-${{env.VERSION}}-${{matrix.label}}' 137 | path: 'simple-socket-fn-logger-${{env.VERSION}}-all' 138 | 139 | - name: 'Release Native Image Asset' 140 | if: success() && contains(github.ref, 'v') 141 | id: upload-release-asset 142 | uses: actions/upload-release-asset@v1 143 | env: 144 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 145 | with: 146 | upload_url: ${{env.UPLOAD_URL}} 147 | asset_name: 'simple-socket-fn-logger-${{env.VERSION}}-${{matrix.label}}' 148 | asset_path: 'simple-socket-fn-logger-${{env.VERSION}}-all' 149 | asset_content_type: application/octet-stream 150 | 151 | build-windows-image: 152 | needs: [build-jar-job] 153 | name: 'Build Windows Image' 154 | runs-on: windows-latest 155 | 156 | steps: 157 | 158 | - name: 'Checkout' 159 | uses: actions/checkout@v1 160 | 161 | - name: 'Download GraalVM' 162 | run: | 163 | Invoke-RestMethod -Uri https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-20.1.0/graalvm-ce-java11-windows-amd64-20.1.0.zip -OutFile 'graal.zip' 164 | 165 | - name: 'Install GraalVM' 166 | run: | 167 | Expand-Archive -path 'graal.zip' -destinationpath '.' 168 | 169 | - name: 'Install Native Image' 170 | run: | 171 | graalvm-ce-java11-20.1.0\bin\gu.cmd install native-image 172 | 173 | - name: 'Set up Visual C Build Tools Workload for Visual Studio 2017 Build Tools' 174 | run: | 175 | choco install visualstudio2017-workload-vctools 176 | 177 | - name: 'Get Version Number' 178 | run: | 179 | echo "::set-env name=VERSION::$(./gradlew properties -q | grep "version:" | awk '{print $2}')" 180 | shell: bash 181 | 182 | - name: 'Get JAR Artifact' 183 | uses: actions/download-artifact@v2-preview 184 | with: 185 | name: 'simple-socket-fn-logger-${{env.VERSION}}-all.jar' 186 | 187 | - name: 'Build Native Image' 188 | shell: cmd 189 | env: 190 | JAVA_HOME: ./graalvm-ce-java11-20.1.0 191 | run: | 192 | call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat" 193 | ./graalvm-ce-java11-20.1.0/bin/native-image --no-server --no-fallback -H:ReflectionConfigurationResources=reflection-config.json -H:IncludeResources=logback.xml -H:Name=simple-socket-fn-logger-${{env.VERSION}}-all --allow-incomplete-classpath -jar simple-socket-fn-logger-${{env.VERSION}}-all.jar 194 | 195 | - name: 'Get Release URL' 196 | if: contains(github.ref, 'v') 197 | uses: actions/download-artifact@v2-preview 198 | with: 199 | name: 'upload_url.txt' 200 | 201 | - name: 'Get Upload URL' 202 | if: contains(github.ref, 'v') 203 | run: | 204 | echo "::set-env name=UPLOAD_URL::$(cat upload_url.txt)" 205 | shell: bash 206 | 207 | - name: 'Publish Windows Image' 208 | if: success() 209 | uses: actions/upload-artifact@v2-preview 210 | with: 211 | name: 'simple-socket-fn-logger-${{env.VERSION}}-windows.exe' 212 | path: 'simple-socket-fn-logger-${{env.VERSION}}-all.exe' 213 | 214 | - name: 'Release Windows Image Asset' 215 | if: success() && contains(github.ref, 'v') 216 | id: upload-release-asset 217 | uses: actions/upload-release-asset@v1 218 | env: 219 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 220 | with: 221 | upload_url: ${{env.UPLOAD_URL}} 222 | asset_name: 'simple-socket-fn-logger-${{env.VERSION}}-windows.exe' 223 | asset_path: 'simple-socket-fn-logger-${{env.VERSION}}-all.exe' 224 | asset_content_type: application/octet-stream -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Java template 3 | # Compiled class file 4 | *.class 5 | 6 | # Log file 7 | *.log 8 | 9 | # BlueJ files 10 | *.ctxt 11 | 12 | # Mobile Tools for Java (J2ME) 13 | .mtj.tmp/ 14 | 15 | # Package Files # 16 | *.jar 17 | *.war 18 | *.nar 19 | *.ear 20 | *.zip 21 | *.tar.gz 22 | *.rar 23 | 24 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 25 | hs_err_pid* 26 | 27 | ### Gradle template 28 | .gradle 29 | /build/ 30 | 31 | # Ignore Gradle GUI config 32 | gradle-app.setting 33 | 34 | # Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) 35 | !gradle-wrapper.jar 36 | 37 | # Cache of project 38 | .gradletasknamecache 39 | 40 | # # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 41 | # gradle/wrapper/gradle-wrapper.properties 42 | 43 | ### JetBrains template 44 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider 45 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 46 | 47 | # User-specific stuff 48 | .idea/**/workspace.xml 49 | .idea/**/tasks.xml 50 | .idea/**/usage.statistics.xml 51 | .idea/**/dictionaries 52 | .idea/**/shelf 53 | 54 | # Generated files 55 | .idea/**/contentModel.xml 56 | 57 | # Sensitive or high-churn files 58 | .idea/**/dataSources/ 59 | .idea/**/dataSources.ids 60 | .idea/**/dataSources.local.xml 61 | .idea/**/sqlDataSources.xml 62 | .idea/**/dynamic.xml 63 | .idea/**/uiDesigner.xml 64 | .idea/**/dbnavigator.xml 65 | 66 | # Gradle 67 | .idea/**/gradle.xml 68 | .idea/**/libraries 69 | 70 | # Gradle and Maven with auto-import 71 | # When using Gradle or Maven with auto-import, you should exclude module files, 72 | # since they will be recreated, and may cause churn. Uncomment if using 73 | # auto-import. 74 | # .idea/artifacts 75 | # .idea/compiler.xml 76 | # .idea/jarRepositories.xml 77 | # .idea/modules.xml 78 | # .idea/*.iml 79 | # .idea/modules 80 | # *.iml 81 | # *.ipr 82 | 83 | # CMake 84 | cmake-build-*/ 85 | 86 | # Mongo Explorer plugin 87 | .idea/**/mongoSettings.xml 88 | 89 | # File-based project format 90 | *.iws 91 | 92 | # IntelliJ 93 | out/ 94 | 95 | # mpeltonen/sbt-idea plugin 96 | .idea_modules/ 97 | 98 | # JIRA plugin 99 | atlassian-ide-plugin.xml 100 | 101 | # Cursive Clojure plugin 102 | .idea/replstate.xml 103 | 104 | # Crashlytics plugin (for Android Studio and IntelliJ) 105 | com_crashlytics_export_strings.xml 106 | crashlytics.properties 107 | crashlytics-build.properties 108 | fabric.properties 109 | 110 | # Editor-based Rest Client 111 | .idea/httpRequests 112 | 113 | # Android studio 3.1+ serialized cache file 114 | .idea/caches/build_file_checksums.ser 115 | 116 | .idea 117 | .DS_Store 118 | native-images.md 119 | simple-socket-fn-logger-* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Todd Sharp 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 | -------------------------------------------------------------------------------- /META-INF/native-image/jni-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name":"java.lang.ClassLoader", 4 | "methods":[ 5 | {"name":"getPlatformClassLoader","parameterTypes":[] }, 6 | {"name":"loadClass","parameterTypes":["java.lang.String"] } 7 | ] 8 | }, 9 | { 10 | "name":"java.lang.ClassNotFoundException" 11 | }, 12 | { 13 | "name":"java.lang.NoSuchMethodError" 14 | } 15 | ] 16 | -------------------------------------------------------------------------------- /META-INF/native-image/proxy-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | ] 3 | -------------------------------------------------------------------------------- /META-INF/native-image/reflect-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name":"ch.qos.logback.classic.encoder.PatternLayoutEncoder", 4 | "allPublicMethods":true, 5 | "methods":[{"name":"","parameterTypes":[] }] 6 | }, 7 | { 8 | "name":"ch.qos.logback.classic.pattern.DateConverter", 9 | "methods":[{"name":"","parameterTypes":[] }] 10 | }, 11 | { 12 | "name":"ch.qos.logback.classic.pattern.LevelConverter", 13 | "methods":[{"name":"","parameterTypes":[] }] 14 | }, 15 | { 16 | "name":"ch.qos.logback.classic.pattern.LineSeparatorConverter", 17 | "methods":[{"name":"","parameterTypes":[] }] 18 | }, 19 | { 20 | "name":"ch.qos.logback.classic.pattern.LoggerConverter", 21 | "methods":[{"name":"","parameterTypes":[] }] 22 | }, 23 | { 24 | "name":"ch.qos.logback.classic.pattern.MessageConverter", 25 | "methods":[{"name":"","parameterTypes":[] }] 26 | }, 27 | { 28 | "name":"ch.qos.logback.classic.pattern.ThreadConverter", 29 | "methods":[{"name":"","parameterTypes":[] }] 30 | }, 31 | { 32 | "name":"ch.qos.logback.classic.pattern.color.HighlightingCompositeConverter", 33 | "methods":[{"name":"","parameterTypes":[] }] 34 | }, 35 | { 36 | "name":"ch.qos.logback.core.ConsoleAppender", 37 | "allPublicMethods":true, 38 | "methods":[{"name":"","parameterTypes":[] }] 39 | }, 40 | { 41 | "name":"ch.qos.logback.core.pattern.color.CyanCompositeConverter", 42 | "methods":[{"name":"","parameterTypes":[] }] 43 | }, 44 | { 45 | "name":"ch.qos.logback.core.pattern.color.GrayCompositeConverter", 46 | "methods":[{"name":"","parameterTypes":[] }] 47 | }, 48 | { 49 | "name":"ch.qos.logback.core.pattern.color.MagentaCompositeConverter", 50 | "methods":[{"name":"","parameterTypes":[] }] 51 | }, 52 | { 53 | "name":"javax.management.ObjectName" 54 | } 55 | ] 56 | -------------------------------------------------------------------------------- /META-INF/native-image/resource-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "resources":[ 3 | {"pattern":"\\Qlogback.xml\\E"}, 4 | {"pattern":"\\Qorg/slf4j/impl/StaticLoggerBinder.class\\E"} 5 | ], 6 | "bundles":[] 7 | } 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # simple-socket-fn-logger 2 | 3 | ![simple-socket-fn-logger](https://github.com/recursivecodes/simple-socket-fn-logger/workflows/simple-socket-fn-logger/badge.svg) 4 | 5 | ## About 6 | 7 | A simple socket server that can be used as a logging endpoint for your Oracle Functions! This can be run on your local machine, or wherever you want to run it (a cloud VM, etc). At bare minimum, it's a great tool to get near realtime logging for your Oracle Functions that are deployed in the Oracle Cloud. But it can be more than that! If you want, you can modify `MessageHandler.java` to persist your log data (maybe to a [free Autonomous DB instance](https://oracle.com/cloud/free))! The syslog format contains a log of data and this logger just outputs the message contents. You have access to a `Map` of data that looks like so: 8 | 9 | ```json 10 | { 11 | "syslog.header.appName": "app_id=ocid1.fnapp.oc1.phx...,fn_id=ocid1.fnfunc.oc1.phx...", 12 | "syslog.header.version": "1", 13 | "syslog.header.hostName": "runner-00001700e5f9", 14 | "syslog.header.facility": "1", 15 | "syslog.header.msgId": "app_id=ocid1.fnapp.oc1.phx...,fn_id=ocid1.fnfunc.oc1.phx...", 16 | "syslog.header.timestamp": "2020-06-15T14:46:35Z", 17 | "syslog.message": "Error in function: ReferenceError: foo is not defined", 18 | "syslog.header.pri": "11", 19 | "syslog.header.procId": "8", 20 | "syslog.header.severity": "3" 21 | } 22 | ``` 23 | 24 | Feel free to extend this as needed! 25 | 26 | ## Usage 27 | 28 | You can use a pre-compiled version of this server, or compile it yourself. 29 | 30 | ### Pre-compiled 31 | 32 | Download the [latest release](https://github.com/recursivecodes/simple-socket-fn-logger/releases), place it in a directory and run the JAR (requires Java 11 JDK installed). See [Running The Server](#running-the-server). 33 | 34 | ### Compiling 35 | 36 | To compile, use Gradle: 37 | 38 | ```shell script 39 | $ ./gradlew shadowJar 40 | ``` 41 | 42 | This will create a runnable JAR in the `build/libs` directory. See [Running The Server](#running-the-server). 43 | 44 | ### Running The Server 45 | 46 | To run the server via the latest released JAR file: 47 | 48 | ```shell script 49 | $ java -jar simple-socket-fn-logger-[version]-all.jar 50 | ``` 51 | 52 | You may also use one of the provided native images. For example, if you downloaded the Mac OS native executable called `simple-socket-fn-logger-0.46-macos`, you would run it like so: 53 | 54 | | NOTE: Windows EXE native image is untested. If you would like to help out with Windows support, file a PR! | 55 | | --- | 56 | 57 | ```shell script 58 | $ chmod +x simple-socket-fn-logger-0.46-macos 59 | $ ./simple-socket-fn-logger-0.46-macos 60 | ``` 61 | 62 | This will start up a socket server on the default port of 30000. If you want to use a different port, pass it in: 63 | 64 | ```shell script 65 | $ java -jar -Dport=32000 simple-socket-fn-logger-[version]-all.jar 66 | ``` 67 | 68 | Native images also support passing in the port: 69 | 70 | ```shell script 71 | $ ./simple-socket-fn-logger-0.46-macos -Dport=32000 72 | ``` 73 | 74 | | WARNING: Check firewall ports, routers, security lists, etc to make sure the port is open! | 75 | | --- | 76 | 77 | This **can** be run on `localhost`, but your syslog URL must be your public IP and your router/firewall should forward the port as necessary! 78 | 79 | ### Config Oracle Function Application 80 | 81 | You'll need to set the syslog URL to point at your new socket server. You can do this via the CLI: 82 | 83 | ```shell script 84 | $ fn update app syslog-demo-app --syslog-url tcp://[your public IP]:[socket server port] 85 | ``` 86 | 87 | Or via the console: 88 | 89 | ![set syslog url via console](https://objectstorage.us-phoenix-1.oraclecloud.com/n/toddrsharp/b/readme-assets/o/2020-06-15_10-58-38.png) 90 | 91 | | WARNING: If your server is not running, remove the `syslog` URL from your function to prevent getting the `Error invoking function. status: 502 message: Syslog endpoint unavailable` error! | 92 | | --- | 93 | 94 | It's worth repeating that this **can** be run on `localhost`, but your syslog URL must be your public IP and your router/firewall should forward the port as necessary! 95 | 96 | ### Sample Output 97 | 98 | Here's what you'll see in your console when a function produces output. You'll find this **much more helpful** than the standard response of `Error invoking function. status: 502 message: function failed`. 99 | 100 | #### Node.JS 101 | 102 | A `console.log()` and an exception: 103 | 104 | ```shell script 105 | Jun 16 12:18:46.060 - Listening on localhost:30000... 106 | Jun 16 12:19:07.154 - this is a console.log() 107 | Jun 16 12:19:07.154 - Error in function: ReferenceError: foo is not defined 108 | Jun 16 12:19:07.159 - at /function/func.js:11:3 109 | Jun 16 12:19:07.164 - at /function/node_modules/@fnproject/fdk/fn-fdk.js:299:26 110 | Jun 16 12:19:07.167 - at new Promise () 111 | Jun 16 12:19:07.169 - at IncomingMessage.req.on.on (/function/node_modules/@fnproject/fdk/fn-fdk.js:297:7) 112 | Jun 16 12:19:07.172 - at IncomingMessage.emit (events.js:193:13) 113 | Jun 16 12:19:07.173 - at endReadableNT (_stream_readable.js:1139:12) 114 | Jun 16 12:19:07.175 - at processTicksAndRejections (internal/process/task_queues.js:81:17) 115 | Jun 16 12:19:07.177 - Error 502 : {"message":"Exception in function, consult logs for details","detail":"ReferenceError: foo is not defined"} 116 | ``` 117 | 118 | #### Java 119 | 120 | A call to `System.out.println()` and an exception: 121 | 122 | ```shell script 123 | Jun 16 12:19:37.682 - Listening on localhost:30000... 124 | Jun 16 12:19:51.922 - This is System.out.println() 125 | Jun 16 12:19:51.930 - An error occurred in function: foo 126 | Jun 16 12:19:51.935 - Caused by: java.lang.Exception: foo 127 | Jun 16 12:19:51.941 - at com.example.fn.HelloFunction.handleRequest(HelloFunction.java:9) 128 | Jun 16 12:19:51.944 - at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 129 | Jun 16 12:19:51.948 - at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 130 | Jun 16 12:19:51.951 - at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 131 | Jun 16 12:19:51.956 - at java.base/java.lang.reflect.Method.invoke(Unknown Source) 132 | ``` -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'idea' 3 | id 'java' 4 | id 'application' 5 | id "com.github.johnrengelman.shadow" version "5.2.0" 6 | } 7 | 8 | group 'codes.recursive' 9 | 10 | mainClassName = 'codes.recursive.Main' 11 | 12 | configurations { 13 | } 14 | 15 | repositories { 16 | mavenCentral() 17 | maven { url "https://repo.spring.io/libs-release/" } 18 | } 19 | 20 | dependencies { 21 | compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3' 22 | compile group: 'com.github.palindromicity', name: 'simple-syslog-5424', version: '0.0.7' 23 | } 24 | 25 | task runServer(dependsOn: 'classes', type: JavaExec) { 26 | classpath = sourceSets.main.runtimeClasspath 27 | main = mainClassName 28 | systemProperties = System.getProperties() 29 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=1.0.0 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/recursivecodes/simple-socket-fn-logger/012d912fb1329964ac672a208361aa86f9589717/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-6.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or 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 UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=`expr $i + 1` 158 | done 159 | case $i in 160 | 0) set -- ;; 161 | 1) set -- "$args0" ;; 162 | 2) set -- "$args0" "$args1" ;; 163 | 3) set -- "$args0" "$args1" "$args2" ;; 164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=`save "$@"` 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | exec "$JAVACMD" "$@" 184 | -------------------------------------------------------------------------------- /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 Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'simple-socket-fn-logger' 2 | 3 | -------------------------------------------------------------------------------- /src/main/java/codes/recursive/Main.java: -------------------------------------------------------------------------------- 1 | package codes.recursive; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | import java.io.IOException; 7 | import java.net.ServerSocket; 8 | import java.net.Socket; 9 | 10 | public class Main { 11 | 12 | private static ServerSocket socketServer; 13 | 14 | public static void main(String[] args) throws IOException { 15 | Logger logger = LoggerFactory.getLogger(Main.class); 16 | int port = Integer.parseInt( System.getProperty("port", "30000") ); 17 | socketServer = new ServerSocket(port); 18 | 19 | logger.info("Listening on localhost:{}...", port); 20 | 21 | Runtime.getRuntime().addShutdownHook(new Thread(() -> { 22 | logger.info("Server shutting down. Goodbye..."); 23 | try { 24 | socketServer.close(); 25 | } 26 | catch (IOException e) { 27 | e.printStackTrace(); 28 | } 29 | })); 30 | 31 | //noinspection InfiniteLoopStatement 32 | while(true) { 33 | Socket socket = socketServer.accept(); 34 | Runnable messageHandler = new MessageHandler(socket); 35 | new Thread(messageHandler).start(); 36 | } 37 | } 38 | 39 | } -------------------------------------------------------------------------------- /src/main/java/codes/recursive/MessageHandler.java: -------------------------------------------------------------------------------- 1 | package codes.recursive; 2 | 3 | import com.github.palindromicity.syslog.SyslogParser; 4 | import com.github.palindromicity.syslog.SyslogParserBuilder; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | 8 | import java.io.BufferedReader; 9 | import java.io.IOException; 10 | import java.io.InputStreamReader; 11 | import java.net.Socket; 12 | import java.util.Map; 13 | 14 | public class MessageHandler implements Runnable { 15 | private final Socket clientSocket; 16 | private final SyslogParser parser = new SyslogParserBuilder().build(); 17 | private final Logger logger = LoggerFactory.getLogger(Main.class); 18 | 19 | public MessageHandler(Socket clientSocket) { 20 | this.clientSocket = clientSocket; 21 | } 22 | 23 | public void run() { 24 | BufferedReader reader = null; 25 | try { 26 | reader = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); 27 | } catch (IOException e) { 28 | e.printStackTrace(); 29 | } 30 | String incomingMsg; 31 | try{ 32 | while( (incomingMsg = reader.readLine()) != null ) { 33 | Map result = parser.parseLine(incomingMsg); 34 | /* 35 | gives us a nicely formatted Map 36 | containing lots of information. 37 | for example: 38 | { 39 | "syslog.header.appName": "app_id=ocid1.fnapp.oc1.phx...,fn_id=ocid1.fnfunc.oc1.phx...", 40 | "syslog.header.version": "1", 41 | "syslog.header.hostName": "runner-00001700e5f9", 42 | "syslog.header.facility": "1", 43 | "syslog.header.msgId": "app_id=ocid1.fnapp.oc1.phx...,fn_id=ocid1.fnfunc.oc1.phx...", 44 | "syslog.header.timestamp": "2020-06-15T14:46:35Z", 45 | "syslog.message": "Error in function: ReferenceError: foo is not defined", 46 | "syslog.header.pri": "11", 47 | "syslog.header.procId": "8", 48 | "syslog.header.severity": "3" 49 | } 50 | */ 51 | logger.info( result.get("syslog.message").toString() ); 52 | } 53 | } 54 | catch (IOException e) { 55 | e.printStackTrace(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | 7 | 8 | %cyan(%d{MMM dd HH:mm:ss.SSS}) - %msg%n 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/main/resources/reflection-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name":"ch.qos.logback.classic.encoder.PatternLayoutEncoder", 4 | "allPublicMethods":true, 5 | "methods":[{"name":"","parameterTypes":[] }] 6 | }, 7 | { 8 | "name":"ch.qos.logback.classic.pattern.DateConverter", 9 | "methods":[{"name":"","parameterTypes":[] }] 10 | }, 11 | { 12 | "name":"ch.qos.logback.classic.pattern.LevelConverter", 13 | "methods":[{"name":"","parameterTypes":[] }] 14 | }, 15 | { 16 | "name":"ch.qos.logback.classic.pattern.LineSeparatorConverter", 17 | "methods":[{"name":"","parameterTypes":[] }] 18 | }, 19 | { 20 | "name":"ch.qos.logback.classic.pattern.LoggerConverter", 21 | "methods":[{"name":"","parameterTypes":[] }] 22 | }, 23 | { 24 | "name":"ch.qos.logback.classic.pattern.MessageConverter", 25 | "methods":[{"name":"","parameterTypes":[] }] 26 | }, 27 | { 28 | "name":"ch.qos.logback.classic.pattern.ThreadConverter", 29 | "methods":[{"name":"","parameterTypes":[] }] 30 | }, 31 | { 32 | "name":"ch.qos.logback.classic.pattern.color.HighlightingCompositeConverter", 33 | "methods":[{"name":"","parameterTypes":[] }] 34 | }, 35 | { 36 | "name":"ch.qos.logback.core.ConsoleAppender", 37 | "allPublicMethods":true, 38 | "methods":[{"name":"","parameterTypes":[] }] 39 | }, 40 | { 41 | "name":"ch.qos.logback.core.pattern.color.CyanCompositeConverter", 42 | "methods":[{"name":"","parameterTypes":[] }] 43 | }, 44 | { 45 | "name":"ch.qos.logback.core.pattern.color.GrayCompositeConverter", 46 | "methods":[{"name":"","parameterTypes":[] }] 47 | }, 48 | { 49 | "name":"ch.qos.logback.core.pattern.color.MagentaCompositeConverter", 50 | "methods":[{"name":"","parameterTypes":[] }] 51 | }, 52 | { 53 | "name":"javax.management.ObjectName" 54 | } 55 | ] 56 | --------------------------------------------------------------------------------