Giter Club home page Giter Club logo

simple-socket-fn-logger's Introduction

simple-socket-fn-logger

simple-socket-fn-logger

About

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)! 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:

{
    "syslog.header.appName": "app_id=ocid1.fnapp.oc1.phx...,fn_id=ocid1.fnfunc.oc1.phx...",
    "syslog.header.version": "1",
    "syslog.header.hostName": "runner-00001700e5f9",
    "syslog.header.facility": "1",
    "syslog.header.msgId": "app_id=ocid1.fnapp.oc1.phx...,fn_id=ocid1.fnfunc.oc1.phx...",
    "syslog.header.timestamp": "2020-06-15T14:46:35Z",
    "syslog.message": "Error in function: ReferenceError: foo is not defined",
    "syslog.header.pri": "11",
    "syslog.header.procId": "8",
    "syslog.header.severity": "3"
}

Feel free to extend this as needed!

Usage

You can use a pre-compiled version of this server, or compile it yourself.

Pre-compiled

Download the latest release, place it in a directory and run the JAR (requires Java 11 JDK installed). See Running The Server.

Compiling

To compile, use Gradle:

$ ./gradlew shadowJar

This will create a runnable JAR in the build/libs directory. See Running The Server.

Running The Server

To run the server via the latest released JAR file:

$ java -jar simple-socket-fn-logger-[version]-all.jar

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:

NOTE: Windows EXE native image is untested. If you would like to help out with Windows support, file a PR!
$ chmod +x simple-socket-fn-logger-0.46-macos
$ ./simple-socket-fn-logger-0.46-macos

This will start up a socket server on the default port of 30000. If you want to use a different port, pass it in:

$ java -jar -Dport=32000 simple-socket-fn-logger-[version]-all.jar

Native images also support passing in the port:

$ ./simple-socket-fn-logger-0.46-macos -Dport=32000
WARNING: Check firewall ports, routers, security lists, etc to make sure the port is open!

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!

Config Oracle Function Application

You'll need to set the syslog URL to point at your new socket server. You can do this via the CLI:

$ fn update app syslog-demo-app --syslog-url tcp://[your public IP]:[socket server port]

Or via the console:

set syslog url via console

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!

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!

Sample Output

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.

Node.JS

A console.log() and an exception:

Jun 16 12:18:46.060 - Listening on localhost:30000...
Jun 16 12:19:07.154 - this is a console.log()
Jun 16 12:19:07.154 - Error in function: ReferenceError: foo is not defined
Jun 16 12:19:07.159 - at /function/func.js:11:3
Jun 16 12:19:07.164 - at /function/node_modules/@fnproject/fdk/fn-fdk.js:299:26
Jun 16 12:19:07.167 - at new Promise (<anonymous>)
Jun 16 12:19:07.169 - at IncomingMessage.req.on.on (/function/node_modules/@fnproject/fdk/fn-fdk.js:297:7)
Jun 16 12:19:07.172 - at IncomingMessage.emit (events.js:193:13)
Jun 16 12:19:07.173 - at endReadableNT (_stream_readable.js:1139:12)
Jun 16 12:19:07.175 - at processTicksAndRejections (internal/process/task_queues.js:81:17)
Jun 16 12:19:07.177 - Error 502 : {"message":"Exception in function, consult logs for details","detail":"ReferenceError: foo is not defined"}

Java

A call to System.out.println() and an exception:

Jun 16 12:19:37.682 - Listening on localhost:30000...
Jun 16 12:19:51.922 - This is System.out.println()
Jun 16 12:19:51.930 - An error occurred in function: foo
Jun 16 12:19:51.935 - Caused by: java.lang.Exception: foo
Jun 16 12:19:51.941 - at com.example.fn.HelloFunction.handleRequest(HelloFunction.java:9)
Jun 16 12:19:51.944 - at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Jun 16 12:19:51.948 - at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
Jun 16 12:19:51.951 - at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
Jun 16 12:19:51.956 - at java.base/java.lang.reflect.Method.invoke(Unknown Source)

simple-socket-fn-logger's People

Contributors

recursivecodes avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.