Skip to content

Commit

Permalink
Merge pull request #1 from zotonic/skeleton
Browse files Browse the repository at this point in the history
Skeleton of logstasher
  • Loading branch information
vkatsuba authored Feb 2, 2022
2 parents bf34fa9 + 66d794c commit 9c4c711
Show file tree
Hide file tree
Showing 16 changed files with 565 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
name: Bug report
about: Create a report of bug for logstasher
title: ''
labels: ''
assignees: ''
---

## `logstasher` version
[Put release version here and update tag link(0.0.0) ...](https://github.com/zotonic/logstasher.git)

## `OS` version
<!-- Put the `OS` version ... -->

## Steps to reproduce
<!-- (Optional)Describe steps to reproduce bug ... -->

## Current behavior
<!-- Describe current behavior ... -->

## Expected behavior
<!-- Describe expected behavior ... -->

## Config
<!-- (Optional)Put configuration ... -->
28 changes: 28 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: Feature request
about: Suggest an idea for logstasher
title: ''
labels: ''
assignees: ''
---

## `logstasher` version
[Put release version here and update tag link(0.0.0)...](https://github.com/zotonic/logstasher.git)

## `OS` version
<!-- Put the `OS` version ... -->

## Description
* **Motivation**
<!-- (Optional)Describe motivation ... -->
* **Proposal**
<!-- (Optional)Describe proposal of the solution ... -->

## Current behavior
<!-- (Optional)Describe current behavior ... -->

## Expected behavior
<!-- (Optional)Describe expected behavior ... -->

## Config
<!-- (Optional)Put configuration ... -->
9 changes: 9 additions & 0 deletions .github/ISSUE_TEMPLATE/other_issues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
name: Other Issues
about: Something that's are not covered by the other templates
title: ''
labels: ''
assignees: ''
---

<!-- Please consider opening a discussion if this is not really an issue -->
27 changes: 27 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI

on:
push:
pull_request:
branches: [ $default-branch ]
release:
types:
- created
workflow_dispatch:

jobs:
ubuntu:
name: "Ubuntu"
runs-on: ubuntu-latest
strategy:
matrix:
otp: [22.3, 23.3, 24.2]
rebar: [3.18.0]
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
rebar3-version: ${{matrix.rebar}}
- name: Tests
run: rebar3 test
27 changes: 27 additions & 0 deletions .github/workflows/hex.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Publish to hex.pm

on:
push:
tags:
- '*'

jobs:
publish:
name: "Ubuntu"
runs-on: ubuntu-latest
strategy:
matrix:
otp: [24.2]
rebar: [3.18.0]
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.otp}}
rebar3-version: ${{matrix.rebar}}
- name: Publish to Hex.pm
env:
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}
run: |
rebar3 edoc_extensions
rebar3 hex publish -r hexpm --yes
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ erl_crash.dump
# rebar 2.x
.rebar
rel/example_project
ebin/*.beam
ebin
deps

# rebar 3
.rebar3
_build/
_checkouts/
doc
rebar3
logs
rebar3.crashdump
94 changes: 94 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,96 @@
# logstasher
[![Hex.pm Version][hexpm version]][hexpm]
[![Hex.pm Downloads][hexpm downloads]][hexpm]
[![Hex.pm Documentation][hexdocs documentation]][hexdocs]
[![Build Status][gh badge]][gh]
[![Erlang Versions][erlang version badge]][gh]

Erlang Logger formatter for logstash

<!-- Badges -->
[hexpm]: https://hex.pm/packages/logstasher
[hexpm version]: https://img.shields.io/hexpm/v/logstasher.svg?style=flat-square
[hexpm downloads]: https://img.shields.io/hexpm/dt/logstasher.svg?style=flat-square
[hexdocs documentation]: https://img.shields.io/badge/hex-docs-purple.svg?style=flat-square
[hexdocs]: https://hexdocs.pm/logstasher
[gh]: https://github.com/zotonic/logstasher/actions/workflows/ci.yml
[gh badge]: https://img.shields.io/github/workflow/status/zotonic/logstasher/CI?style=flat-square
[erlang version badge]: https://img.shields.io/badge/erlang-22.0%20to%2024.2.1-blue.svg?style=flat-square


## Hex package

In `rebar.config`, add the logstasher Hex package to the deps:

```erlang
{deps, [
{logstasher, "~> 1.0.0"}
]}.

```

## Erlang Configuration

In `sys.config`, enable `logstasher_h` as a Logger handler and configure the `logstasher`
application:


```erlang
[
{kernel, [
{logger, [
{handler, logstash, logstasher_h,
#{
level => info
}
}
]}
]},

{logstasher, [
{transport, udp}, % tcp | udp | console
{host, "localhost"}, % inet:hostname()
{port, 5000} % inet:port_number()
]}
].
```

After this, also add the `logstasher` application to your `.app.src` file:

```erlang
{applications, [
....
logstasher,
....
]},
```

## Logstash Configuration

```ruby
input {
udp {
codec => json
port => 5000
queue_size => 10000
workers => 10
type => default_log_type
}
}
output {
stdout {}
elasticsearch {
protocol => http
}
}
```

## Send data to logstash

It is possible to send other data to logstash:

```erlang
logstasher:send_message(<<"Hello world!">>, #{ some => <<"fields">> }).
```

A timestamp will be added to the message.
21 changes: 21 additions & 0 deletions config/sys.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{kernel, [
{logger, [
{handler, logstash, logstasher_h,
#{
level => info%,
%config => #{
% host => "localhost",
% port => 8080
%}
}
}
]}
]},

{logstasher, [
{transport, tcp}, % tcp | udp
{host , "localhost"}, % inet:hostname()
{port, 8080} % inet:port_number()
]}
].
29 changes: 29 additions & 0 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{erl_opts, [debug_info]}.

{deps, [
{jsx, "3.1.0"}
]}.

{minimum_otp_vsn, "22"}.

{project_plugins, [
{rebar3_hex, "~> 7.0.1"},
{rebar3_edoc_extensions, "~> 0.2.5"}
]}.

{dialyzer, [{warnings, [no_return, unmatched_returns, error_handling, underspecs]}]}.

{xref_checks,
[deprecated_function_calls, exports_not_used, locals_not_used, undefined_function_calls]}.

{cover_enabled, true}.

{cover_opts, [verbose]}.

{alias,
[{test, [compile, xref, dialyzer, {ct, "--verbose"}, cover, edoc]}]}.

{shell, [
{config, "config/sys.config"},
{apps, [logstasher]}
]}.
8 changes: 8 additions & 0 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{"1.2.0",
[{<<"jsx">>,{pkg,<<"jsx">>,<<"3.1.0">>},0}]}.
[
{pkg_hash,[
{<<"jsx">>, <<"D12516BAA0BB23A59BB35DCCAF02A1BD08243FCBB9EFE24F2D9D056CCFF71268">>}]},
{pkg_hash_ext,[
{<<"jsx">>, <<"0C5CC8FDC11B53CC25CF65AC6705AD39E54ECC56D1C22E4ADB8F5A53FB9427F3">>}]}
].
16 changes: 16 additions & 0 deletions src/logstasher.app.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{application, logstasher, [
{description, "The logstasher is Erlang Logger formatter for logstash"},
{vsn, git},
{registered, []},
{mod, {logstasher_app, []}},
{applications, [
kernel,
stdlib,
jsx
]},
{env,[]},
{modules, []},

{licenses, ["Apache-2.0"]},
{links, [{"github", "https://github.com/zotonic/logstasher.git"}]}
]}.
Loading

0 comments on commit 9c4c711

Please sign in to comment.