summaryrefslogtreecommitdiffstats
path: root/vespalog
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2022-09-14 12:40:44 +0000
committerArne Juul <arnej@yahooinc.com>2022-09-14 12:40:44 +0000
commit4abd7cb5a849bfd495a18fe1318321d339c96eab (patch)
tree27d083409ae838c21726512c71dcf0b30cf0022e /vespalog
parent1f99dece721715fea08424c6f5968af8425b9d92 (diff)
simpler without generating code
Diffstat (limited to 'vespalog')
-rw-r--r--vespalog/src/vespa/log/.gitignore1
-rw-r--r--vespalog/src/vespa/log/CMakeLists.txt10
-rw-r--r--vespalog/src/vespa/log/loglevelnames.cpp33
-rwxr-xr-xvespalog/src/vespa/log/mknm.pl46
4 files changed, 34 insertions, 56 deletions
diff --git a/vespalog/src/vespa/log/.gitignore b/vespalog/src/vespa/log/.gitignore
index 7b45206e869..290968e7bfd 100644
--- a/vespalog/src/vespa/log/.gitignore
+++ b/vespalog/src/vespa/log/.gitignore
@@ -3,6 +3,5 @@
.depend
Makefile
logctl
-loglevelnames.cpp
logtest
logtest.logcontrol
diff --git a/vespalog/src/vespa/log/CMakeLists.txt b/vespalog/src/vespa/log/CMakeLists.txt
index 1b68a53ad3d..dbeba17334b 100644
--- a/vespalog/src/vespa/log/CMakeLists.txt
+++ b/vespalog/src/vespa/log/CMakeLists.txt
@@ -2,7 +2,7 @@
vespa_add_library(vespalog
SOURCES
exceptions.cpp
- ${CMAKE_CURRENT_BINARY_DIR}/loglevelnames.cpp
+ loglevelnames.cpp
log.cpp
bufferedlogger.cpp
log-target-fd.cpp
@@ -18,11 +18,3 @@ vespa_add_library(vespalog
reject-filter.cpp
INSTALL lib64
)
-
-add_custom_command(
- OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/loglevelnames.cpp
- COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/mknm.pl < ${CMAKE_CURRENT_SOURCE_DIR}/log.h > lln.NEW && mv lln.NEW ${CMAKE_CURRENT_BINARY_DIR}/loglevelnames.cpp
- MAIN_DEPENDENCY log.h
- DEPENDENCIES mknm.pl
-)
-
diff --git a/vespalog/src/vespa/log/loglevelnames.cpp b/vespalog/src/vespa/log/loglevelnames.cpp
new file mode 100644
index 00000000000..4b571b23994
--- /dev/null
+++ b/vespalog/src/vespa/log/loglevelnames.cpp
@@ -0,0 +1,33 @@
+#include <string.h>
+#include <vespa/log/log.h>
+
+namespace ns_log {
+
+enum Logger::LogLevel
+Logger::parseLevel(const char *lname)
+{
+ if (strcmp(lname, "fatal") == 0) return fatal;
+ if (strcmp(lname, "error") == 0) return error;
+ if (strcmp(lname, "warning") == 0) return warning;
+ if (strcmp(lname, "config") == 0) return config;
+ if (strcmp(lname, "info") == 0) return info;
+ if (strcmp(lname, "event") == 0) return event;
+ if (strcmp(lname, "debug") == 0) return debug;
+ if (strcmp(lname, "spam") == 0) return spam;
+ // bad level name signaled by NUM_LOGLEVELS
+ return NUM_LOGLEVELS;
+}
+
+const char *Logger::logLevelNames[] = {
+ "fatal",
+ "error",
+ "warning",
+ "config",
+ "info",
+ "event",
+ "debug",
+ "spam",
+ 0 // converting NUM_LOGLEVELS gives null pointer
+};
+
+} // namespace
diff --git a/vespalog/src/vespa/log/mknm.pl b/vespalog/src/vespa/log/mknm.pl
deleted file mode 100755
index 9aa2f6310ce..00000000000
--- a/vespalog/src/vespa/log/mknm.pl
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/usr/bin/perl
-# Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-while (<>) {
- if ( s/.*\benum\s+LogLevel\s*\{// ) {
- chomp;
- $t = $_;
- while (<>) {
- if ( s/\}.*// ) {
- $t .= $_;
- $t =~ s/,/ /g;
- @t = split(" ", $t);
- if ( $t[$#t] ne "NUM_LOGLEVELS" ) {
- die "expected NUM_LOGLEVELS got '$t[$#t]'\n";
- }
- pop @t;
- makecpp();
- }
- $t .= $_;
- }
- }
-}
-die "did not find enum\n";
-
-sub makecpp
-{
- print "#include <string.h>\n";
- print '#include <vespa/log/log.h>';
- print "\n\n" . "namespace ns_log {" . "\n\n";
-
- print "enum Logger::LogLevel\n";
- print "Logger::parseLevel(const char *lname)\n{\n";
- foreach $l ( @t ) {
- print " if (strcmp(lname, \"$l\") == 0) return $l;\n";
- }
- print " // bad level name signaled by NUM_LOGLEVELS\n";
- print " return NUM_LOGLEVELS;\n";
- print "}\n\n";
-
- print "const char *Logger::logLevelNames[] = {" . "\n ";
- foreach $l ( @t ) { $l = "\"$l\""; }
- push @t, "0 // converting NUM_LOGLEVELS gives null pointer\n";
- print join(",\n ", @t);
- print "};\n\n} // namespace\n";
- exit(0);
-}