WIP 847, solve 1008, solve 1010 by adamralph · Pull Request #1009 · scriptcs/scriptcs · GitHub
Skip to content

WIP 847, solve 1008, solve 1010#1009

Merged
filipw merged 16 commits into
scriptcs:devfrom
adamralph:847
Jul 27, 2015
Merged

WIP 847, solve 1008, solve 1010#1009
filipw merged 16 commits into
scriptcs:devfrom
adamralph:847

Conversation

@adamralph

Copy link
Copy Markdown
Contributor

Re #847 - move the logging interfaces from Core to Contracts, so that anyone referencing Contracts can continue to get one injected, as the WebApi2 script pack does

fixes #1008 by switching from passing around ILog to passing around an ILogProvider. This also allows anyone who gets an logging interface injected to create a logger specific to them. E.g. the WebApi2 script pack can create a "WebApiPack" logger or even one for each type. If we expose ILogProvider to scripts, they can create a logger with the script name, etc.

This is the console output at debug level after this change:

image

fixes #1010

@adamralph

Copy link
Copy Markdown
Contributor Author

@adamralph

Copy link
Copy Markdown
Contributor Author

Trying to figure out what happened with the CI build.

Works On My Machine™

@adamralph

Copy link
Copy Markdown
Contributor Author

That turned out to be rather subtle. The tests were all passing in VS with whatever test runner I tried, but were failing on the command line. I then switched VS to release config and it also failed. I tracked it down to this https://github.com/adamralph/scriptcs/blob/871c88bee11ec0130e9383eee52f26a2a4552960/src/ScriptCs.Contracts/Logging/LogProviderExtensions.cs#L14

The JIT was inlining the method in the release build which fatally altered the stack, causing this particular piece of magic to fail. It's the same method as used in LibLog so it's proven to work (https://github.com/damianh/LibLog/blob/69873d63d382073ac16266a071654fb01fdd4b46/src/LibLog/LibLog.cs#L438-L439) but over there it's not an extension method so it doesn't get inlined. I tried splitting it into two lines to match the LibLog impl. exactly but it made no difference.

I guess LibLog may also be liable to this problem, but it's been getting lucky so far just because of the way that the JIT heuristics work out. I'll probably raise an issue over there for consideration.

@khellang

khellang commented Apr 2, 2015

Copy link
Copy Markdown
Member

You could try adding a MethodImpl attribute with MethodImplOptions.NoInlining. See https://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.methodimploptions(v=vs.110).aspx

@khellang

khellang commented Apr 2, 2015

Copy link
Copy Markdown
Member

Uh. Looks like that's already done. Damn mobile views...

@adamralph

Copy link
Copy Markdown
Contributor Author

I added a commit to fix #1010

Before:

C:\code>scriptcs awol.csx
ERROR: Could not find file 'C:\code\awol.csx'. - 'C:\code\awol.csx'.

C:\code>

After:

C:\code>scriptcs awol.csx
ERROR: Error executing script 'awol.csx' [FileNotFoundException] Could not find file 'C:\code\awol.csx'.

C:\code>

@adamralph

Copy link
Copy Markdown
Contributor Author

As far as I can see, this PR now completes all the logging changes envisioned so far.

It is using the latest version of LibLog (4.1.1) which contains a new feature which I contributed (damianh-archive/LibLog#56) allowing LibLog to function purely as a provider of out of the box support for common logging frameworks and sitting, internally, underneath the public logging API of the consuming library.

To summarise:

  • ScriptCs.Contracts defines it's own public logging API, decoupled from LibLog, with the initial definition copied from LibLog (because it's very good).
  • All types in other projects now accept ILogProvider parameters instead of ILog to allow specific loggers to be created to support features such as Show logger name at debug and trace level #1008
  • ScriptCs.Contracts provides a DefaultLogProvider which uses LibLog providers internally to provide out of the box support for common logging frameworks. This is not used by scriptcs.exe. It is purely for hosts.
  • ScriptCs.Contracts provides a NullLogProvider as a cheap way for hosts to disable logging without having to install a logging framework and provide a null config (LibLog logs to the console by default)

To clarify, these changes are independent of the decision we take regarding breaking changes for 0.15 (see #996 (comment)). If we do decide to reinstate the Common.Logging overloads for a transition period then this can be done later, independently of these changes.

@adamralph

Copy link
Copy Markdown
Contributor Author

rebased

@adamralph

Copy link
Copy Markdown
Contributor Author

Added one more commit: LibLog 4.2 no longer logs to the console by default which removes the need to publicly expose NullLogProvider for hosts to switch this off. They can just use DefaultLogProvider in all cases.

@adamralph

Copy link
Copy Markdown
Contributor Author

Rebased and upgraded to LibLog 4.2.2

@adamralph adamralph mentioned this pull request Apr 28, 2015
29 tasks
@adamralph

Copy link
Copy Markdown
Contributor Author

rebased

@filipw

filipw commented Jul 27, 2015

Copy link
Copy Markdown
Member

filipw added a commit that referenced this pull request Jul 27, 2015
@filipw filipw merged commit 750ffab into scriptcs:dev Jul 27, 2015
@adamralph adamralph deleted the 847 branch July 27, 2015 10:50
@adamralph adamralph changed the title close 847, solve 1008 WIP 847, solve 1008, solve 1010 Jul 27, 2015
@filipw filipw mentioned this pull request Jul 27, 2015
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better console output when script not found Show logger name at debug and trace level

3 participants