Attention is currently required from: kirr, pespin.
laforge has posted comments on this change by kirr. ( https://gerrit.osmocom.org/c/osmocom-bb/+/39533?usp=email )
Change subject: trx_toolkit/transceiver: Do not forward nor log from under tx_queue_lock
......................................................................
Patch Set 1: Code-Review+1
--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/39533?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I7d10c972c45b2b5765e7c3a28f8646508b3c8a82
Gerrit-Change-Number: 39533
Gerrit-PatchSet: 1
Gerrit-Owner: kirr <kirr(a)nexedi.com>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-CC: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-CC: osmith <osmith(a)sysmocom.de>
Gerrit-Attention: kirr <kirr(a)nexedi.com>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Comment-Date: Sat, 15 Feb 2025 08:43:14 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Attention is currently required from: laforge, osmith, pespin.
fixeria has posted comments on this change by fixeria. ( https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/39415?usp=email )
Change subject: Add GSMTAP logging handler
......................................................................
Patch Set 8:
(1 comment)
Patchset:
PS6:
> I couldn't find the logger_gsmtap project in gerrit yet. […]
I just created a repository in Gerrit and pushed patches for review:
https://gerrit.osmocom.org/c/erlang/logger_gsmtap/+/39552https://gerrit.osmocom.org/c/erlang/logger_gsmtap/+/39553
There's currently no build verification, I'll look how it's done for other projects.
--
To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/39415?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: comment
Gerrit-Project: erlang/osmo-s1gw
Gerrit-Branch: master
Gerrit-Change-Id: Iea884e2ca146b852c64bd9f135d8c71f4c925f09
Gerrit-Change-Number: 39415
Gerrit-PatchSet: 8
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: osmith <osmith(a)sysmocom.de>
Gerrit-Attention: laforge <laforge(a)osmocom.org>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Comment-Date: Fri, 14 Feb 2025 19:21:22 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: laforge <laforge(a)osmocom.org>
fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/erlang/logger_gsmtap/+/39552?usp=email )
Change subject: Initial commit
......................................................................
Initial commit
Change-Id: I30fad55b6e9d8d9f975de4deb2f97c1e98ae5c5e
---
A .gitignore
A LICENSE
A README.md
A rebar.config
A rebar.lock
A src/logger_gsmtap.app.src
A src/logger_gsmtap.erl
A src/logger_gsmtap_h.erl
8 files changed, 745 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/erlang/logger_gsmtap refs/changes/52/39552/1
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..df53f7d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,20 @@
+.rebar3
+_build
+_checkouts
+_vendor
+.eunit
+*.o
+*.beam
+*.plt
+*.swp
+*.swo
+.erlang.cookie
+ebin
+log
+erl_crash.dump
+.rebar
+logs
+.idea
+*.iml
+rebar3.crashdump
+*~
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..ee6256c
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,373 @@
+Mozilla Public License Version 2.0
+==================================
+
+1. Definitions
+--------------
+
+1.1. "Contributor"
+ means each individual or legal entity that creates, contributes to
+ the creation of, or owns Covered Software.
+
+1.2. "Contributor Version"
+ means the combination of the Contributions of others (if any) used
+ by a Contributor and that particular Contributor's Contribution.
+
+1.3. "Contribution"
+ means Covered Software of a particular Contributor.
+
+1.4. "Covered Software"
+ means Source Code Form to which the initial Contributor has attached
+ the notice in Exhibit A, the Executable Form of such Source Code
+ Form, and Modifications of such Source Code Form, in each case
+ including portions thereof.
+
+1.5. "Incompatible With Secondary Licenses"
+ means
+
+ (a) that the initial Contributor has attached the notice described
+ in Exhibit B to the Covered Software; or
+
+ (b) that the Covered Software was made available under the terms of
+ version 1.1 or earlier of the License, but not also under the
+ terms of a Secondary License.
+
+1.6. "Executable Form"
+ means any form of the work other than Source Code Form.
+
+1.7. "Larger Work"
+ means a work that combines Covered Software with other material, in
+ a separate file or files, that is not Covered Software.
+
+1.8. "License"
+ means this document.
+
+1.9. "Licensable"
+ means having the right to grant, to the maximum extent possible,
+ whether at the time of the initial grant or subsequently, any and
+ all of the rights conveyed by this License.
+
+1.10. "Modifications"
+ means any of the following:
+
+ (a) any file in Source Code Form that results from an addition to,
+ deletion from, or modification of the contents of Covered
+ Software; or
+
+ (b) any new file in Source Code Form that contains any Covered
+ Software.
+
+1.11. "Patent Claims" of a Contributor
+ means any patent claim(s), including without limitation, method,
+ process, and apparatus claims, in any patent Licensable by such
+ Contributor that would be infringed, but for the grant of the
+ License, by the making, using, selling, offering for sale, having
+ made, import, or transfer of either its Contributions or its
+ Contributor Version.
+
+1.12. "Secondary License"
+ means either the GNU General Public License, Version 2.0, the GNU
+ Lesser General Public License, Version 2.1, the GNU Affero General
+ Public License, Version 3.0, or any later versions of those
+ licenses.
+
+1.13. "Source Code Form"
+ means the form of the work preferred for making modifications.
+
+1.14. "You" (or "Your")
+ means an individual or a legal entity exercising rights under this
+ License. For legal entities, "You" includes any entity that
+ controls, is controlled by, or is under common control with You. For
+ purposes of this definition, "control" means (a) the power, direct
+ or indirect, to cause the direction or management of such entity,
+ whether by contract or otherwise, or (b) ownership of more than
+ fifty percent (50%) of the outstanding shares or beneficial
+ ownership of such entity.
+
+2. License Grants and Conditions
+--------------------------------
+
+2.1. Grants
+
+Each Contributor hereby grants You a world-wide, royalty-free,
+non-exclusive license:
+
+(a) under intellectual property rights (other than patent or trademark)
+ Licensable by such Contributor to use, reproduce, make available,
+ modify, display, perform, distribute, and otherwise exploit its
+ Contributions, either on an unmodified basis, with Modifications, or
+ as part of a Larger Work; and
+
+(b) under Patent Claims of such Contributor to make, use, sell, offer
+ for sale, have made, import, and otherwise transfer either its
+ Contributions or its Contributor Version.
+
+2.2. Effective Date
+
+The licenses granted in Section 2.1 with respect to any Contribution
+become effective for each Contribution on the date the Contributor first
+distributes such Contribution.
+
+2.3. Limitations on Grant Scope
+
+The licenses granted in this Section 2 are the only rights granted under
+this License. No additional rights or licenses will be implied from the
+distribution or licensing of Covered Software under this License.
+Notwithstanding Section 2.1(b) above, no patent license is granted by a
+Contributor:
+
+(a) for any code that a Contributor has removed from Covered Software;
+ or
+
+(b) for infringements caused by: (i) Your and any other third party's
+ modifications of Covered Software, or (ii) the combination of its
+ Contributions with other software (except as part of its Contributor
+ Version); or
+
+(c) under Patent Claims infringed by Covered Software in the absence of
+ its Contributions.
+
+This License does not grant any rights in the trademarks, service marks,
+or logos of any Contributor (except as may be necessary to comply with
+the notice requirements in Section 3.4).
+
+2.4. Subsequent Licenses
+
+No Contributor makes additional grants as a result of Your choice to
+distribute the Covered Software under a subsequent version of this
+License (see Section 10.2) or under the terms of a Secondary License (if
+permitted under the terms of Section 3.3).
+
+2.5. Representation
+
+Each Contributor represents that the Contributor believes its
+Contributions are its original creation(s) or it has sufficient rights
+to grant the rights to its Contributions conveyed by this License.
+
+2.6. Fair Use
+
+This License is not intended to limit any rights You have under
+applicable copyright doctrines of fair use, fair dealing, or other
+equivalents.
+
+2.7. Conditions
+
+Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
+in Section 2.1.
+
+3. Responsibilities
+-------------------
+
+3.1. Distribution of Source Form
+
+All distribution of Covered Software in Source Code Form, including any
+Modifications that You create or to which You contribute, must be under
+the terms of this License. You must inform recipients that the Source
+Code Form of the Covered Software is governed by the terms of this
+License, and how they can obtain a copy of this License. You may not
+attempt to alter or restrict the recipients' rights in the Source Code
+Form.
+
+3.2. Distribution of Executable Form
+
+If You distribute Covered Software in Executable Form then:
+
+(a) such Covered Software must also be made available in Source Code
+ Form, as described in Section 3.1, and You must inform recipients of
+ the Executable Form how they can obtain a copy of such Source Code
+ Form by reasonable means in a timely manner, at a charge no more
+ than the cost of distribution to the recipient; and
+
+(b) You may distribute such Executable Form under the terms of this
+ License, or sublicense it under different terms, provided that the
+ license for the Executable Form does not attempt to limit or alter
+ the recipients' rights in the Source Code Form under this License.
+
+3.3. Distribution of a Larger Work
+
+You may create and distribute a Larger Work under terms of Your choice,
+provided that You also comply with the requirements of this License for
+the Covered Software. If the Larger Work is a combination of Covered
+Software with a work governed by one or more Secondary Licenses, and the
+Covered Software is not Incompatible With Secondary Licenses, this
+License permits You to additionally distribute such Covered Software
+under the terms of such Secondary License(s), so that the recipient of
+the Larger Work may, at their option, further distribute the Covered
+Software under the terms of either this License or such Secondary
+License(s).
+
+3.4. Notices
+
+You may not remove or alter the substance of any license notices
+(including copyright notices, patent notices, disclaimers of warranty,
+or limitations of liability) contained within the Source Code Form of
+the Covered Software, except that You may alter any license notices to
+the extent required to remedy known factual inaccuracies.
+
+3.5. Application of Additional Terms
+
+You may choose to offer, and to charge a fee for, warranty, support,
+indemnity or liability obligations to one or more recipients of Covered
+Software. However, You may do so only on Your own behalf, and not on
+behalf of any Contributor. You must make it absolutely clear that any
+such warranty, support, indemnity, or liability obligation is offered by
+You alone, and You hereby agree to indemnify every Contributor for any
+liability incurred by such Contributor as a result of warranty, support,
+indemnity or liability terms You offer. You may include additional
+disclaimers of warranty and limitations of liability specific to any
+jurisdiction.
+
+4. Inability to Comply Due to Statute or Regulation
+---------------------------------------------------
+
+If it is impossible for You to comply with any of the terms of this
+License with respect to some or all of the Covered Software due to
+statute, judicial order, or regulation then You must: (a) comply with
+the terms of this License to the maximum extent possible; and (b)
+describe the limitations and the code they affect. Such description must
+be placed in a text file included with all distributions of the Covered
+Software under this License. Except to the extent prohibited by statute
+or regulation, such description must be sufficiently detailed for a
+recipient of ordinary skill to be able to understand it.
+
+5. Termination
+--------------
+
+5.1. The rights granted under this License will terminate automatically
+if You fail to comply with any of its terms. However, if You become
+compliant, then the rights granted under this License from a particular
+Contributor are reinstated (a) provisionally, unless and until such
+Contributor explicitly and finally terminates Your grants, and (b) on an
+ongoing basis, if such Contributor fails to notify You of the
+non-compliance by some reasonable means prior to 60 days after You have
+come back into compliance. Moreover, Your grants from a particular
+Contributor are reinstated on an ongoing basis if such Contributor
+notifies You of the non-compliance by some reasonable means, this is the
+first time You have received notice of non-compliance with this License
+from such Contributor, and You become compliant prior to 30 days after
+Your receipt of the notice.
+
+5.2. If You initiate litigation against any entity by asserting a patent
+infringement claim (excluding declaratory judgment actions,
+counter-claims, and cross-claims) alleging that a Contributor Version
+directly or indirectly infringes any patent, then the rights granted to
+You by any and all Contributors for the Covered Software under Section
+2.1 of this License shall terminate.
+
+5.3. In the event of termination under Sections 5.1 or 5.2 above, all
+end user license agreements (excluding distributors and resellers) which
+have been validly granted by You or Your distributors under this License
+prior to termination shall survive termination.
+
+************************************************************************
+* *
+* 6. Disclaimer of Warranty *
+* ------------------------- *
+* *
+* Covered Software is provided under this License on an "as is" *
+* basis, without warranty of any kind, either expressed, implied, or *
+* statutory, including, without limitation, warranties that the *
+* Covered Software is free of defects, merchantable, fit for a *
+* particular purpose or non-infringing. The entire risk as to the *
+* quality and performance of the Covered Software is with You. *
+* Should any Covered Software prove defective in any respect, You *
+* (not any Contributor) assume the cost of any necessary servicing, *
+* repair, or correction. This disclaimer of warranty constitutes an *
+* essential part of this License. No use of any Covered Software is *
+* authorized under this License except under this disclaimer. *
+* *
+************************************************************************
+
+************************************************************************
+* *
+* 7. Limitation of Liability *
+* -------------------------- *
+* *
+* Under no circumstances and under no legal theory, whether tort *
+* (including negligence), contract, or otherwise, shall any *
+* Contributor, or anyone who distributes Covered Software as *
+* permitted above, be liable to You for any direct, indirect, *
+* special, incidental, or consequential damages of any character *
+* including, without limitation, damages for lost profits, loss of *
+* goodwill, work stoppage, computer failure or malfunction, or any *
+* and all other commercial damages or losses, even if such party *
+* shall have been informed of the possibility of such damages. This *
+* limitation of liability shall not apply to liability for death or *
+* personal injury resulting from such party's negligence to the *
+* extent applicable law prohibits such limitation. Some *
+* jurisdictions do not allow the exclusion or limitation of *
+* incidental or consequential damages, so this exclusion and *
+* limitation may not apply to You. *
+* *
+************************************************************************
+
+8. Litigation
+-------------
+
+Any litigation relating to this License may be brought only in the
+courts of a jurisdiction where the defendant maintains its principal
+place of business and such litigation shall be governed by laws of that
+jurisdiction, without reference to its conflict-of-law provisions.
+Nothing in this Section shall prevent a party's ability to bring
+cross-claims or counter-claims.
+
+9. Miscellaneous
+----------------
+
+This License represents the complete agreement concerning the subject
+matter hereof. If any provision of this License is held to be
+unenforceable, such provision shall be reformed only to the extent
+necessary to make it enforceable. Any law or regulation which provides
+that the language of a contract shall be construed against the drafter
+shall not be used to construe this License against a Contributor.
+
+10. Versions of the License
+---------------------------
+
+10.1. New Versions
+
+Mozilla Foundation is the license steward. Except as provided in Section
+10.3, no one other than the license steward has the right to modify or
+publish new versions of this License. Each version will be given a
+distinguishing version number.
+
+10.2. Effect of New Versions
+
+You may distribute the Covered Software under the terms of the version
+of the License under which You originally received the Covered Software,
+or under the terms of any subsequent version published by the license
+steward.
+
+10.3. Modified Versions
+
+If you create software not governed by this License, and you want to
+create a new license for such software, you may create and use a
+modified version of this License if you rename the license and remove
+any references to the name of the license steward (except to note that
+such modified license differs from this License).
+
+10.4. Distributing Source Code Form that is Incompatible With Secondary
+Licenses
+
+If You choose to distribute Source Code Form that is Incompatible With
+Secondary Licenses under the terms of this version of the License, the
+notice described in Exhibit B of this License must be attached.
+
+Exhibit A - Source Code Form License Notice
+-------------------------------------------
+
+ This Source Code Form is subject to the terms of the Mozilla Public
+ License, v. 2.0. If a copy of the MPL was not distributed with this
+ file, You can obtain one at https://mozilla.org/MPL/2.0/.
+
+If it is not possible or desirable to put the notice in a particular
+file, then You may include the notice in a location (such as a LICENSE
+file in a relevant directory) where a recipient would be likely to look
+for such a notice.
+
+You may add additional accurate notices of copyright ownership.
+
+Exhibit B - "Incompatible With Secondary Licenses" Notice
+---------------------------------------------------------
+
+ This Source Code Form is "Incompatible With Secondary Licenses", as
+ defined by the Mozilla Public License, v. 2.0.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..db0bc16
--- /dev/null
+++ b/README.md
@@ -0,0 +1,82 @@
+logger_gsmtap
+=============
+
+GSMTAP logging handler.
+
+This is a logging handler for Erlang's built-in
+[Logger](https://www.erlang.org/doc/apps/kernel/logger.html) module.
+It sends log messages via GSMTAP (`udp/4729`), allowing capture of
+log messages alongside with other PDUs sent/received by the program.
+
+[GSMTAP](https://osmocom.org/projects/baseband/wiki/GSMTAP) is a
+pseudo-header initially designed to encapsulate GSM air interface (Um)
+frames within UDP/IP packets. Over time, its functionality was extended
+to enable the transport of logging messages.
+
+
+Adding to your project
+----------------------
+
+In case you're using rebar3, modify `rebar.config` as follows:
+
+```erlang
+{deps, [{logger_gsmtap,
+ {git, "https://gitea.osmocom.org/erlang/logger_gsmtap.git", {branch, "master"}}}
+]}.
+```
+
+
+API and Configuration
+---------------------
+
+To add an instance of the GSMTAP handler, you can use either
+[`logger:add_handler/3`](https://www.erlang.org/doc/apps/kernel/logger.html#add_handler/3)
+or the [configuration file](https://www.erlang.org/docs/25/man/config.html).
+The handler configuration argument is a map which can contain general
+configuration parameters, as documented in the
+[User's Guide](https://www.erlang.org/doc/apps/kernel/logger_chapter.html#handler-c…,
+and handler specific parameters. The specific data is stored in a sub map
+with the key `config`, and can contain the following parameters:
+
+- **`loc_addr :: string() | inet:ip_address()`** -
+ This specifies the local (bind) address to originate GSMTAP PDUs from.
+
+ Defaults to `"0.0.0.0"`, letting the OS to select it automatically.
+
+- **`rem_addr :: string() | inet:ip_address()`** -
+ This specifies the remote address to send GSMTAP PDUs to.
+
+ Defaults to `"127.0.0.1"` (localhost).
+
+- **`app_name :: string() | atom()`** -
+ This specifies the application name to be included in GSMTAP PDUs.
+
+ Defaults to `unknown`.
+
+Modification of these parameters is currently not supported.
+
+### Example of adding a GSMTAP handler using `logger:add_handler/3`
+
+```erlang
+logger:add_handler(gsmtap, logger_gsmtap_h,
+ #{config => #{rem_addr => "127.0.0.1",
+ app_name => "MyApp"}}).
+```
+
+### Example of adding a GSMTAP handler via configuration file
+
+```erlang
+{kernel, [
+ {logger_level, debug},
+ {logger, [
+ %% standard handler printing to stderr at level INFO
+ {handler, default, logger_std_h,
+ #{level => info}},
+ %% GSMTAP handler sending datagrams to 127.0.0.1 at level DEBUG
+ {handler, gsmtap, logger_gsmtap_h,
+ #{level => debug,
+ config => #{rem_addr => "127.0.0.1",
+ app_name => "MyApp"}}}
+ ]}
+]}
+```
diff --git a/rebar.config b/rebar.config
new file mode 100644
index 0000000..e354b58
--- /dev/null
+++ b/rebar.config
@@ -0,0 +1,9 @@
+%% -*- erlang -*-
+
+{erl_opts, [debug_info]}.
+
+{minimum_otp_vsn, "25.2.3"}.
+
+{deps, []}.
+
+%% vim:set ts=4 sw=4 et:
diff --git a/rebar.lock b/rebar.lock
new file mode 100644
index 0000000..57afcca
--- /dev/null
+++ b/rebar.lock
@@ -0,0 +1 @@
+[].
diff --git a/src/logger_gsmtap.app.src b/src/logger_gsmtap.app.src
new file mode 100644
index 0000000..8eb1a26
--- /dev/null
+++ b/src/logger_gsmtap.app.src
@@ -0,0 +1,15 @@
+%% -*- erlang -*-
+
+{application, logger_gsmtap, [
+ {description, "GSMTAP handler for Erlang's Logger module"},
+ {vsn, semver},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib
+ ]},
+ {licenses, ["Mozilla Public License 2.0"]},
+ {links, [{"Gitea", "https://gitea.osmocom.org/erlang/logger_gsmtap"}]}
+ ]}.
+
+%% vim:set ts=4 sw=4 et:
diff --git a/src/logger_gsmtap.erl b/src/logger_gsmtap.erl
new file mode 100644
index 0000000..570952d
--- /dev/null
+++ b/src/logger_gsmtap.erl
@@ -0,0 +1,156 @@
+%% Copyright (C) 2025 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+%% Author: Vadim Yanitskiy <vyanitskiy(a)sysmocom.de>
+%%
+%% All Rights Reserved
+%%
+%% SPDX-License-Identifier: MPL-2.0
+%%
+%% This Source Code Form is subject to the terms of the Mozilla Public
+%% License, v. 2.0. If a copy of the MPL was not distributed with this
+%% file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+-module(logger_gsmtap).
+
+-behaviour(gen_server).
+
+%% public API
+-export([start/3,
+ stop/1,
+ log/2]).
+%% gen_server callbacks
+-export([init/1,
+ handle_call/3,
+ handle_cast/2,
+ terminate/2]).
+
+-define(GSMTAP_PORT, 4729).
+-define(GSMTAP_VERSION, 16#02).
+-define(GSMTAP_HDR_LEN, 16#04). %% in number of 32bit words
+-define(GSMTAP_TYPE_OSMOCORE_LOG, 16#10).
+
+
+%% ------------------------------------------------------------------
+%% public API
+%% ------------------------------------------------------------------
+
+-spec start(LAddr, RAddr, AppName) -> gen_server:start_ret()
+ when LAddr :: inet:ip_address(),
+ RAddr :: inet:ip_address(),
+ AppName :: string().
+start(LAddr, RAddr, AppName) ->
+ gen_server:start(?MODULE, [LAddr, RAddr, AppName], []).
+
+
+-spec log(pid(), logger:log_event()) -> ok.
+log(Pid, LogEvent) ->
+ gen_server:cast(Pid, {?FUNCTION_NAME, LogEvent}).
+
+
+-spec stop(pid()) -> ok.
+stop(Pid) ->
+ gen_server:stop(Pid).
+
+
+%% ------------------------------------------------------------------
+%% gen_server API
+%% ------------------------------------------------------------------
+
+init([LAddr, RAddr, AppName]) ->
+ {ok, Sock} = gen_udp:open(0, [binary,
+ {ip, LAddr}, %% bind addr
+ {reuseaddr, true}]),
+ ok = gen_udp:connect(Sock, RAddr, ?GSMTAP_PORT),
+ {ok, #{sock => Sock,
+ app_name => AppName}}.
+
+
+handle_call(_Request, _From, S) ->
+ {reply, {error, not_implemented}, S}.
+
+
+handle_cast({log, LogEvent},
+ #{sock := Sock,
+ app_name := AppName} = S) ->
+ PDU = gsmtap_pdu(LogEvent#{app_name => AppName}),
+ gen_udp:send(Sock, PDU),
+ {noreply, S};
+
+handle_cast(_Request, S) ->
+ {noreply, S}.
+
+
+terminate(_Reason, #{sock := Sock}) ->
+ gen_udp:close(Sock),
+ ok.
+
+
+%% ------------------------------------------------------------------
+%% private API
+%% ------------------------------------------------------------------
+
+-spec gsmtap_pdu(map()) -> binary().
+gsmtap_pdu(#{msg := Msg,
+ level := Level,
+ app_name := AppName,
+ meta := #{pid := Pid,
+ time := Time} = Meta}) ->
+ << ?GSMTAP_VERSION,
+ ?GSMTAP_HDR_LEN,
+ ?GSMTAP_TYPE_OSMOCORE_LOG,
+ 16#00:(128 - 3 * 8), %% padding
+ (Time div 1_000_000):32, %% seconds
+ (Time rem 1_000_000):32, %% microseconds
+ (charbuf(AppName, 16))/bytes, %% process name
+ 16#00:32, %% dummy, Pid goes to subsys
+ (log_level(Level)),
+ 16#00:24, %% padding
+ (charbuf(pid_to_list(Pid), 16))/bytes, %% subsys
+ (charbuf(filename(Meta), 32))/bytes, %% filename
+ (maps:get(line, Meta, 0)):32, %% line number
+ (list_to_binary(msg2str(Msg)))/bytes %% the message
+ >>.
+
+
+-type log_event_msg() :: {io:format(), [term()]} |
+ {report, logger:report()} |
+ {string, unicode:chardata()}.
+-spec msg2str(log_event_msg()) -> string().
+msg2str({string, Str}) ->
+ Str;
+
+msg2str({report, Report}) ->
+ %% TODO: use report_cb() here
+ io_lib:format("~p", [Report]);
+
+msg2str({FmtStr, Args}) ->
+ io_lib:format(FmtStr, Args).
+
+
+filename(#{file := FileName}) ->
+ filename:basename(FileName);
+
+filename(#{}) -> "(none)".
+
+
+-spec charbuf(Str0, Size) -> binary()
+ when Str0 :: string(),
+ Size :: non_neg_integer().
+charbuf(Str0, Size) ->
+ Str1 = string:slice(Str0, 0, Size - 1), %% truncate, if needed
+ Str2 = string:pad(Str1, Size, trailing, 16#00), %% pad, if needed
+ list_to_binary(Str2).
+
+
+-spec log_level(atom()) -> 0..255.
+log_level(debug) -> 1;
+log_level(info) -> 3;
+log_level(notice) -> 5;
+log_level(warning) -> 6; %% XXX: non-standard
+log_level(error) -> 7;
+log_level(critical) -> 8;
+log_level(alert) -> 9; %% XXX: non-standard
+log_level(emergency) -> 11; %% XXX: non-standard
+log_level(_) -> 255. %% XXX: non-standard
+
+
+%% vim:set ts=4 sw=4 et:
diff --git a/src/logger_gsmtap_h.erl b/src/logger_gsmtap_h.erl
new file mode 100644
index 0000000..c3cba56
--- /dev/null
+++ b/src/logger_gsmtap_h.erl
@@ -0,0 +1,89 @@
+%% Copyright (C) 2025 by sysmocom - s.f.m.c. GmbH <info(a)sysmocom.de>
+%% Author: Vadim Yanitskiy <vyanitskiy(a)sysmocom.de>
+%%
+%% All Rights Reserved
+%%
+%% SPDX-License-Identifier: MPL-2.0
+%%
+%% This Source Code Form is subject to the terms of the Mozilla Public
+%% License, v. 2.0. If a copy of the MPL was not distributed with this
+%% file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+-module(logger_gsmtap_h).
+
+-moduledoc """
+GSMTAP logging handler.
+""".
+
+-behaviour(logger_handler).
+
+%% logger_handler callbacks
+-export([adding_handler/1,
+ removing_handler/1,
+ filter_config/1,
+ log/2]).
+
+-define(LADDR_DEFAULT, "0.0.0.0").
+-define(RADDR_DEFAULT, "127.0.0.1").
+-define(APP_NAME_DEFAULT, unknown).
+
+
+%% ------------------------------------------------------------------
+%% logger_handler API
+%% ------------------------------------------------------------------
+
+-spec adding_handler(logger_handler:config()) -> {ok, logger_handler:config()} |
+ {error, term()}.
+adding_handler(Config) ->
+ HConfig = maps:get(config, Config, #{}),
+ LAddr = ipaddr(maps:get(loc_addr, HConfig, ?LADDR_DEFAULT)),
+ RAddr = ipaddr(maps:get(rem_addr, HConfig, ?RADDR_DEFAULT)),
+ AppName = app_name(maps:get(app_name, HConfig, ?APP_NAME_DEFAULT)),
+ {ok, Pid} = logger_gsmtap:start(LAddr, RAddr, AppName),
+ {ok, Config#{config => HConfig#{pid => Pid,
+ loc_addr => LAddr,
+ rem_addr => RAddr,
+ app_name => AppName}}}.
+
+
+-spec removing_handler(logger_handler:config()) -> ok.
+removing_handler(#{config := #{pid := Pid}}) ->
+ logger_gsmtap:stop(Pid),
+ ok.
+
+
+-spec filter_config(logger_handler:config()) -> logger_handler:config().
+filter_config(#{config := HConfig} = Config) ->
+ Config#{config => maps:without([pid], HConfig)}.
+
+
+-spec log(logger:log_event(), logger_handler:config()) -> term().
+log(LogEvent, #{config := #{pid := Pid}}) ->
+ logger_gsmtap:log(Pid, LogEvent).
+
+
+%% ------------------------------------------------------------------
+%% private API
+%% ------------------------------------------------------------------
+
+-spec ipaddr(Addr0) -> Addr1
+ when Addr0 :: string() | inet:ip_address(),
+ Addr1 :: inet:ip_address().
+ipaddr(AddrStr) when is_list(AddrStr) ->
+ {ok, Addr} = inet:parse_address(AddrStr),
+ Addr;
+
+ipaddr(Addr) ->
+ true = inet:is_ip_address(Addr),
+ Addr.
+
+
+-spec app_name(string() | atom()) -> string().
+app_name(AppName) when is_list(AppName) ->
+ AppName;
+
+app_name(AppName) when is_atom(AppName) ->
+ atom_to_list(AppName).
+
+
+%% vim:set ts=4 sw=4 et:
--
To view, visit https://gerrit.osmocom.org/c/erlang/logger_gsmtap/+/39552?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: erlang/logger_gsmtap
Gerrit-Branch: master
Gerrit-Change-Id: I30fad55b6e9d8d9f975de4deb2f97c1e98ae5c5e
Gerrit-Change-Number: 39552
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Attention is currently required from: fixeria, laforge, osmith, pespin.
Hello Jenkins Builder, laforge, osmith, pespin,
I'd like you to reexamine a change. Please visit
https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/39415?usp=email
to look at the new patch set (#8).
The following approvals got outdated and were removed:
Code-Review+1 by laforge, Code-Review+1 by pespin, Verified+1 by Jenkins Builder
Change subject: Add GSMTAP logging handler
......................................................................
Add GSMTAP logging handler
This patch integrates a logging handler [1][2] for Erlang's built-in
logger. It sends logging messages via GSMTAP (udp/4729), allowing
capture of log messages alongside with other PDUs (S1AP, PFCP)
sent/received by the gateway.
The new handler is added to the example configuration, sending
all logging messages (DEBUG and above) to 127.0.0.1 by default.
[1] https://www.erlang.org/doc/apps/kernel/logger_handler.html
[2] https://gitea.osmocom.org/erlang/logger_gsmtap
Change-Id: Iea884e2ca146b852c64bd9f135d8c71f4c925f09
---
M config/sys.config
M rebar.config
M rebar.lock
M src/osmo_s1gw.app.src
4 files changed, 15 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/erlang/osmo-s1gw refs/changes/15/39415/8
--
To view, visit https://gerrit.osmocom.org/c/erlang/osmo-s1gw/+/39415?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: newpatchset
Gerrit-Project: erlang/osmo-s1gw
Gerrit-Branch: master
Gerrit-Change-Id: Iea884e2ca146b852c64bd9f135d8c71f4c925f09
Gerrit-Change-Number: 39415
Gerrit-PatchSet: 8
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: osmith <osmith(a)sysmocom.de>
Gerrit-Attention: laforge <laforge(a)osmocom.org>
Gerrit-Attention: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/39540?usp=email )
Change subject: gsmtap: fix outdated header version in comment
......................................................................
gsmtap: fix outdated header version in comment
Change-Id: Iee4cbd5f8699ed7da28a0f9ac5856b435e76b86a
---
M include/osmocom/core/gsmtap.h
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
laforge: Looks good to me, approved
Jenkins Builder: Verified
pespin: Looks good to me, but someone else must approve
diff --git a/include/osmocom/core/gsmtap.h b/include/osmocom/core/gsmtap.h
index ebb5296..d153efc 100644
--- a/include/osmocom/core/gsmtap.h
+++ b/include/osmocom/core/gsmtap.h
@@ -303,7 +303,7 @@
/* ====== DO NOT MAKE UNAPPROVED MODIFICATIONS HERE ===== */
/*! Structure of the GSMTAP pseudo-header */
struct gsmtap_hdr {
- uint8_t version; /*!< version, set to 0x01 currently */
+ uint8_t version; /*!< version, set to GSMTAP_VERSION */
uint8_t hdr_len; /*!< length in number of 32bit words */
uint8_t type; /*!< see GSMTAP_TYPE_* */
uint8_t timeslot; /*!< timeslot (0..7 on Um) */
--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/39540?usp=email
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Iee4cbd5f8699ed7da28a0f9ac5856b435e76b86a
Gerrit-Change-Number: 39540
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>