Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
maestro-core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
maestro
maestro-core
Commits
4dd3dbf6
Commit
4dd3dbf6
authored
4 years ago
by
Utz-Uwe Haus
Browse files
Options
Downloads
Patches
Plain Diff
implement support for string-named debug levels
parent
01f6b912
No related branches found
No related tags found
2 merge requests
!3
Jsc ci update
,
!2
update JSC-CI branch to devel
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
maestro/logging.c
+48
-12
48 additions, 12 deletions
maestro/logging.c
with
48 additions
and
12 deletions
maestro/logging.c
+
48
−
12
View file @
4dd3dbf6
...
...
@@ -5,6 +5,7 @@
**/
/*
* Copyright (C) 2019 Cray Computer GmbH
* Copyright (C) 2020 HPE, HP Schweiz GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
...
...
@@ -38,6 +39,7 @@
#include
"maestro/i_globals.h"
#include
"maestro/i_statistics.h"
#include
<errno.h>
#include
<ctype.h>
#include
<pthread.h>
#ifdef HAVE_PTHREAD_NP_H
...
...
@@ -259,7 +261,6 @@ mstro__ensure_threadid(void)
static
_Atomic
(
bool
)
g_queried_env
=
false
;
/* log destination choice */
static
int
g_log_dst
=
MSTRO_LOG_DST_STDERR
;
static
char
*
g_env_debug_flag
=
NULL
;
static
uint64_t
g_log_module_mask
=
MSTRO_LOG_MODULE_ALL
;
...
...
@@ -332,15 +333,39 @@ const char *mstro_log_module_name(uint64_t module)
return
"???"
;
}
static
inline
int
mstro_log__parse_debug_level
(
const
char
*
debug_level
)
{
/* FIXME: improve when merging with libERL */
if
(
strncasecmp
(
debug_level
,
"noise"
,
1
)
==
0
)
{
return
MSTRO_LOG_NOISE
;
}
else
if
(
strncasecmp
(
debug_level
,
"debug"
,
1
)
==
0
)
{
return
MSTRO_LOG_DEBUG
;
}
else
if
(
strncasecmp
(
debug_level
,
"info"
,
1
)
==
0
)
{
return
MSTRO_LOG_INFO
;
}
else
if
(
strncasecmp
(
debug_level
,
"warn"
,
1
)
==
0
)
{
return
MSTRO_LOG_WARN
;
}
else
if
(
strncasecmp
(
debug_level
,
"err"
,
1
)
==
0
)
{
return
MSTRO_LOG_ERR
;
}
else
{
return
MSTRO_MAX_LOG_LEVEL
;
/* default */
}
}
/* one-time init function for log infrastructure */
static
inline
void
mstro_log__init
()
{
_Atomic
(
bool
)
already_initialized
=
atomic_exchange
(
&
g_queried_env
,
true
);
if
(
!
already_initialized
)
{
pthread_mutex_t
mtx
=
PTHREAD_MUTEX_INITIALIZER
;
int
err
=
pthread_mutex_lock
(
&
mtx
);
if
(
err
!=
0
)
abort
();
if
(
!
g_queried_env
)
{
/* we're the first ones, do init */
g_queried_env
=
true
;
g_pid
=
getpid
();
const
char
*
env_log_dst
=
getenv
(
MSTRO_ENV_LOG_DST
);
...
...
@@ -361,22 +386,26 @@ mstro_log__init()
}
}
g_env_debug_flag
=
getenv
(
MSTRO_ENV_LOG_LEVEL
);
if
(
g_env_debug_flag
!=
NULL
)
{
int
env_level
=
atoi
(
g_env_debug_flag
);
if
(
env_level
<
0
||
env_level
>=
MSTRO_log__MAX
)
{
char
*
env_debug_level
=
getenv
(
MSTRO_ENV_LOG_LEVEL
);
if
(
env_debug_level
!=
NULL
)
{
if
(
isalpha
(
env_debug_level
[
0
]))
{
g_debug_level
=
mstro_log__parse_debug_level
(
env_debug_level
);
}
else
{
g_debug_level
=
atoi
(
env_debug_level
);
}
if
(
g_debug_level
<
0
||
g_debug_level
>=
MSTRO_log__MAX
)
{
LOG_WARN
(
MSTRO_LOG_MODULE_CORE
,
"Attempt to set debug level to %s in environment variable %s, ignored
\n
"
,
g_env_debug_flag
,
MSTRO_ENV_LOG_LEVEL
);
g_debug_level
,
MSTRO_ENV_LOG_LEVEL
);
g_debug_level
=
MSTRO_MAX_LOG_LEVEL
;
}
else
{
g_debug_level
=
MIN
(
MSTRO_MAX_LOG_LEVEL
,
env
_level
);
g_debug_level
=
MIN
(
MSTRO_MAX_LOG_LEVEL
,
g_debug
_level
);
}
LOG_INFO
(
MSTRO_LOG_MODULE_CORE
,
"Environment variable %s sets log level to %d
\n
"
,
MSTRO_ENV_LOG_LEVEL
,
g_debug_level
);
}
char
*
env_log_color
=
getenv
(
MSTRO_ENV_LOG_COLOR
);
if
(
env_log_color
!=
NULL
)
{
enum
ansi_color_symbol
i
;
...
...
@@ -412,7 +441,14 @@ mstro_log__init()
/* thread ID can't be set here, every thread sets it at first call */
}
else
{
/* we're not the first */
LOG_DEBUG
(
MSTRO_LOG_MODULE_CORE
,
"Competing init, lost to other thread
\n
"
);
}
err
=
pthread_mutex_unlock
(
&
mtx
);
if
(
err
!=
0
)
abort
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment