-
Notifications
You must be signed in to change notification settings - Fork 89
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
Log console output during replay to file #985 #76
Conversation
Can you please briefly explain why change like this? There is no comment in your code. |
I can add comments right into code if required.
|
src/log/file_appender.cpp
Outdated
if(!my->cfg.rotate) | ||
my->out.open( my->cfg.filename, std::ios_base::out | std::ios_base::app); | ||
{ | ||
fc::scoped_lock<boost::mutex> lock( my->slock ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is a constructor, I do not see the need for a lock here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have different threads, that's why I've added lock here, IMHO slock
mutex is supposed to be used for log files within different threads, maybe I'm wrong.
Thanks !
src/log/file_appender.cpp
Outdated
@@ -141,9 +160,11 @@ namespace fc { | |||
{ | |||
fc::create_directories(my->cfg.filename.parent_path()); | |||
|
|||
if(!my->cfg.rotate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't walked all of the code, but if rotate == true, will removing this cause open() to be called twice (once here, and once in rotate_files()) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if rotate
check was removed, and twice won't be open because there is a check in open_log_filename
method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need better abstraction / modularization.
src/log/file_appender.cpp
Outdated
@@ -57,21 +69,30 @@ namespace fc { | |||
} | |||
} | |||
|
|||
void open_log_filename() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function name is confusing. I'd recommend rename it to open_log_file()
or something else that can describe the logic better.
In addition, the check for file name inside the function made it even harder to understand, I think it would be better to move out the check, e.g. have an open()
simply opens a file or perhaps close then reopen, and only call it when necessary (aka with a check).
In short, try to simplify the code.
src/log/file_appender.cpp
Outdated
fc::time_point _now; | ||
fc::time_point_sec _start_time; | ||
string _timestamp_string; | ||
fc::path _old_log_filename, _log_filename, _link_filename; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For member variables, please declare only one variable per line.
src/log/file_appender.cpp
Outdated
line << std::setw( 21 ) << (m.get_context().get_thread_name().substr(0,9) + string(":") + m.get_context().get_task_name()).c_str() << " "; | ||
line << std::setw( 21 ) << | ||
(m.get_context().get_thread_name().substr(0,9) + string(":") + m.get_context().get_task_name()).c_str() | ||
<< " "; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code style here looks a bit ugly. I'd prefer
line << "something"
<< "something else"
<< "the end";
src/log/file_appender.cpp
Outdated
@@ -141,9 +160,7 @@ namespace fc { | |||
{ | |||
fc::create_directories(my->cfg.filename.parent_path()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not move the whole logic into constructor of impl
class for simplicity? All operation is done on my
anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the same earlier, I agree it would be better ! Thanks !
pushed new commit "more improvements" Thanks ! |
Why is this so? |
src/log/file_appender.cpp
Outdated
if( cfg.rotate ) | ||
{ | ||
FC_ASSERT( cfg.rotation_interval >= seconds( 1 ) ); | ||
FC_ASSERT( cfg.rotation_limit >= cfg.rotation_interval ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these assertions should be put before creating log file, even before setup_log_filenames
.
src/log/file_appender.cpp
Outdated
} | ||
catch( ... ) | ||
{ | ||
std::cerr << "error opening log file: " << cfg.filename.preferred_string() << "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the appender usable after caught an exception here? What will happen when trying to write?
src/log/file_appender.cpp
Outdated
_old_log_filename = _log_filename; | ||
|
||
open_log_file(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic seems a bit strange.
- Is there a chance that the file got closed but not reopened?
- Is there a chance that the file be opened again when not closed?
Probably because By the way, I guess the |
(just for the info) I've pushed 2 new commits:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we decide to merge the second version, you should rebase -i
to get rid of the first version. But not yet.
@@ -137,18 +134,7 @@ namespace fc { | |||
file_appender::file_appender( const variant& args ) : | |||
my( new impl( args.as<config>( FC_MAX_LOG_OBJECT_DEPTH ) ) ) | |||
{ | |||
try | |||
{ | |||
fc::create_directories(my->cfg.filename.parent_path()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this must be moved to impl::impl(), not simply removed.
{ | ||
fc::create_directories(my->cfg.filename.parent_path()); | ||
|
||
if(!my->cfg.rotate) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and this shouldn't be removed.
c720d64
to
c544b38
Compare
I've cleaned up my previous changes with 1st solution and forced new push commit |
@cogutvalera: Peter said "not yet". He mean you should NOT rebase by now. Then you did it regardless :-/ |
IMHO the 2nd solution is simpler and it works as required, then why to rebase "not yet" ? |
src/log/file_appender.cpp
Outdated
|
||
try | ||
{ | ||
fc::create_directories(cfg.filename.parent_path()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create_directories should happen before rotate_files.
The idea was to preserve the original version in case my ideas didn't work. I'm ok with the rebase if it does work as intended. |
Thanks! @abitmore @jmjatlanta please re-review. |
There may be an edge case here that we may want to fix, but the chances of it happening are very remote. Scenario: Destructor called, then rotate_files gets the lock. I am okay with that being there, as the file_appender is typically only destroyed at program exit, and the problem has probably been there from before this issue was opened. |
@pmconrad @jmjatlanta Thanks guys ! |
Thanks ! |
PR for "Log console output during replay to file #985 bitshares/bitshares-core#985"