stumpless 2.2.0
Loading...
Searching...
No Matches
severity_level_example.c

Demonstrates how to work with the severity levels of logged events.

Demonstrates how to work with the severity levels of logged events.

// SPDX-License-Identifier: Apache-2.0
/*
* Copyright 2020-2021 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.
*/
#include <stdlib.h>
#include <stumpless.h>
int
main( int argc, char **argv ) {
struct stumpless_target *target;
// setting up a target to the console for quick and easy results
target = stumpless_open_stdout_target( "severity level example" );
// this message will be logged with a severity level of INFO because there is
// no severity provided
stump_i( "this message will have INFO severity" );
// this message will have a severity level of EMERG because it takes the
// severity as one of its arguments
stumplog_i( STUMPLESS_FACILITY_KERN | STUMPLESS_SEVERITY_EMERG,
"THE SYSTEM IS DOWN!!!" );
// logging a message at each severity level
stump_em( "emergency!" );
stump_a( "alert!" );
stump_c( "critical!" );
stump_er( "error!" );
stump_w( "warning!" );
stump_n( "notice" );
stump_i( "informational" );
stump_d( "debug" );
stump_t( "trace" );
// the output of the above statements depends on what symbols are defined:
// without any extra symbols defined, this will result in these messages:
// <8>1 2020-07-14T20:01:30.930277Z Angus - 6505 - - emergency!
// <9>1 2020-07-14T20:01:30.931151Z Angus - 6505 - - alert!
// <10>1 2020-07-14T20:01:30.932863Z Angus - 6505 - - critical!
// <11>1 2020-07-14T20:01:30.933504Z Angus - 6505 - - error!
// <12>1 2020-07-14T20:01:30.935897Z Angus - 6505 - - warning!
// <13>1 2020-07-14T20:01:30.936486Z Angus - 6505 - - notice
// <14>1 2020-07-14T20:01:30.937814Z Angus - 6505 - - informational
// <15>1 2020-07-14T20:01:30.938356Z Angus - 6505 - - debug
// <15>1 2020-07-14T20:01:30.938627Z Angus - 6505 - [trace file="stumpless/docs/examples/severity_level/severity_level_example.c" line="50" function="main"] trace
// if you define the following symbols:
// STUMPLESS_DISABLE_WARNING_LEVEL
// STUMPLESS_DISABLE_CRIT_LEVEL
// STUMPLESS_DISABLE_EMERG_LEVEL
// this will result in these messages (note the missing ones):
// <9>1 2020-07-14T20:07:41.088757Z Angus - 6680 - - alert!
// <11>1 2020-07-14T20:07:41.089744Z Angus - 6680 - - error!
// <13>1 2020-07-14T20:07:41.090743Z Angus - 6680 - - notice
// <14>1 2020-07-14T20:07:41.093912Z Angus - 6680 - - informational
// <15>1 2020-07-14T20:07:41.094765Z Angus - 6680 - - debug
// <15>1 2020-07-14T20:07:41.094987Z Angus - 6505 - [trace file="stumpless/docs/examples/severity_level/severity_level_example.c" line="50" function="main"] trace
// if you define the STUMPLESS_ENABLE_UPTO_INFO symbol (or the equivalent
// STUMPLESS_DISABLE_DOWNTO_DEBUG symbol), this will result in these messages:
// <8>1 2020-07-14T20:08:57.060259Z Angus - 6686 - - emergency!
// <9>1 2020-07-14T20:08:57.061415Z Angus - 6686 - - alert!
// <10>1 2020-07-14T20:08:57.062374Z Angus - 6686 - - critical!
// <11>1 2020-07-14T20:08:57.063497Z Angus - 6686 - - error!
// <12>1 2020-07-14T20:08:57.064536Z Angus - 6686 - - warning!
// <13>1 2020-07-14T20:08:57.065685Z Angus - 6686 - - notice
// <14>1 2020-07-14T20:08:57.066834Z Angus - 6686 - - informational
// if you define STUMPLESS_DISABLE_ALL_LEVELS, then there will be no messages!
// closing our target
// final call required to completely free all resources (caches, etc.)
return EXIT_SUCCESS;
}
#define stump_a(...)
Logs a message to the current target with alert severity.
Definition alert.h:97
#define stump_c(...)
Logs a message to the current target with crit severity.
Definition crit.h:97
#define stump_d(...)
Logs a message to the current target with debug severity.
Definition debug.h:97
#define stump_em(...)
Logs a message to the current target with emerg severity.
Definition emerg.h:97
#define stump_er(...)
Logs a message to the current target with err severity.
Definition err.h:97
#define stump_i(...)
Logs a message to the current target with info severity.
Definition info.h:97
#define stumplog_i(priority,...)
Adds a message to the current target with the specified priority.
Definition info.h:508
STUMPLESS_PUBLIC_FUNCTION void stumpless_free_all(void)
Closes the default target if it has been opened, frees all memory allocated internally,...
#define stump_n(...)
Logs a message to the current target with notice severity.
Definition notice.h:97
STUMPLESS_PUBLIC_FUNCTION struct stumpless_target * stumpless_open_stdout_target(const char *name)
Opens a stream target for the stdout stream.
A target that log entries can be sent to.
Definition target.h:140
The main header file for the stumpless logging library.
STUMPLESS_PUBLIC_FUNCTION void stumpless_close_target(struct stumpless_target *target)
Closes a target.
#define stump_t(...)
Logs a message to the current target with debug severity, along with the file, line,...
Definition trace.h:106
#define stump_w(...)
Logs a message to the current target with warning severity.
Definition warning.h:97