Skip to content

Commit

Permalink
merge priority and prival files
Browse files Browse the repository at this point in the history
The functions for working with priority values were spread across two
source files name "priority" and "prival". This change consolidates
them to the "prival" files so that they are located in a single file
named consistently with existing struct members.
  • Loading branch information
goatshriek authored Jul 1, 2024
1 parent ab72891 commit 4ed5f17
Show file tree
Hide file tree
Showing 18 changed files with 334 additions and 386 deletions.
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cff-version: 1.2.0
title: Stumpless Logging Library
license: Apache-2.0
repository-code: "https://github.com/goatshriek/stumpless"
version: 2.2.0
date-released: 2024-05-26
version: 3.0.0
date-released: 2024-06-30
keywords:
- journald
- logging
Expand Down
13 changes: 4 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(POLICY CMP0135)
endif()

project(stumpless
VERSION 2.2.0
VERSION 3.0.0
)
set(CMAKE_PROJECT_HOMEPAGE_URL "https://goatshriek.github.io/stumpless/")

Expand Down Expand Up @@ -226,6 +226,7 @@ set(STUMPLESS_SOURCES
${PROJECT_SOURCE_DIR}/src/log.c
${PROJECT_SOURCE_DIR}/src/memory.c
${PROJECT_SOURCE_DIR}/src/param.c
${PROJECT_SOURCE_DIR}/src/prival.c
${PROJECT_SOURCE_DIR}/src/severity.c
${PROJECT_SOURCE_DIR}/src/strbuilder.c
${PROJECT_SOURCE_DIR}/src/strhelper.c
Expand All @@ -236,8 +237,6 @@ set(STUMPLESS_SOURCES
${PROJECT_SOURCE_DIR}/src/target/stream.c
${PROJECT_SOURCE_DIR}/src/version.c
${PROJECT_SOURCE_DIR}/src/validate.c
${PROJECT_SOURCE_DIR}/src/priority.c
${PROJECT_SOURCE_DIR}/src/prival.c
)


Expand Down Expand Up @@ -1081,10 +1080,6 @@ add_function_test(version
SOURCES ${PROJECT_SOURCE_DIR}/test/function/version.cpp
)

add_function_test(priority
SOURCES ${PROJECT_SOURCE_DIR}/test/function/priority.cpp
)

add_function_test(prival
SOURCES ${PROJECT_SOURCE_DIR}/test/function/prival.cpp
)
Expand Down Expand Up @@ -1138,8 +1133,8 @@ add_performance_test(element
SOURCES test/performance/element.cpp
)

add_performance_test(priority
SOURCES test/performance/priority.cpp
add_performance_test(prival
SOURCES "${PROJECT_SOURCE_DIR}/test/performance/prival.cpp"
)

add_performance_test(entry
Expand Down
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ fixes, check out the
[roadmap](https://github.com/goatshriek/stumpless/blob/master/docs/roadmap.md).


## [3.0.0] - 2024-06-30
### Removed
- `stumpless/priority.h`, which was merged into `stumpless/prival.h`.


## [2.2.0] - 2024-05-26
### Added
- @since format check enforcement in CI pipeline.
Expand Down
30 changes: 1 addition & 29 deletions include/private/entry.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 */

/*
* Copyright 2018-2023 Joel E. Anderson
* Copyright 2018-2024 Joel E. Anderson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,34 +46,6 @@
void
entry_free_all( void );

/**
* Gets the priority value from facility and severity parameters.
*
* Priority value is calculated by left shifting the facility value by 3
* and adding it to the severity value which is according to the
* RFC 5424 Section 6.2.1. The shift operation is done prior to get_prival()
* function with macros in "facility.h"
*
* **Thread Safety: MT-Safe**
* This function is thread safe.
*
* **Async Signal Safety: AS-Safe **
* This function must be safe to call from signal handlers
*
* **Async Cancel Safety: AC-Safe**
* This function must be safe to call from threads that may be asynchronously
* cancelled.
*
* @param facility Facility value. This should be a \c STUMPLESS_FACILITY value.
*
* @param severity Severity value. This should be a \c STUMPLESS_SEVERITY value
*
* @return Priority value
*/
int
get_prival( enum stumpless_facility facility,
enum stumpless_severity severity );

/**
* Locks the mutex within the entry.
*
Expand Down
55 changes: 55 additions & 0 deletions include/private/prival.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* SPDX-License-Identifier: Apache-2.0 */

/*
* Copyright 2018-2024 Joel E. Anderson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef __STUMPLESS_PRIVATE_PRIVAL_H
#define __STUMPLESS_PRIVATE_PRIVAL_H

#include <stumpless/facility.h>
#include <stumpless/severity.h>

/**
* Gets the priority value from facility and severity parameters.
*
* Priority value is calculated by left shifting the facility value by 3
* and adding it to the severity value which is according to the
* RFC 5424 Section 6.2.1. The shift operation is done prior to get_prival()
* function with macros in "facility.h"
*
* Moved from "private/entry.h" to "private/prival.h" in release v3.0.0.
*
* **Thread Safety: MT-Safe**
* This function is thread safe.
*
* **Async Signal Safety: AS-Safe **
* This function must be safe to call from signal handlers
*
* **Async Cancel Safety: AC-Safe**
* This function must be safe to call from threads that may be asynchronously
* cancelled.
*
* @param facility Facility value. This should be a \c STUMPLESS_FACILITY value.
*
* @param severity Severity value. This should be a \c STUMPLESS_SEVERITY value
*
* @return Priority value
*/
int
get_prival( enum stumpless_facility facility,
enum stumpless_severity severity );

#endif /* __STUMPLESS_PRIVATE_PRIVAL_H */
3 changes: 1 addition & 2 deletions include/stumpless.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
#include <stumpless/memory.h>
#include <stumpless/option.h>
#include <stumpless/param.h>
#include <stumpless/prival.h>
#include <stumpless/severity.h>
#include <stumpless/target.h>
#include <stumpless/target/buffer.h>
Expand All @@ -204,8 +205,6 @@
#include <stumpless/target/sqlite3.h>
#include <stumpless/target/stream.h>
#include <stumpless/version.h>
#include <stumpless/priority.h>
#include <stumpless/prival.h>

#ifdef STUMPLESS_CHAIN_TARGETS_SUPPORTED
/** @example chain_example.c
Expand Down
66 changes: 0 additions & 66 deletions include/stumpless/priority.h

This file was deleted.

38 changes: 36 additions & 2 deletions include/stumpless/prival.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* SPDX-License-Identifier: Apache-2.0 */

/*
* Copyright 2024 Joel E. Anderson
* Copyright 2022-2024 Joel E. Anderson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,8 @@
*/

/** @file
* Functions for working with privals.
* Functions for working with privals, which contain both facility and
* severity values.
*
* @since release v2.2.0
*/
Expand All @@ -30,6 +31,7 @@
#ifdef __cplusplus
extern "C" {
#endif

/**
* Gets the string representation of the given prival.
*
Expand Down Expand Up @@ -57,6 +59,38 @@ STUMPLESS_PUBLIC_FUNCTION
const char *
stumpless_get_prival_string( int prival );

/**
* Extract PRIVAL number (Facility and Severity) from the given string with
* the direct number or with two names divided with a period in the order:
* facility first, then severity ("<facility_descr>.<severity_descr>").
*
* In release v2.2.0 this function was in a separate header
* "stumpless/priority.h". This header was consolidated into
* "stumpless/prival.h" in release v3.0.0.
*
* **Thread Safety: MT-Safe**
* This function is thread safe. A mutex is used to coordinate changes to the
* target while it is being read.
*
* **Async Signal Safety: AS-Unsafe lock**
* This function is not safe to call from signal handlers due to the use of a
* non-reentrant lock to coordinate the read of the target.
*
* **Async Cancel Safety: AC-Unsafe lock**
* This function is not safe to call from threads that may be asynchronously
* cancelled, due to the use of a lock that could be left locked..
*
* @since release v2.2.0
*
* @param string The string to extract the prival from.
*
* @return the PRIVAL number used for the severity and facility values of
* the logged entry, in the event of an error it returns -1.
*/
STUMPLESS_PUBLIC_FUNCTION
int
stumpless_prival_from_string( const char *string );

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down
7 changes: 1 addition & 6 deletions src/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "private/entry.h"
#include "private/error.h"
#include "private/facility.h"
#include "private/prival.h"
#include "private/severity.h"
#include "private/strbuilder.h"
#include "private/strhelper.h"
Expand Down Expand Up @@ -1220,12 +1221,6 @@ entry_free_all( void ) {
entry_cache = NULL;
}

int
get_prival( enum stumpless_facility facility,
enum stumpless_severity severity ) {
return facility | severity;
}

void
lock_entry( const struct stumpless_entry *entry ) {
config_lock_mutex( entry->mutex );
Expand Down
Loading

0 comments on commit 4ed5f17

Please sign in to comment.