Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(404)

Side by Side Diff: pkg/analysis_server/lib/driver.dart

Issue 360973002: Add a "--log" option to analysis server to dump log messages to a file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library driver; 5 library driver;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 8
9 import 'package:analysis_server/http_server.dart'; 9 import 'package:analysis_server/http_server.dart';
10 import 'package:analysis_server/src/socket_server.dart'; 10 import 'package:analysis_server/src/socket_server.dart';
11 import 'package:analysis_server/stdio_server.dart'; 11 import 'package:analysis_server/stdio_server.dart';
12 import 'package:args/args.dart'; 12 import 'package:args/args.dart';
13 import 'package:logging/logging.dart';
13 14
14 /** 15 /**
15 * The [Driver] class represents a single running instance of the analysis 16 * The [Driver] class represents a single running instance of the analysis
16 * server application. It is responsible for parsing command line options 17 * server application. It is responsible for parsing command line options
17 * and starting the HTTP and/or stdio servers. 18 * and starting the HTTP and/or stdio servers.
18 */ 19 */
19 class Driver { 20 class Driver {
20 /** 21 /**
21 * The name of the application that is used to start a server. 22 * The name of the application that is used to start a server.
22 */ 23 */
23 static const BINARY_NAME = 'server'; 24 static const BINARY_NAME = 'server';
24 25
25 /** 26 /**
26 * The name of the option used to print usage information. 27 * The name of the option used to print usage information.
27 */ 28 */
28 static const String HELP_OPTION = "help"; 29 static const String HELP_OPTION = "help";
29 30
30 /** 31 /**
31 * The name of the option used to specify the port to which the server will 32 * The name of the option used to specify the port to which the server will
32 * connect. 33 * connect.
33 */ 34 */
34 static const String PORT_OPTION = "port"; 35 static const String PORT_OPTION = "port";
35 36
37 /**
38 * The name of the option used to specify the log file.
39 */
40 static const String LOG_FILE_OPTION = "log";
41
36 SocketServer socketServer = new SocketServer(); 42 SocketServer socketServer = new SocketServer();
37 43
38 HttpAnalysisServer httpServer; 44 HttpAnalysisServer httpServer;
39 45
40 StdioAnalysisServer stdioServer; 46 StdioAnalysisServer stdioServer;
41 47
42 Driver() { 48 Driver() {
43 httpServer = new HttpAnalysisServer(socketServer); 49 httpServer = new HttpAnalysisServer(socketServer);
44 stdioServer = new StdioAnalysisServer(socketServer); 50 stdioServer = new StdioAnalysisServer(socketServer);
45 } 51 }
46 52
47 /** 53 /**
48 * Use the given command-line arguments to start this server. 54 * Use the given command-line arguments to start this server.
49 */ 55 */
50 void start(List<String> args) { 56 void start(List<String> args) {
51 ArgParser parser = new ArgParser(); 57 ArgParser parser = new ArgParser();
52 parser.addFlag(HELP_OPTION, help: 58 parser.addFlag(HELP_OPTION, help:
53 "print this help message without starting a server", defaultsTo: false, 59 "print this help message without starting a server", defaultsTo: false,
54 negatable: false); 60 negatable: false);
55 parser.addOption(PORT_OPTION, help: 61 parser.addOption(PORT_OPTION, help:
56 "[port] the port on which the server will listen"); 62 "[port] the port on which the server will listen");
63 parser.addOption(LOG_FILE_OPTION, help:
64 "[path] file to log debugging messages to");
57 65
58 ArgResults results = parser.parse(args); 66 ArgResults results = parser.parse(args);
59 if (results[HELP_OPTION]) { 67 if (results[HELP_OPTION]) {
60 _printUsage(parser); 68 _printUsage(parser);
61 return; 69 return;
62 } 70 }
71 if (results[LOG_FILE_OPTION] != null) {
72 try {
73 File file = new File(results[LOG_FILE_OPTION]);
74 IOSink sink = file.openWrite();
75 Logger.root.onRecord.listen((LogRecord record) {
76 sink.writeln(record);
Brian Wilkerson 2014/07/01 17:30:01 Where do we close the file?
Paul Berry 2014/07/01 17:51:12 We just let the OS close it for us when the proces
77 });
78 } catch (exception) {
79 print('Could not open log file: $exception');
80 exitCode = 1;
81 return;
82 }
83 }
63 int port; 84 int port;
64 bool serve_http = false; 85 bool serve_http = false;
65 if (results[PORT_OPTION] != null) { 86 if (results[PORT_OPTION] != null) {
66 serve_http = true; 87 serve_http = true;
67 try { 88 try {
68 port = int.parse(results[PORT_OPTION]); 89 port = int.parse(results[PORT_OPTION]);
69 } on FormatException { 90 } on FormatException {
70 print('Invalid port number: ${results[PORT_OPTION]}'); 91 print('Invalid port number: ${results[PORT_OPTION]}');
71 print(''); 92 print('');
72 _printUsage(parser); 93 _printUsage(parser);
(...skipping 16 matching lines...) Expand all
89 /** 110 /**
90 * Print information about how to use the server. 111 * Print information about how to use the server.
91 */ 112 */
92 void _printUsage(ArgParser parser) { 113 void _printUsage(ArgParser parser) {
93 print('Usage: $BINARY_NAME [flags]'); 114 print('Usage: $BINARY_NAME [flags]');
94 print(''); 115 print('');
95 print('Supported flags are:'); 116 print('Supported flags are:');
96 print(parser.getUsage()); 117 print(parser.getUsage());
97 } 118 }
98 } 119 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698