-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: log runtime output to env var "BPFTIME_LOG_OUTPUT"
- Loading branch information
Showing
9 changed files
with
88 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "spdlog/spdlog.h" | ||
#include "spdlog/cfg/env.h" | ||
#include "spdlog/sinks/basic_file_sink.h" | ||
#include "spdlog/sinks/stdout_color_sinks.h" | ||
|
||
namespace bpftime { | ||
|
||
void bpftime_set_logger_from_env(); | ||
|
||
/* | ||
Set global logger for this process. | ||
- "console": Default. Output to stderr. Suggested for temporary debugging. | ||
- "syslog": Output to syslog. Suggested for daemon as deployed service. | ||
- some file path. Output to file. | ||
*/ | ||
void bpftime_set_logger(const std::string& target); | ||
|
||
void bpftime_logger_flush(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* SPDX-License-Identifier: MIT | ||
* | ||
* Copyright (c) 2022, eunomia-bpf org | ||
* All rights reserved. | ||
*/ | ||
|
||
#include "bpftime_logger.hpp" | ||
#include <cstdlib> | ||
#include <iostream> | ||
|
||
void bpftime::bpftime_set_logger_from_env(){ | ||
const char* _target = std::getenv("BPFTIME_LOG_OUTPUT"); | ||
if (_target == NULL){ | ||
bpftime_set_logger(""); | ||
} else { | ||
bpftime_set_logger(std::string(_target)); | ||
} | ||
} | ||
|
||
void bpftime::bpftime_set_logger(const std::string& target){ | ||
if (target == "syslog") { | ||
throw "Not implemented yet"; | ||
} else if (target == "console" || target == "") { // Default to be console. | ||
spdlog::debug("Set logger to stderr"); | ||
auto logger = spdlog::stderr_color_mt("stderr"); | ||
logger->set_pattern("[%Y-%m-%d %H:%M:%S][%^%l%$][%t] %v"); | ||
logger->flush_on(spdlog::level::info); | ||
spdlog::set_default_logger(logger); | ||
} else { | ||
spdlog::debug("Set logger to file: {}", target); | ||
auto logger = spdlog::basic_logger_mt("glogger", target); // Todo. What happens if target invalid || target be wiped? | ||
logger->set_pattern("[%Y-%m-%d %H:%M:%S][%^%l%$][%t] %v"); | ||
logger->flush_on(spdlog::level::info); | ||
spdlog::set_default_logger(logger); | ||
} | ||
spdlog::cfg::load_env_levels(); | ||
} | ||
|
||
void bpftime::bpftime_logger_flush(){ | ||
spdlog::default_logger()->flush(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters