Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-Spgwu-Tiny-Simple
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
CommunityXG
OpenXG-Spgwu-Tiny-Simple
Commits
ab5955c0
Commit
ab5955c0
authored
Sep 23, 2019
by
lionelgo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log options: stdout/rotate file (args options)
parent
8792d6c1
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
68 additions
and
41 deletions
+68
-41
build/scripts/build_helper.spgw
build/scripts/build_helper.spgw
+2
-0
src/common/logger.cpp
src/common/logger.cpp
+13
-20
src/common/logger.hpp
src/common/logger.hpp
+3
-3
src/oai_spgwc/main.cpp
src/oai_spgwc/main.cpp
+4
-2
src/oai_spgwc/options.cpp
src/oai_spgwc/options.cpp
+13
-5
src/oai_spgwc/options.hpp
src/oai_spgwc/options.hpp
+8
-2
src/oai_spgwu/main.cpp
src/oai_spgwu/main.cpp
+4
-2
src/oai_spgwu/options.cpp
src/oai_spgwu/options.cpp
+13
-5
src/oai_spgwu/options.hpp
src/oai_spgwu/options.hpp
+8
-2
No files found.
build/scripts/build_helper.spgw
View file @
ab5955c0
...
...
@@ -97,6 +97,8 @@ install_spdlog_from_git() {
git clone $GIT_URL
cd spdlog && git checkout master
ret=$?;[[ $ret -ne 0 ]] && popd && return $ret
# enable syslog, Useless (defined in SPGW code)
sed -i '/#define SPDLOG_ENABLE_SYSLOG/s/^\/\///g' include/spdlog/tweakme.h
popd
fi
return 0
...
...
src/common/logger.cpp
View file @
ab5955c0
...
...
@@ -15,6 +15,7 @@
*/
#include "logger.hpp"
#include "spdlog/sinks/syslog_sink.h"
#include <iostream>
#include <sstream>
...
...
@@ -23,37 +24,29 @@
Logger
*
Logger
::
m_singleton
=
NULL
;
void
Logger
::
_init
(
const
char
*
app
)
void
Logger
::
_init
(
const
char
*
app
,
const
bool
log_stdout
,
bool
const
log_rot_file
)
{
int
num_sinks
=
0
;
spdlog
::
set_async_mode
(
2048
);
#if TRACE_IS_ON
spdlog
::
level
::
level_enum
llevel
=
spdlog
::
level
::
trace
;
m_sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
ansicolor_stdout_sink_mt
>
()
);
std
::
string
filename
=
fmt
::
format
(
"./{}.log"
,
app
);
m_sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
rotating_file_sink_mt
>
(
filename
,
5
*
1024
*
1024
,
3
)
);
m_sinks
[
0
].
get
()
->
set_level
(
llevel
);
m_sinks
[
1
].
get
()
->
set_level
(
llevel
);
#elif DEBUG_IS_ON
spdlog
::
level
::
level_enum
llevel
=
spdlog
::
level
::
debug
;
m_sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
ansicolor_stdout_sink_mt
>
()
);
std
::
string
filename
=
fmt
::
format
(
"./{}.log"
,
app
);
m_sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
rotating_file_sink_mt
>
(
filename
,
5
*
1024
*
1024
,
3
)
);
m_sinks
[
0
].
get
()
->
set_level
(
llevel
);
m_sinks
[
1
].
get
()
->
set_level
(
llevel
);
#elif INFO_IS_ON
spdlog
::
level
::
level_enum
llevel
=
spdlog
::
level
::
info
;
m_sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
ansicolor_stdout_sink_mt
>
()
);
std
::
string
filename
=
fmt
::
format
(
"./{}.log"
,
app
);
m_sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
rotating_file_sink_mt
>
(
filename
,
5
*
1024
*
1024
,
3
)
);
m_sinks
[
0
].
get
()
->
set_level
(
llevel
);
m_sinks
[
1
].
get
()
->
set_level
(
llevel
);
#else
spdlog
::
level
::
level_enum
llevel
=
spdlog
::
level
::
warn
;
std
::
string
filename
=
fmt
::
format
(
"./{}.log"
,
app
);
m_sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
rotating_file_sink_mt
>
(
filename
,
5
*
1024
*
1024
,
3
)
);
m_sinks
[
0
].
get
()
->
set_level
(
llevel
);
#endif
//m_sinks.push_back( std::make_shared<spdlog::sinks::syslog_sink>() );
if
(
log_stdout
)
{
std
::
string
filename
=
fmt
::
format
(
"./{}.log"
,
app
);
m_sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
ansicolor_stdout_sink_mt
>
()
);
m_sinks
[
num_sinks
++
].
get
()
->
set_level
(
llevel
);
}
if
(
log_rot_file
)
{
std
::
string
filename
=
fmt
::
format
(
"./{}.log"
,
app
);
m_sinks
.
push_back
(
std
::
make_shared
<
spdlog
::
sinks
::
rotating_file_sink_mt
>
(
filename
,
5
*
1024
*
1024
,
3
)
);
m_sinks
[
num_sinks
++
].
get
()
->
set_level
(
llevel
);
}
std
::
stringstream
ss
;
ss
<<
"[%Y-%m-%dT%H:%M:%S.%f] ["
<<
app
<<
"] [%n] [%l] %v"
;
...
...
src/common/logger.hpp
View file @
ab5955c0
...
...
@@ -74,8 +74,8 @@ class Logger
{
public:
static
void
init
(
const
char
*
app
)
{
singleton
().
_init
(
app
);
}
static
void
init
(
const
std
::
string
&
app
)
{
init
(
app
.
c_str
()
);
}
static
void
init
(
const
char
*
app
,
const
bool
log_stdout
,
const
bool
log_rot_file
)
{
singleton
().
_init
(
app
,
log_stdout
,
log_rot_file
);
}
static
void
init
(
const
std
::
string
&
app
,
const
bool
log_stdout
,
const
bool
log_rot_file
)
{
init
(
app
.
c_str
(),
log_stdout
,
log_rot_file
);
}
static
_Logger
&
async_cmd
()
{
return
*
singleton
().
m_async_cmd
;
}
static
_Logger
&
enb_s1u
()
{
return
*
singleton
().
m_enb_s1u
;
}
...
...
@@ -112,7 +112,7 @@ private:
Logger
()
{}
~
Logger
()
{}
void
_init
(
const
char
*
app
);
void
_init
(
const
char
*
app
,
const
bool
log_stdout
,
const
bool
log_rot_file
);
std
::
vector
<
spdlog
::
sink_ptr
>
m_sinks
;
...
...
src/oai_spgwc/main.cpp
View file @
ab5955c0
...
...
@@ -81,8 +81,6 @@ void my_app_signal_handler(int s)
int
main
(
int
argc
,
char
**
argv
)
{
srand
(
time
(
NULL
));
// Logger
Logger
::
init
(
"spgwc"
);
// Command line options
if
(
!
Options
::
parse
(
argc
,
argv
)
)
...
...
@@ -90,6 +88,10 @@ int main(int argc, char **argv)
std
::
cout
<<
"Options::parse() failed"
<<
std
::
endl
;
return
1
;
}
// Logger
Logger
::
init
(
"spgwc"
,
Options
::
getlogStdout
()
,
Options
::
getlogRotFilelog
());
Logger
::
sgwc_app
().
startup
(
"Options parsed"
);
struct
sigaction
sigIntHandler
;
...
...
src/oai_spgwc/options.cpp
View file @
ab5955c0
...
...
@@ -25,7 +25,8 @@
int
Options
::
options
;
std
::
string
Options
::
m_libconfigcfg
;
bool
Options
::
m_log_rot_file_log
;
bool
Options
::
m_log_stdout
;
void
Options
::
help
()
{
...
...
@@ -33,6 +34,8 @@ void Options::help()
<<
"Usage: spgwc [OPTIONS]..."
<<
std
::
endl
<<
" -h, --help Print help and exit"
<<
std
::
endl
<<
" -c, --libconfigcfg filename Read the application configuration from this file."
<<
std
::
endl
<<
" -o, --stdoutlog Send the application logs to STDOUT fd."
<<
std
::
endl
<<
" -r, --rotatelog Send the application logs to local file (in current working directory)."
<<
std
::
endl
;
}
...
...
@@ -64,21 +67,24 @@ bool Options::parseInputOptions( int argc, char **argv )
struct
option
long_options
[]
=
{
{
"help"
,
no_argument
,
NULL
,
'h'
},
{
"libconfigcfg"
,
required_argument
,
NULL
,
'f'
},
{
"stdoutlog"
,
no_argument
,
NULL
,
'o'
},
{
"rotatelog"
,
no_argument
,
NULL
,
'r'
},
{
NULL
,
0
,
NULL
,
0
}
};
// Loop on arguments
while
(
1
)
{
c
=
getopt_long
(
argc
,
argv
,
"hc:"
,
long_options
,
&
option_index
);
c
=
getopt_long
(
argc
,
argv
,
"h
or
c:"
,
long_options
,
&
option_index
);
if
(
c
==
-
1
)
break
;
// Exit from the loop.
switch
(
c
)
{
case
'h'
:
{
help
();
exit
(
0
);
break
;
}
case
'c'
:
{
m_libconfigcfg
=
optarg
;
options
|=
libconfigcfg
;
break
;
}
case
'h'
:
{
help
();
exit
(
0
);
break
;
}
case
'c'
:
{
m_libconfigcfg
=
optarg
;
options
|=
libconfigcfg
;
break
;
}
case
'o'
:
{
m_log_stdout
=
true
;
options
|=
log_stdout
;
break
;
}
case
'r'
:
{
m_log_rot_file_log
=
true
;
options
|=
log_rot_file_log
;
break
;
}
case
'?'
:
...
...
@@ -86,6 +92,8 @@ bool Options::parseInputOptions( int argc, char **argv )
switch
(
optopt
)
{
case
'c'
:
{
std
::
cout
<<
"Option -l (libconfig config) requires an argument"
<<
std
::
endl
;
break
;
}
case
'o'
:
{
std
::
cout
<<
"Option -o do not requires an argument, can be also set with option -r."
<<
std
::
endl
;
break
;
}
case
'r'
:
{
std
::
cout
<<
"Option -r do not requires an argument, can be also set with option -o."
<<
std
::
endl
;
break
;
}
default:
{
std
::
cout
<<
"Unrecognized option ["
<<
c
<<
"]"
<<
std
::
endl
;
break
;
}
}
result
=
false
;
...
...
src/oai_spgwc/options.hpp
View file @
ab5955c0
...
...
@@ -30,18 +30,24 @@ public:
static
bool
parseJson
();
static
bool
validateOptions
();
static
const
std
::
string
&
getlibconfigConfig
()
{
return
m_libconfigcfg
;
}
static
const
std
::
string
&
getlibconfigConfig
()
{
return
m_libconfigcfg
;
}
static
const
bool
&
getlogRotFilelog
()
{
return
m_log_rot_file_log
;
}
static
const
bool
&
getlogStdout
()
{
return
m_log_stdout
;
}
private:
enum
OptionsSelected
{
libconfigcfg
=
0x01
,
libconfigcfg
=
0x01
,
log_stdout
=
0x02
,
log_rot_file_log
=
0x04
};
static
void
help
();
static
int
options
;
static
bool
m_log_rot_file_log
;
static
bool
m_log_stdout
;
static
std
::
string
m_libconfigcfg
;
};
...
...
src/oai_spgwu/main.cpp
View file @
ab5955c0
...
...
@@ -63,8 +63,6 @@ void my_app_signal_handler(int s){
//------------------------------------------------------------------------------
int
main
(
int
argc
,
char
**
argv
)
{
// Logger
Logger
::
init
(
"spgwu"
);
// Command line options
if
(
!
Options
::
parse
(
argc
,
argv
)
)
...
...
@@ -72,6 +70,10 @@ int main(int argc, char **argv)
std
::
cout
<<
"Options::parse() failed"
<<
std
::
endl
;
return
1
;
}
// Logger
Logger
::
init
(
"spgwu"
,
Options
::
getlogStdout
()
,
Options
::
getlogRotFilelog
());
Logger
::
spgwu_app
().
startup
(
"Options parsed"
);
struct
sigaction
sigIntHandler
;
...
...
src/oai_spgwu/options.cpp
View file @
ab5955c0
...
...
@@ -25,7 +25,8 @@
int
Options
::
options
;
std
::
string
Options
::
m_libconfigcfg
;
bool
Options
::
m_log_rot_file_log
;
bool
Options
::
m_log_stdout
;
void
Options
::
help
()
{
...
...
@@ -33,6 +34,8 @@ void Options::help()
<<
"Usage: spgwu [OPTIONS]..."
<<
std
::
endl
<<
" -h, --help Print help and exit"
<<
std
::
endl
<<
" -c, --libconfigcfg filename Read the application configuration from this file."
<<
std
::
endl
<<
" -o, --stdoutlog Send the application logs to STDOUT fd."
<<
std
::
endl
<<
" -r, --rotatelog Send the application logs to local file (in current working directory)."
<<
std
::
endl
;
}
...
...
@@ -64,21 +67,24 @@ bool Options::parseInputOptions( int argc, char **argv )
struct
option
long_options
[]
=
{
{
"help"
,
no_argument
,
NULL
,
'h'
},
{
"libconfigcfg"
,
required_argument
,
NULL
,
'f'
},
{
"stdoutlog"
,
no_argument
,
NULL
,
'o'
},
{
"rotatelog"
,
no_argument
,
NULL
,
'r'
},
{
NULL
,
0
,
NULL
,
0
}
};
// Loop on arguments
while
(
1
)
{
c
=
getopt_long
(
argc
,
argv
,
"hc:"
,
long_options
,
&
option_index
);
c
=
getopt_long
(
argc
,
argv
,
"h
or
c:"
,
long_options
,
&
option_index
);
if
(
c
==
-
1
)
break
;
// Exit from the loop.
switch
(
c
)
{
case
'h'
:
{
help
();
exit
(
0
);
break
;
}
case
'c'
:
{
m_libconfigcfg
=
optarg
;
options
|=
libconfigcfg
;
break
;
}
case
'h'
:
{
help
();
exit
(
0
);
break
;
}
case
'c'
:
{
m_libconfigcfg
=
optarg
;
options
|=
libconfigcfg
;
break
;
}
case
'o'
:
{
m_log_stdout
=
true
;
options
|=
log_stdout
;
break
;
}
case
'r'
:
{
m_log_rot_file_log
=
true
;
options
|=
log_rot_file_log
;
break
;
}
case
'?'
:
...
...
@@ -86,6 +92,8 @@ bool Options::parseInputOptions( int argc, char **argv )
switch
(
optopt
)
{
case
'c'
:
{
std
::
cout
<<
"Option -l (libconfig config) requires an argument"
<<
std
::
endl
;
break
;
}
case
'o'
:
{
std
::
cout
<<
"Option -o do not requires an argument, can be also set with option -r."
<<
std
::
endl
;
break
;
}
case
'r'
:
{
std
::
cout
<<
"Option -r do not requires an argument, can be also set with option -o."
<<
std
::
endl
;
break
;
}
default:
{
std
::
cout
<<
"Unrecognized option ["
<<
c
<<
"]"
<<
std
::
endl
;
break
;
}
}
result
=
false
;
...
...
src/oai_spgwu/options.hpp
View file @
ab5955c0
...
...
@@ -30,18 +30,24 @@ public:
static
bool
parseJson
();
static
bool
validateOptions
();
static
const
std
::
string
&
getlibconfigConfig
()
{
return
m_libconfigcfg
;
}
static
const
std
::
string
&
getlibconfigConfig
()
{
return
m_libconfigcfg
;
}
static
const
bool
&
getlogRotFilelog
()
{
return
m_log_rot_file_log
;
}
static
const
bool
&
getlogStdout
()
{
return
m_log_stdout
;
}
private:
enum
OptionsSelected
{
libconfigcfg
=
0x01
,
libconfigcfg
=
0x01
,
log_stdout
=
0x02
,
log_rot_file_log
=
0x04
};
static
void
help
();
static
int
options
;
static
bool
m_log_rot_file_log
;
static
bool
m_log_stdout
;
static
std
::
string
m_libconfigcfg
;
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment