Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/linker.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/linker
diff options
context:
space:
mode:
authorRadek Doulik <rodo@xamarin.com>2017-09-12 22:28:40 +0300
committerMarek Safar <marek.safar@gmail.com>2017-09-13 16:48:09 +0300
commit8062a86c4b6b4b6beeefb7ea8e0000d959b77d94 (patch)
tree071cde2df55c4ab3756f9f433117cc61b5485548 /linker
parente0bbc7e8791fef65a2d2dd849cd4dd0826c74300 (diff)
Improve logging
Added the ILogger interface for logging messages from the linker. There is a new default implementation, the ConsoleLogger class, which just continues to use simple S.C.WriteLine as before. The LinkerContext newly contains Logger property, which can be set to instance of class implementing ILogger interface. As an example, Xamarin.Android linker will be able to provide own logger, forwarding the messages to Microsoft.Build.Utilities.TaskLoggingHelper. This way it will be possible to see linker messages, depending on the actual msbuild's verbosity level, in the XA build output.
Diffstat (limited to 'linker')
-rw-r--r--linker/Mono.Linker.Steps/BlacklistStep.cs12
-rw-r--r--linker/Mono.Linker.Steps/ResolveFromAssemblyStep.cs3
-rw-r--r--linker/Mono.Linker.csproj2
-rw-r--r--linker/Mono.Linker/ConsoleLogger.cs11
-rw-r--r--linker/Mono.Linker/ILogger.cs15
-rw-r--r--linker/Mono.Linker/LinkContext.cs13
6 files changed, 46 insertions, 10 deletions
diff --git a/linker/Mono.Linker.Steps/BlacklistStep.cs b/linker/Mono.Linker.Steps/BlacklistStep.cs
index 6c6344bc3..197d32b40 100644
--- a/linker/Mono.Linker.Steps/BlacklistStep.cs
+++ b/linker/Mono.Linker.Steps/BlacklistStep.cs
@@ -51,13 +51,11 @@ namespace Mono.Linker.Steps {
continue;
try {
- if (Context.LogInternalExceptions)
- Console.WriteLine ("Processing resource linker descriptor: {0}", name);
+ Context.LogMessage ("Processing resource linker descriptor: {0}", name);
Context.Pipeline.AddStepAfter (typeof (TypeMapStep), GetResolveStep (name));
} catch (XmlException ex) {
/* This could happen if some broken XML file is included. */
- if (Context.LogInternalExceptions)
- Console.WriteLine ("Error processing {0}: {1}", name, ex);
+ Context.LogMessage ("Error processing {0}: {1}", name, ex);
}
}
@@ -69,14 +67,12 @@ namespace Mono.Linker.Steps {
.Where (res => IsReferenced (GetAssemblyName (res.Name)))
.Cast<EmbeddedResource> ()) {
try {
- if (Context.LogInternalExceptions)
- Console.WriteLine ("Processing embedded resource linker descriptor: {0}", rsc.Name);
+ Context.LogMessage ("Processing embedded resource linker descriptor: {0}", rsc.Name);
Context.Pipeline.AddStepAfter (typeof (TypeMapStep), GetExternalResolveStep (rsc, asm));
} catch (XmlException ex) {
/* This could happen if some broken XML file is embedded. */
- if (Context.LogInternalExceptions)
- Console.WriteLine ("Error processing {0}: {1}", rsc.Name, ex);
+ Context.LogMessage ("Error processing {0}: {1}", rsc.Name, ex);
}
}
}
diff --git a/linker/Mono.Linker.Steps/ResolveFromAssemblyStep.cs b/linker/Mono.Linker.Steps/ResolveFromAssemblyStep.cs
index 6595b826d..189e1533d 100644
--- a/linker/Mono.Linker.Steps/ResolveFromAssemblyStep.cs
+++ b/linker/Mono.Linker.Steps/ResolveFromAssemblyStep.cs
@@ -137,8 +137,7 @@ namespace Mono.Linker.Steps
// Both cases are bugs not on our end but we still want to link all assemblies
// especially when such types cannot be used anyway
//
- if (context.LogInternalExceptions)
- System.Console.WriteLine ($"Cannot find declaration of exported type '{exported}' from the assembly '{assembly}'");
+ context.LogMessage ($"Cannot find declaration of exported type '{exported}' from the assembly '{assembly}'");
continue;
}
diff --git a/linker/Mono.Linker.csproj b/linker/Mono.Linker.csproj
index ff826f3a3..93a652809 100644
--- a/linker/Mono.Linker.csproj
+++ b/linker/Mono.Linker.csproj
@@ -91,6 +91,8 @@
<Compile Include="Mono.Linker\TypeReferenceExtensions.cs" />
<Compile Include="Mono.Linker\XApiReader.cs" />
<Compile Include="Mono.Linker.Steps\TypeMapStep.cs" />
+ <Compile Include="Mono.Linker\ILogger.cs" />
+ <Compile Include="Mono.Linker\ConsoleLogger.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
diff --git a/linker/Mono.Linker/ConsoleLogger.cs b/linker/Mono.Linker/ConsoleLogger.cs
new file mode 100644
index 000000000..f7059f2b8
--- /dev/null
+++ b/linker/Mono.Linker/ConsoleLogger.cs
@@ -0,0 +1,11 @@
+using System;
+namespace Mono.Linker
+{
+ public class ConsoleLogger : ILogger
+ {
+ public void LogMessage (MessageImportance importance, string message, params object[] values)
+ {
+ Console.WriteLine (message, values);
+ }
+ }
+}
diff --git a/linker/Mono.Linker/ILogger.cs b/linker/Mono.Linker/ILogger.cs
new file mode 100644
index 000000000..d4f610fbb
--- /dev/null
+++ b/linker/Mono.Linker/ILogger.cs
@@ -0,0 +1,15 @@
+using System;
+namespace Mono.Linker
+{
+ public enum MessageImportance
+ {
+ High,
+ Low,
+ Normal,
+ }
+
+ public interface ILogger
+ {
+ void LogMessage (MessageImportance importance, string message, params object[] values);
+ }
+}
diff --git a/linker/Mono.Linker/LinkContext.cs b/linker/Mono.Linker/LinkContext.cs
index e61187eb5..155e202c1 100644
--- a/linker/Mono.Linker/LinkContext.cs
+++ b/linker/Mono.Linker/LinkContext.cs
@@ -112,6 +112,8 @@ namespace Mono.Linker {
public bool LogInternalExceptions { get; set; } = false;
+ public ILogger Logger { get; set; } = new ConsoleLogger ();
+
public LinkContext (Pipeline pipeline)
: this (pipeline, new AssemblyResolver ())
{
@@ -301,5 +303,16 @@ namespace Mono.Linker {
{
_resolver.Dispose ();
}
+
+ public void LogMessage (string message, params object[] values)
+ {
+ LogMessage (MessageImportance.Normal, message, values);
+ }
+
+ public void LogMessage (MessageImportance importance, string message, params object [] values)
+ {
+ if (LogInternalExceptions && Logger != null)
+ Logger.LogMessage (importance, message, values);
+ }
}
}