add log generationt tool and clean up Terminate to use standard names

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/ec/trunk@36944 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2013-08-05 10:45:52 +00:00
parent 77c3d1593f
commit c24081a1ca
6 changed files with 226 additions and 20 deletions

View file

@ -1,3 +1,10 @@
2013-08-05 Richard Frith-Macdonald <rfm@gnu.org>
* LogTool.m: Tool to generate logs
* Terminate.m: Cleanups
* GNUmakefile: Build new tool
* ECCL.h: Document new tool
2013-07-12 Richard Frith-Macdonald <rfm@gnu.org>
* EcProcess.h: New method to get EC user directory

31
ECCL.h
View file

@ -38,6 +38,37 @@
server processes for large scale software systems.
</p>
</section>
<section>
<heading>The LogTool command line tool</heading>
<p>The LogTool command line tool provides a mechanism to log various
types of messages (using the ECCL logging system) from a process
which is not itsself ECCL enabled (ie not built using the ECCL
classes). You may use this to generate logging from shell scripts
or from Java servlets etc.
</p>
<p>The tool requires at least two arguments:<br />
'-Name XXX' specifies the name under which the message is to be logged
and<br />
'-Mesg XXX' specifies the content of the message to be logged.<br />
The optional '-Mode XXX' argument specifies the type of log to be
generated (one of Audit, Debug, Warn, Error or Alert) and defaults
to generating a 'Warn' log.
</p>
</section>
<section>
<heading>The Terminate command line tool</heading>
<p>The Terminate command line tool provides a mechanism to shut down
an ECCL host. This tool contacts a Command server and tells it to
shut down all it's local client process and the shut itsself down.
</p>
<p>You may use -CommandHost and -CommandName to specify a Command
server to contact, otherwise the default local Command server is
contacted (or if there is no local server, any available Command
server on the local network is contacted).
</p>
</section>
</chapter>
*/

View file

@ -34,6 +34,9 @@
@class NSMutableSet;
@class NSString;
/* The EcClientI class provides a lightweight interface to a remote
* process, equipped to handle inter-process keepalive signalling.
*/
@interface EcClientI : NSObject
{
id<CmdClient> theServer;

View file

@ -64,6 +64,7 @@ TOOL_NAME = \
Command \
Console \
Control \
LogTool \
Terminate \
@ -79,10 +80,14 @@ Control_OBJC_FILES = Control.m EcControl.m EcClientI.m NSFileHandle+Printf.m
Control_TOOL_LIBS += -lECCL
Control_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR)
LogTool_OBJC_FILES = LogTool.m
LogTool_TOOL_LIBS += -lECCL
LogTool_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR)
Terminate_OBJC_FILES = Terminate.m
Terminate_TOOL_LIBS += -lECCL
Terminate_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR)
Terminate_CPPFLAGS += ${ECCL_CPPFLAGS}

144
LogTool.m Normal file
View file

@ -0,0 +1,144 @@
/** Enterprise Control Configuration and Logging
Copyright (C) 2012 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <rfm@gnu.org>
Date: Febrary 2010
Originally developed from 1996 to 2012 by Brainstorm, and donated to
the FSF.
This file is part of the GNUstep project.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02111 USA.
*/
#import <Foundation/Foundation.h>
#import "EcProcess.h"
@interface LogTool : EcProcess
{
}
@end
@implementation LogTool
- (void) cmdQuit: (NSInteger)status
{
[super cmdQuit: status];
exit(status);
}
@end
static void
inner_main()
{
NSUserDefaults *defs;
NSArray *args;
LogTool *tool;
NSString *name;
NSString *mode;
NSString *mesg;
EcLogType eclt;
CREATE_AUTORELEASE_POOL(arp);
defs = [NSUserDefaults standardUserDefaults];
args = [[NSProcessInfo processInfo] arguments];
if ([args containsObject: @"--help"] == YES)
{
printf("LogTool ... options are\n");
printf("-Name NN (no default)\n");
printf("\tSpecify name of proceess making log\n");
printf("-Mode NN (Warn)\n");
printf("\tSpecify log mode (Audit, Debug, Warn, Error, Alert)\n");
printf("-Mesg the-message-to-logs (none)\n");
printf("\tSpecify the test to be logged\n");
exit(0);
}
name = [defs stringForKey: @"Name"];
if ([name length] == 0)
{
NSLog(@"You must define a Name under which to log");
exit(1);
}
mode = [defs stringForKey: @"Mode"];
if ([mode length] == 0)
{
mode = @"Warn";
}
if ([@"Audit" isEqual: mode])
{
eclt = LT_AUDIT;
}
else if ([@"Debug" isEqual: mode])
{
eclt = LT_DEBUG;
}
else if ([@"Warn" isEqual: mode])
{
eclt = LT_WARNING;
}
else if ([@"Error" isEqual: mode])
{
eclt = LT_ERROR;
}
else if ([@"Alert" isEqual: mode])
{
eclt = LT_ALERT;
}
else
{
NSLog(@"You must specify a known log Mode");
exit(1);
}
mesg = [defs stringForKey: @"Mesg"];
if ([mesg length] == 0)
{
NSLog(@"You must specify a Mesg to log");
exit(1);
}
/* Now establish the command server.
*/
tool = [[[LogTool alloc] initWithDefaults:
[NSDictionary dictionaryWithObjectsAndKeys:
@"yes", @"NoDaemon", // Never run as daemon
@"yes", @"Transient", // Don't log to console
name, @"ProgramName",
nil]] autorelease];
[EcProc cmdNewServer];
[tool log: mesg type: eclt];
[tool cmdFlushLogs];
[tool cmdQuit: 0];
RELEASE(arp);
exit(0);
}
int
main(int argc, char *argv[])
{
inner_main();
return 0;
}

View file

@ -30,48 +30,64 @@
#import <Foundation/Foundation.h>
#import "EcProcess.h"
#import "EcUserDefaults.h"
int
main()
{
CREATE_AUTORELEASE_POOL(arp);
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
NSUserDefaults *defs;
NSString *pref;
NSString *host;
NSString *name;
id proxy;
BOOL any = NO;
host = [defs stringForKey: @"BSCommandHost"];
if (host == nil)
pref = EC_DEFAULTS_PREFIX;
if (nil == pref)
{
host = [defs stringForKey: @"CommandHost"];
if (host == nil)
{
host = @"*";
}
}
if ([host length] == 0)
{
host = [[NSHost currentHost] name];
pref = @"";
}
defs = [NSUserDefaults userDefaultsWithPrefix: pref
strict: EC_DEFAULTS_STRICT];
/*
* Shut down the local command server.
*/
name = [defs stringForKey: @"BSCommandName"];
name = [defs stringForKey: @"CommandName"];
if (name == nil)
{
name = [defs stringForKey: @"CommandName"];
if (name == nil)
{
name = @"Command";
}
name = @"Command";
}
host = [defs stringForKey: @"CommandHost"];
if ([host length] == 0)
{
any = YES;
host = [[NSHost currentHost] name];
}
proxy = [NSConnection rootProxyForConnectionWithRegisteredName: name
host: host
usingNameServer: [NSSocketPortNameServer sharedInstance]];
[(id<Command>)proxy terminate];
if (nil == proxy && YES == any)
{
host = @"*";
proxy = [NSConnection rootProxyForConnectionWithRegisteredName: name
host: host
usingNameServer: [NSSocketPortNameServer sharedInstance]];
}
if (nil == proxy)
{
NSLog(@"Unable to contact %@ on %@", name, host);
}
else
{
[(id<Command>)proxy terminate];
}
RELEASE(arp);
return 0;
}