mirror of
https://github.com/gnustep/libs-ec.git
synced 2025-02-22 11:21:28 +00:00
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:
parent
65c43d8fff
commit
e7dd948f84
6 changed files with 226 additions and 20 deletions
|
@ -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>
|
2013-07-12 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* EcProcess.h: New method to get EC user directory
|
* EcProcess.h: New method to get EC user directory
|
||||||
|
|
31
ECCL.h
31
ECCL.h
|
@ -38,6 +38,37 @@
|
||||||
server processes for large scale software systems.
|
server processes for large scale software systems.
|
||||||
</p>
|
</p>
|
||||||
</section>
|
</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>
|
</chapter>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,9 @@
|
||||||
@class NSMutableSet;
|
@class NSMutableSet;
|
||||||
@class NSString;
|
@class NSString;
|
||||||
|
|
||||||
|
/* The EcClientI class provides a lightweight interface to a remote
|
||||||
|
* process, equipped to handle inter-process keepalive signalling.
|
||||||
|
*/
|
||||||
@interface EcClientI : NSObject
|
@interface EcClientI : NSObject
|
||||||
{
|
{
|
||||||
id<CmdClient> theServer;
|
id<CmdClient> theServer;
|
||||||
|
|
|
@ -64,6 +64,7 @@ TOOL_NAME = \
|
||||||
Command \
|
Command \
|
||||||
Console \
|
Console \
|
||||||
Control \
|
Control \
|
||||||
|
LogTool \
|
||||||
Terminate \
|
Terminate \
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,10 +80,14 @@ Control_OBJC_FILES = Control.m EcControl.m EcClientI.m NSFileHandle+Printf.m
|
||||||
Control_TOOL_LIBS += -lECCL
|
Control_TOOL_LIBS += -lECCL
|
||||||
Control_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR)
|
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_OBJC_FILES = Terminate.m
|
||||||
Terminate_TOOL_LIBS += -lECCL
|
Terminate_TOOL_LIBS += -lECCL
|
||||||
Terminate_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR)
|
Terminate_LIB_DIRS += -L./$(GNUSTEP_OBJ_DIR)
|
||||||
|
Terminate_CPPFLAGS += ${ECCL_CPPFLAGS}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
144
LogTool.m
Normal file
144
LogTool.m
Normal 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;
|
||||||
|
}
|
54
Terminate.m
54
Terminate.m
|
@ -30,48 +30,64 @@
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
#import "EcProcess.h"
|
#import "EcProcess.h"
|
||||||
|
#import "EcUserDefaults.h"
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main()
|
main()
|
||||||
{
|
{
|
||||||
CREATE_AUTORELEASE_POOL(arp);
|
CREATE_AUTORELEASE_POOL(arp);
|
||||||
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
NSUserDefaults *defs;
|
||||||
|
NSString *pref;
|
||||||
NSString *host;
|
NSString *host;
|
||||||
NSString *name;
|
NSString *name;
|
||||||
id proxy;
|
id proxy;
|
||||||
|
BOOL any = NO;
|
||||||
|
|
||||||
host = [defs stringForKey: @"BSCommandHost"];
|
pref = EC_DEFAULTS_PREFIX;
|
||||||
if (host == nil)
|
if (nil == pref)
|
||||||
{
|
{
|
||||||
host = [defs stringForKey: @"CommandHost"];
|
pref = @"";
|
||||||
if (host == nil)
|
|
||||||
{
|
|
||||||
host = @"*";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ([host length] == 0)
|
|
||||||
{
|
|
||||||
host = [[NSHost currentHost] name];
|
|
||||||
}
|
}
|
||||||
|
defs = [NSUserDefaults userDefaultsWithPrefix: pref
|
||||||
|
strict: EC_DEFAULTS_STRICT];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Shut down the local command server.
|
* Shut down the local command server.
|
||||||
*/
|
*/
|
||||||
name = [defs stringForKey: @"BSCommandName"];
|
name = [defs stringForKey: @"CommandName"];
|
||||||
if (name == nil)
|
if (name == nil)
|
||||||
{
|
{
|
||||||
name = [defs stringForKey: @"CommandName"];
|
name = @"Command";
|
||||||
if (name == nil)
|
}
|
||||||
{
|
|
||||||
name = @"Command";
|
host = [defs stringForKey: @"CommandHost"];
|
||||||
}
|
if ([host length] == 0)
|
||||||
|
{
|
||||||
|
any = YES;
|
||||||
|
host = [[NSHost currentHost] name];
|
||||||
}
|
}
|
||||||
|
|
||||||
proxy = [NSConnection rootProxyForConnectionWithRegisteredName: name
|
proxy = [NSConnection rootProxyForConnectionWithRegisteredName: name
|
||||||
host: host
|
host: host
|
||||||
usingNameServer: [NSSocketPortNameServer sharedInstance]];
|
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);
|
RELEASE(arp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue