Skip to content
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

Add timestamp to debug log #5203

Closed
uchagani opened this issue Jan 16, 2015 · 9 comments
Closed

Add timestamp to debug log #5203

uchagani opened this issue Jan 16, 2015 · 9 comments
Assignees
Labels
Milestone

Comments

@uchagani
Copy link
Contributor

@uchagani uchagani commented Jan 16, 2015

I've requested a similar feature before but now I'm asking for timestamps to be added to at least the debug logs.

I've trying to isolate a problem with bringing up machines and have isolated a port forwarding issue. However I can't isolate to a single place in the log file because it everything is going by so fast. I'd like to be able to compare timestamps from when I see the error and what is happening in the logs.

@sethvargo
Copy link
Contributor

@sethvargo sethvargo commented Jan 16, 2015

@uchagani how would having timestamps help solve this issue? Maybe I am misunderstanding, but the logs should be sequential.

@uchagani
Copy link
Contributor Author

@uchagani uchagani commented Jan 16, 2015

I'm using vagrant as part of a CI Build/Deploy/Test cycle. I am noticing a strange behavior in one of the apps I am testing where, when another vagrant box is spun up, the port-forwarding of the new box, causes a network glitch in boxes that are already spun up.

I'm trying to narrow down where in the vagrant log this is happening. I already have timestamps from my app regarding the crash and i wanted to line that up with the vagrant log to see what exactly in vagrant is causing the problem.

@philippe-granet
Copy link

@philippe-granet philippe-granet commented Oct 24, 2015

Add this at start of your Vagrantfile, it helps me:

$out_file = File.new('debug.log', 'w')
def $stdout.write string
    log_datas=string
    if log_datas.gsub(/\r?\n/, "") != ''
        log_datas=::Time.now.strftime("%d/%m/%Y %T")+" "+log_datas.gsub(/\r\n/, "\n")
    end
    super log_datas
    $out_file.write log_datas
    $out_file.flush
end
def $stderr.write string
    log_datas=string
    if log_datas.gsub(/\r?\n/, "") != ''
        log_datas=::Time.now.strftime("%d/%m/%Y %T")+" "+log_datas.gsub(/\r\n/, "\n")
    end
    super log_datas
    $out_file.write log_datas
    $out_file.flush
end

It gives me (console + debug.log) :

24/10/2015 13:37:50 ==> default: Attempting graceful shutdown of VM...
24/10/2015 13:38:11 ==> default: Checking if box 'ubuntu/trusty64' is up to date...
24/10/2015 13:38:13 ==> default: Clearing any previously set forwarded ports...
24/10/2015 13:38:16 ==> default: Clearing any previously set network interfaces...
24/10/2015 13:38:17 ==> default: Preparing network interfaces based on configuration...
24/10/2015 13:38:17     default: Adapter 1: nat
24/10/2015 13:38:17 ==> default: Forwarding ports...
24/10/2015 13:38:17     default: 9991 => 9993 (adapter 1)
24/10/2015 13:38:17     default: 22 => 2222 (adapter 1)
24/10/2015 13:38:17 ==> default: Running 'pre-boot' VM customizations...
24/10/2015 13:38:17 ==> default: Booting VM...
24/10/2015 13:38:21 ==> default: Waiting for machine to boot. This may take a few minutes...
24/10/2015 13:38:21     default: SSH address: 127.0.0.1:2222
24/10/2015 13:38:21     default: SSH username: vagrant
24/10/2015 13:38:21     default: SSH auth method: private key
24/10/2015 13:38:28     default: Warning: Remote connection disconnect. Retrying...
24/10/2015 13:38:40 ==> default: Machine booted and ready!
@sethvargo sethvargo added this to the 2.0.0 milestone May 30, 2016
@chrisroberts chrisroberts modified the milestones: 1.9.0, 2.0.0 Sep 29, 2016
@chrisroberts chrisroberts self-assigned this Sep 29, 2016
@mcandre
Copy link
Contributor

@mcandre mcandre commented Nov 10, 2017

Solid feature idea, maybe submit a PR?

@philippe-granet
Copy link

@philippe-granet philippe-granet commented Nov 11, 2017

See PR #9175

@gustavomcarmo
Copy link

@gustavomcarmo gustavomcarmo commented Nov 24, 2017

Great @philippe-granet !!!

I've just improved your solution placing the code in a different file called timestamp-logger.rb and adding just one line of code at the start of my Vagrantfile: load 'timestamp-logger.rb'

@philippe-granet
Copy link

@philippe-granet philippe-granet commented Dec 15, 2017

A PR has been merged : #9269

@briancain
Copy link
Member

@briancain briancain commented Dec 15, 2017

I'm going to go ahead and close this now that #9269 has been merged. Thanks!

@briancain briancain closed this Dec 15, 2017
@hashibot
Copy link

@hashibot hashibot bot commented Mar 31, 2020

I'm going to lock this issue because it has been closed for 30 days . This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@hashibot hashibot bot locked and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
8 participants