NTP Analyzer  0.8.2
Analyze the operation of time servers
LogExtensions.cs
Go to the documentation of this file.
1 //
2 // Copyright (c) 2013-2017 Carsten Sonne Larsen <cs@innolan.net>
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE.
21 
22 using System;
23 using System.Collections.Generic;
24 using System.Net;
25 using Ntp.Analyzer.Config.Node;
27 using Ntp.Analyzer.Objects;
28 using Ntp.Common.Log;
29 
30 namespace Ntp.Analyzer.Process.Log
31 {
32  internal static class LogExtensions
33  {
34  internal static void AddErrors(this LogBase log, IEnumerable<string> errors)
35  {
36  foreach (string error in errors)
37  log.WriteLine(error, Severity.Error);
38  }
39 
40  internal static void ClusterError(this LogBase log, Exception e)
41  {
42  log.WriteLine("Error during initialization of cluster node.", Severity.Error);
43  log.WriteLine(e);
44  }
45 
46  internal static void ClusterReady(this LogBase log, NodeConfiguration node)
47  {
48  log.WriteLine($"Requesting to cluster {node.Address}", Severity.Notice);
49  }
50 
51  internal static void ConfigFile(this LogBase log, string file)
52  {
53  log.WriteLine($"Using configuration {file}", Severity.Notice);
54  }
55 
56  internal static void DatabaseError(this LogBase log, Exception e)
57  {
58  log.WriteLine("Error during initialization of database.", Severity.Error);
59  log.WriteLine(e);
60  }
61 
62  internal static void HostImportError(this LogBase log, Exception e)
63  {
64  log.WriteLine($"Could not import host data {e.Message}", Severity.Warn);
65  log.WriteLine(e, Severity.Trace);
66  }
67 
68  internal static void HostNotFound(this LogBase log, int hostId)
69  {
70  log.WriteLine($"Host with ID {hostId} does not exists in database.", Severity.Warn);
71  }
72 
73  internal static void InitializationError(this LogBase log, Exception e)
74  {
75  log.WriteLine($"Cannot create logs: {e.Message}", Severity.Error);
76  log.WriteLine(e);
77  }
78 
79  internal static void InstanceName(this LogBase log, string name)
80  {
81  log.WriteLine($"Instance named {name}", Severity.Notice);
82  }
83 
84  internal static void JobInitEnd(this LogBase log)
85  {
86  log.WriteLine("All jobs initialized.", Severity.Debug);
87  }
88 
89  internal static void JobInitStart(this LogBase log)
90  {
91  log.WriteLine("Initializing jobs.", Severity.Info);
92  }
93 
94  internal static void KnownServer(this LogBase log, int id, string name)
95  {
96  log.WriteLine(
97  $"Found known time server {name} with id {id} in list.",
98  Severity.Info);
99  }
100 
101  internal static void ListenerError(this LogBase log, Exception e)
102  {
103  log.WriteLine("Error during initialization of command channels.", Severity.Warn);
104  log.WriteLine(e);
105  }
106 
107  internal static void ListenerReady(this LogBase log, Listener listener)
108  {
109  log.WriteLine($"Opening command channel on {listener}", Severity.Notice);
110  }
111 
112  internal static void NewHost(this LogBase log, HostConfiguration server, IPAddress ip)
113  {
114  log.WriteLine(
115  $"Created a new host in database ID {server.HostId} with name {server.ServerName} and IP {ip}.",
116  Severity.Info);
117  }
118 
119  internal static void NewPeer(this LogBase log, AssociationEntry entry)
120  {
121  log.WriteLine(
122  $"Created a new peer in database with name {entry.Remote} and IP {entry.Remote}.",
123  Severity.Info);
124  }
125 
126  internal static void NoConfig(this LogBase log, string file)
127  {
128  log.WriteLine($"Cannot find configuration file {file}", Severity.Error);
129  }
130 
131  internal static void OpenNtpConfigError(this LogBase log)
132  {
133  log.WriteLine("Traffic data collection is not supported for OpenNTP.", Severity.Warn);
134  }
135 
136  internal static void PeerImportError(this LogBase log, Exception e)
137  {
138  log.WriteLine($"Could not import peer data {e.Message}", Severity.Warn);
139  log.WriteLine(e, Severity.Trace);
140  }
141 
142  internal static void PeerIpAmbiguous(this LogBase log, AssociationEntry entry)
143  {
144  log.WriteLine(
145  $"Ambiguous peer IP {entry.Remote}. Multiple occurrences found in database.",
146  Severity.Warn);
147  }
148 
149  internal static void PeerIpNotFound(this LogBase log, AssociationEntry entry)
150  {
151  log.WriteLine($"Peer with IP {entry.Remote} does not exists in database.", Severity.Warn);
152  }
153 
154  internal static void PidFileError(this LogBase log, Exception e)
155  {
156  log.WriteLine($"Cannot create pid file. {e.Message}", Severity.Warn);
157  }
158 
159  internal static void ProcessId(this LogBase log, int pid)
160  {
161  log.WriteLine($"Running with process ID {pid}", Severity.Notice);
162  }
163 
164  internal static void SchedulerError(this LogBase log, Exception e)
165  {
166  log.WriteLine("Error during initialization of scheduler.", Severity.Error);
167  log.WriteLine(e);
168  }
169 
170  internal static void Starting(this LogBase log, string version)
171  {
172  log.WriteLine($"NTP Analyzer {version} started.", Severity.Notice);
173  }
174 
175  internal static void TableError(this LogBase log, Exception e)
176  {
177  log.WriteLine("Could not populate tables with data.", Severity.Error);
178  log.WriteLine(e);
179  }
180 
181  internal static void UserId(this LogBase log, uint userId)
182  {
183  log.WriteLine($"Running under user id {userId}", Severity.Info);
184  }
185 
186  internal static void UserIdError(this LogBase log, uint userId)
187  {
188  log.WriteLine($"Failed to set user id {userId}", Severity.Warn);
189  }
190 
191  internal static void HostNameNotFound(this LogBase log, string ip, Exception e)
192  {
193  log.WriteLine($"Could not find host name for IP {ip}.", Severity.Info);
194  log.WriteLine(e, Severity.Debug);
195  }
196  }
197 }
static void HostNotFound(this LogBase log, int hostId)
static void AddErrors(this LogBase log, IEnumerable< string > errors)
static void OpenNtpConfigError(this LogBase log)
abstract void WriteLine(string text, Severity severity)
static void HostNameNotFound(this LogBase log, string ip, Exception e)
static void UserId(this LogBase log, uint userId)
static void PeerIpAmbiguous(this LogBase log, AssociationEntry entry)
static void HostImportError(this LogBase log, Exception e)
static void PidFileError(this LogBase log, Exception e)
static void InitializationError(this LogBase log, Exception e)
static void JobInitStart(this LogBase log)
var e
Definition: bootstrap.min.js:6
static void ClusterReady(this LogBase log, NodeConfiguration node)
static void NewHost(this LogBase log, HostConfiguration server, IPAddress ip)
static void ListenerError(this LogBase log, Exception e)
static void NoConfig(this LogBase log, string file)
static void KnownServer(this LogBase log, int id, string name)
static void TableError(this LogBase log, Exception e)
static void Starting(this LogBase log, string version)
static void ConfigFile(this LogBase log, string file)
static void ProcessId(this LogBase log, int pid)
static void ClusterError(this LogBase log, Exception e)
static void DatabaseError(this LogBase log, Exception e)
static void ListenerReady(this LogBase log, Listener listener)
static void SchedulerError(this LogBase log, Exception e)
var version
Definition: bootstrap.js:13
static void JobInitEnd(this LogBase log)
static void UserIdError(this LogBase log, uint userId)
static void PeerImportError(this LogBase log, Exception e)
static void NewPeer(this LogBase log, AssociationEntry entry)
static void InstanceName(this LogBase log, string name)
static void PeerIpNotFound(this LogBase log, AssociationEntry entry)