Skip to content

Comments in log moudule, log模块的注释 #551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
y0sh1ne opened this issue May 3, 2025 · 1 comment
Open

Comments in log moudule, log模块的注释 #551

y0sh1ne opened this issue May 3, 2025 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Needs help from a contributor question Further information is requested

Comments

@y0sh1ne
Copy link

y0sh1ne commented May 3, 2025

Question

/**
* These functions won't output header information such as __FUNCTION__,
* The user should control these information
* If the header information should be outputed
* please use LOG_PANIC, LOG_ERROR ...
*/
template <class T>
Log &operator<<(T message);

这个地方注释说不会输出header信息,但这些函数的定义中都调用了Log::out()方法。

miniob/src/common/log/log.h

Lines 236 to 242 in 95edd11

template <class T>
Log &Log::operator<<(T msg)
{
// at this time, the input level is the default log level
out(console_level_, log_level_, msg);
return *this;
}

Log::out()方法中使用了宏LOG_HEAD (290行)。

miniob/src/common/log/log.h

Lines 281 to 314 in 95edd11

int Log::out(const LOG_LEVEL console_level, const LOG_LEVEL log_level, T &msg)
{
bool locked = false;
if (console_level < LOG_LEVEL_PANIC || console_level > console_level_ || log_level < LOG_LEVEL_PANIC ||
log_level > log_level_) {
return LOG_STATUS_OK;
}
try {
char prefix[ONE_KILO] = {0};
LOG_HEAD(prefix, log_level);
if (LOG_LEVEL_PANIC <= console_level && console_level <= console_level_) {
cout << prefix_map_[console_level] << msg;
}
if (LOG_LEVEL_PANIC <= log_level && log_level <= log_level_) {
pthread_mutex_lock(&lock_);
locked = true;
ofs_ << prefix;
ofs_ << msg;
ofs_.flush();
log_line_++;
pthread_mutex_unlock(&lock_);
locked = false;
}
} catch (exception &e) {
if (locked) {
pthread_mutex_unlock(&lock_);
}
cerr << e.what() << endl;
return LOG_STATUS_ERR;
}
return LOG_STATUS_OK;
}

注释是正确的吗?

@y0sh1ne y0sh1ne added the question Further information is requested label May 3, 2025
@nautaa
Copy link
Member

nautaa commented May 6, 2025

@y0sh1ne you are right, thanks for your feedback, if you are interest in it, you can submit pull request to modify the comments.

@nautaa nautaa added the enhancement New feature or request label May 6, 2025
@nautaa nautaa added good first issue Good for newcomers help wanted Needs help from a contributor labels May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Needs help from a contributor question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants