8000 Filelogging with nlog by pmiossec · Pull Request #999 · git-tfs/git-tfs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Filelogging with nlog #999

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

Merged
merged 14 commits into from
Oct 18, 2016
Merged

Conversation

pmiossec
Copy link
Member
@pmiossec pmiossec commented Oct 3, 2016
  • Use nlog to log git-tfs logs in a file (even debug logs even if not run in debug which will help to debug AFTER a problem occured)
  • Happy side effect: add colors in the console

@pmiossec pmiossec force-pushed the filelogging_with_nlog branch from 80d854b to 6ea86ff Compare October 4, 2016 00:15
@pmiossec
Copy link
Member Author
pmiossec commented Oct 9, 2016

Is there someone interested by reviewing or testing it? Otherwise I will merge it...

Copy link
Member
@spraints spraints left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks mostly fine. I like that TextWriter stdout isn't a constructor arg all over the place. In some places (like where there was code to make a progress meter (stdout.Write(".")) or where command-line usage is displayed, it seems like writing to stdout might still be appropriate. That said, I like having just one way to write output, so I'm 👍 on using Trace.Write* for everything. (Maybe the top-level error handler is an exception to this?)

@@ -312,7 +310,8 @@ private void GetRootChangesetForBranch(IList<RootBranch> rootBranches, string tf
GetRelevantChangesetBasedOnChangeType(mergedItemsToFirstChangesetInBranchToCreate, tfsPathParentBranch, tfsPathBranchToCreate, out renameFromBranch);

AddNewRootBranch(rootBranches, new RootBranch(rootChangesetInParentBranch, tfsPathBranchToCreate));
Trace.WriteLineIf(renameFromBranch != null, "Found original branch '" + renameFromBranch + "' (renamed in branch '" + tfsPathBranchToCreate + "')");
if(renameFromBranch != null)
Trace.WriteLine("Found original branch '" + renameFromBranch + "' (renamed in branch '" + tfsPathBranchToCreate + "')");
if (renameFromBranch != null)
GetRootChangesetForBranch(rootBranches, renameFromBranch);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these two if statements be combined?

do
{
_stdout.Write(".");
//Trace.TraceInformation(".");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just delete this line?

CommandOutputPipe(stdout => realStdout.Write(stdout.ReadToEnd()), command);
var textWriter = new StringWriter();
CommandOutputPipe(stdout => textWriter.Write(stdout.ReadToEnd()), command);
Trace.TraceInformation(textWriter.ToString());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why buffer it? Would a one-liner still work?

CommandOutputPipe(stdout => Trace.TraceInformation(stdout.ReadToEnd()), command);

}
}

public void InitializeGlobals()
{
_globals.Logger = _logger;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What uses _globals.Logger? Could it be injected in constructors rather than assigned here?

Trace.WriteLine("Command run:" + _globals.CommandLineRun);
InitializeGlobals();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to InitializeGlobals() feels like it should be at the beginning of Run(), so that ParseOptions can update globals if desired. Why move it here?

var unparsedArgs 10000 = ParseOptions(command, args);
UpdateLoggerOnDebugging();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is totally a style-nit, but why not continue to set up the logger for debugging in the setter for Globals.DebugOutput? It could be factored much better, but it's nice to have that contained in Globals so that this class can stay focussed on delegating things to the right command object.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember what is the reason. This development stayed a long time in my repository :(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have fixed everything except that. Not sure if really needed....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not needed.

foreach (var solution in gitTfsException.RecommendedSolutions)
{
Console.WriteLine("- " + solution);
Trace.TraceError("- " + solution);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any chance that nlog won't be configured to show errors by this point? For example, if GetLogger() throws an exception, maybe because the log file can't be written to, what will happen here? I'd like to err on the side of these messages always being shown.

if (!System.Diagnostics.Debugger.IsAttached)
{
System.Diagnostics.Trace.Listeners.Clear();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to do this that doesn't require every test to subclass BaseTest, or do anything at all? It'd be nice to be able to add new test classes without worrying about including this bit of setup.

8000

Looking around a bit, it looks like the answer to my question is no, or not really. A static initializer might work, but a static initializer might not run often enough(?) and might run at the wrong time, too. It looks like there's an IUseFixture thing that would make it so that the test classes derive from an interface instead of a class, which is marginally better, but also harder to look at and understand.

So consider this comment a rant that you don't need to do anything about. Unless you have a good idea of how to make it better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big problem for me. If we forget to ingherit from BaseTest, that's just that the build will outpout some logs. Not a big deal and if it is annoying it will be quickly fixed...

@spraints
Copy link
Member

Happy side effect: add colors in the console

:) :)

Is there someone interested by reviewing or testing it? Otherwise I will merge it...

Sorry for the delay. There was a lot to look through, so I skipped over this when you first opened it. I left some comments now.

@pmiossec
Copy link
Member Author

Sorry for the delay.

No problem

I left some comments now.

👍 I will try to fix all that as soon as possible...

Copy link
Member
@spraints spraints left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤘

@pmiossec pmiossec force-pushed the filelogging_with_nlog branch from e607649 to 7fefecb Compare October 18, 2016 19:23
@pmiossec pmiossec merged commit 101fa7e into git-tfs:master Oct 18, 2016
@pmiossec pmiossec deleted the filelogging_with_nlog branch October 18, 2016 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0