Skip to content

Commit 1aed38f

Browse files
authored
Merge pull request #1457 from asmagill/loggingUpdates
Logging updates to LuaSkin
2 parents 9c7d11e + 1c0c8c5 commit 1aed38f

File tree

7 files changed

+54
-154
lines changed

7 files changed

+54
-154
lines changed

LuaSkin/LuaSkin/Skin.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -757,18 +757,5 @@ NSString *specMaskToString(int spec);
757757
*/
758758
- (NSString *)tracebackWithTag:(NSString *)theTag fromStackPos:(int)level ;
759759

760-
/*!
761-
@abstract Log the specified message with at the specified level with the traceback position prepended.
762-
763-
@discussion Logs the specified message, prepended with the lua chunk name and line number at the specified traceback level, for the specified level. The log level and combined message is logged with @link logAtLevel:withMessage: @/link.
764-
765-
@warning This method is primarily for testing and may be removed in a future release.
766-
767-
@param level The message log level as an integer. Predefined levels are defined and used within LuaSkin itself as (in decreasing level of severity) @link LS_LOG_ERROR @/link, @link LS_LOG_WARN @/link, @link LS_LOG_INFO @/link, @link LS_LOG_DEBUG @/link, and @link LS_LOG_VERBOSE @/link.
768-
@param theMessage the message to log
769-
@param pos the lua traceback level to attempt to retrieve the chunk name and line number from
770-
*/
771-
- (void)logAtLevel:(int)level withMessage:(NSString *)theMessage fromStackPos:(int)pos ;
772-
773760
@end
774761

LuaSkin/LuaSkin/Skin.m

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -490,8 +490,7 @@ - (BOOL)registerPushNSHelper:(pushNSHelperFunction)helperFN forClass:(const char
490490
[self logAtLevel:LS_LOG_WARN
491491
withMessage:[NSString stringWithFormat:@"registerPushNSHelper:forClass:%s already defined at %@",
492492
className,
493-
self.registeredNSHelperLocations[@(className)]]
494-
fromStackPos:level] ;
493+
self.registeredNSHelperLocations[@(className)]]] ;
495494
} else {
496495
luaL_where(self.L, level) ;
497496
NSString *locationString = @(lua_tostring(self.L, -1)) ;
@@ -502,8 +501,7 @@ - (BOOL)registerPushNSHelper:(pushNSHelperFunction)helperFN forClass:(const char
502501
}
503502
} else {
504503
[self logAtLevel:LS_LOG_WARN
505-
withMessage:@"registerPushNSHelper:forClass: requires both helperFN and className"
506-
fromStackPos:level] ;
504+
withMessage:@"registerPushNSHelper:forClass: requires both helperFN and className"] ;
507505
}
508506
return allGood ;
509507
}
@@ -572,8 +570,7 @@ - (BOOL)registerLuaObjectHelper:(luaObjectHelperFunction)helperFN forClass:(cons
572570
[self logAtLevel:LS_LOG_WARN
573571
withMessage:[NSString stringWithFormat:@"registerLuaObjectHelper:forClass:%s already defined at %@",
574572
className,
575-
self.registeredLuaObjectHelperFunctions[@(className)]]
576-
fromStackPos:level] ;
573+
self.registeredLuaObjectHelperFunctions[@(className)]]] ;
577574
} else {
578575
luaL_where(self.L, level) ;
579576
NSString *locationString = @(lua_tostring(self.L, -1)) ;
@@ -584,8 +581,7 @@ - (BOOL)registerLuaObjectHelper:(luaObjectHelperFunction)helperFN forClass:(cons
584581
}
585582
} else {
586583
[self logAtLevel:LS_LOG_WARN
587-
withMessage:@"registerLuaObjectHelper:forClass: requires both helperFN and className"
588-
fromStackPos:level] ;
584+
withMessage:@"registerLuaObjectHelper:forClass: requires both helperFN and className"] ;
589585
}
590586
return allGood ;
591587
}
@@ -624,8 +620,7 @@ - (NSRect)tableToRectAtIndex:(int)idx {
624620
return NSMakeRect(x, y, w, h) ;
625621
} else {
626622
[self logAtLevel:LS_LOG_WARN
627-
withMessage:[NSString stringWithFormat:@"returning NSZeroRect: can't make NSRect from %s.", lua_typename(self.L, lua_type(self.L, idx))]
628-
fromStackPos:1] ;
623+
withMessage:[NSString stringWithFormat:@"returning NSZeroRect: can't make NSRect from %s.", lua_typename(self.L, lua_type(self.L, idx))]] ;
629624
return NSZeroRect ;
630625
}
631626
}
@@ -639,8 +634,7 @@ - (NSPoint)tableToPointAtIndex:(int)idx {
639634
return NSMakePoint(x, y);
640635
} else {
641636
[self logAtLevel:LS_LOG_WARN
642-
withMessage:[NSString stringWithFormat:@"returning NSZeroPoint: can't make NSPoint from %s.", lua_typename(self.L, lua_type(self.L, idx))]
643-
fromStackPos:1] ;
637+
withMessage:[NSString stringWithFormat:@"returning NSZeroPoint: can't make NSPoint from %s.", lua_typename(self.L, lua_type(self.L, idx))]] ;
644638
return NSZeroPoint ;
645639
}
646640
}
@@ -654,8 +648,7 @@ - (NSSize)tableToSizeAtIndex:(int)idx {
654648
return NSMakeSize(w, h);
655649
} else {
656650
[self logAtLevel:LS_LOG_WARN
657-
withMessage:[NSString stringWithFormat:@"returning NSZeroSize: can't make NSSize from %s.", lua_typename(self.L, lua_type(self.L, idx))]
658-
fromStackPos:1] ;
651+
withMessage:[NSString stringWithFormat:@"returning NSZeroSize: can't make NSSize from %s.", lua_typename(self.L, lua_type(self.L, idx))]] ;
659652
return NSZeroSize ;
660653
}
661654
}
@@ -677,8 +670,7 @@ - (lua_Integer)maxNatIndex:(int)idx {
677670
}
678671
} else {
679672
[self logAtLevel:LS_LOG_ERROR
680-
withMessage:[NSString stringWithFormat:@"table expected (found %s)", lua_typename(self.L, lua_type(self.L, idx))]
681-
fromStackPos:0] ;
673+
withMessage:[NSString stringWithFormat:@"table expected (found %s)", lua_typename(self.L, lua_type(self.L, idx))]] ;
682674
}
683675
return max ;
684676
}
@@ -695,8 +687,7 @@ - (lua_Integer)countNatIndex:(int)idx {
695687
}
696688
} else {
697689
[self logAtLevel:LS_LOG_ERROR
698-
withMessage:[NSString stringWithFormat:@"table expected (found %s)", lua_typename(self.L, lua_type(self.L, idx))]
699-
fromStackPos:0] ;
690+
withMessage:[NSString stringWithFormat:@"table expected (found %s)", lua_typename(self.L, lua_type(self.L, idx))]] ;
700691
}
701692
return max ;
702693
}
@@ -1026,8 +1017,7 @@ - (id)toNSObjectAtIndex:(int)idx withOptions:(NSUInteger)options alreadySeenObje
10261017
if (seenObject) {
10271018
if ([[seenObject lastObject] isEqualToNumber:@(NO)] && ((options & LS_NSAllowsSelfReference) != LS_NSAllowsSelfReference)) {
10281019
[self logAtLevel:LS_LOG_WARN
1029-
withMessage:@"lua table cannot contain self-references"
1030-
fromStackPos:1] ;
1020+
withMessage:@"lua table cannot contain self-references"] ;
10311021
// return [NSNull null] ;
10321022
return nil ;
10331023
} else {
@@ -1060,8 +1050,7 @@ - (id)toNSObjectAtIndex:(int)idx withOptions:(NSUInteger)options alreadySeenObje
10601050
} else {
10611051
if (stringOptions != LS_NSNone) {
10621052
[self logAtLevel:LS_LOG_DEBUG
1063-
withMessage:@"only one of LS_NSPreserveLuaStringExactly or LS_NSLuaStringAsDataOnly can be specified: using default behavior"
1064-
fromStackPos:0] ;
1053+
withMessage:@"only one of LS_NSPreserveLuaStringExactly or LS_NSLuaStringAsDataOnly can be specified: using default behavior"] ;
10651054
}
10661055
return [self getValidUTF8AtIndex:idx] ;
10671056
}
@@ -1190,8 +1179,7 @@ - (id)tableAtIndex:(int)idx withOptions:(NSUInteger)options alreadySeenObjects:(
11901179
} else {
11911180
[self logAtLevel:LS_LOG_ERROR
11921181
withMessage:[NSString stringWithFormat:@"array element (%s) cannot be converted into a proper NSObject",
1193-
luaL_tolstring(self.L, -1, NULL)]
1194-
fromStackPos:1] ;
1182+
luaL_tolstring(self.L, -1, NULL)]] ;
11951183
result = nil ;
11961184
lua_pop(self.L, 2) ; // luaL_tolstring result and lua_geti result
11971185
return nil ;
@@ -1209,8 +1197,7 @@ - (id)tableAtIndex:(int)idx withOptions:(NSUInteger)options alreadySeenObjects:(
12091197
[self logAtLevel:LS_LOG_ERROR
12101198
withMessage:[NSString stringWithFormat:@"dictionary %@ (%s) cannot be converted into a proper NSObject",
12111199
(key) ? @"key" : @"value",
1212-
luaL_tolstring(self.L, (key) ? -2 : lua_gettop(self.L), NULL)]
1213-
fromStackPos:1] ;
1200+
luaL_tolstring(self.L, (key) ? -2 : lua_gettop(self.L), NULL)]] ;
12141201
result = nil ;
12151202
lua_pop(self.L, 3) ; // luaL_tolstring result, lua_next value, and lua_next key
12161203
return nil ;
@@ -1236,17 +1223,6 @@ - (void) logAtLevel:(int)level withMessage:(NSString *)theMessage {
12361223
}
12371224
}
12381225

1239-
// Testing for: chunkname:currentline:theMessage
1240-
- (void) logAtLevel:(int)level withMessage:(NSString *)theMessage fromStackPos:(int)pos {
1241-
luaL_where(self.L, pos) ;
1242-
NSString *locationInfo = @(lua_tostring(self.L, -1)) ;
1243-
lua_pop(self.L, 1) ;
1244-
if (!locationInfo || [locationInfo isEqualToString:@""])
1245-
locationInfo = [NSString stringWithFormat:@"(no lua location info at depth %d)", pos] ;
1246-
1247-
[self logAtLevel:level withMessage:[NSString stringWithFormat:@"%@:%@", locationInfo, theMessage]] ;
1248-
}
1249-
12501226
// shorthand
12511227
- (void)logVerbose:(NSString *)theMessage { [self logAtLevel:LS_LOG_VERBOSE withMessage:theMessage] ; }
12521228
- (void)logDebug:(NSString *)theMessage { [self logAtLevel:LS_LOG_DEBUG withMessage:theMessage] ; }

extensions/application/internal.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,9 +1174,7 @@ static int nsrunningapplication_tolua(lua_State *L, id obj) {
11741174

11751175
if (!new_application(L, [app processIdentifier])) {
11761176
lua_pop(L, 1) ; // removed aborted userdata
1177-
[[LuaSkin shared] logAtLevel:LS_LOG_WARN
1178-
withMessage:[NSString stringWithFormat:@"No Process ID for %@", obj]
1179-
fromStackPos:1] ;
1177+
[[LuaSkin shared] logWarn:[NSString stringWithFormat:@"No Process ID for %@", obj]] ;
11801178
lua_pushnil(L) ;
11811179
}
11821180
return 1 ;

extensions/socket/internal.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,22 @@ - (id)init {
7979
}
8080

8181
- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port {
82-
[LuaSkin logInfo:@"TCP socket connected"];
82+
[LuaSkin logDebug:@"TCP socket connected"];
8383
self.userData = DEFAULT;
8484
if (self.connectCallback != LUA_NOREF)
8585
connectCallback(self);
8686
}
8787

8888
- (void)socket:(GCDAsyncSocket *)sock didConnectToUrl:(NSURL *)url {
89-
[LuaSkin logInfo:@"TCP Unix domain socket connected"];
89+
[LuaSkin logDebug:@"TCP Unix domain socket connected"];
9090
self.userData = DEFAULT;
9191
self.unixSocketPath = [url path];
9292
if (self.connectCallback != LUA_NOREF)
9393
connectCallback(self);
9494
}
9595

9696
- (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket {
97-
[LuaSkin logInfo:@"TCP client connected"];
97+
[LuaSkin logDebug:@"TCP client connected"];
9898
newSocket.userData = CLIENT;
9999

100100
@synchronized(self.connectedSockets) {
@@ -104,12 +104,12 @@ - (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSo
104104

105105
- (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err {
106106
if (sock.userData == CLIENT) {
107-
[LuaSkin logInfo:[NSString stringWithFormat:@"TCP client disconnected: %@", [err localizedDescription]]];
107+
[LuaSkin logDebug:[NSString stringWithFormat:@"TCP client disconnected: %@", [err localizedDescription]]];
108108
@synchronized(self.connectedSockets) {
109109
[self.connectedSockets removeObject:sock];
110110
}
111111
} else if (sock.userData == SERVER) {
112-
[LuaSkin logInfo:[NSString stringWithFormat:@"TCP server disconnected: %@", [err localizedDescription]]];
112+
[LuaSkin logDebug:[NSString stringWithFormat:@"TCP server disconnected: %@", [err localizedDescription]]];
113113
@synchronized(self.connectedSockets) {
114114
for (HSAsyncTcpSocket *client in self.connectedSockets)
115115
[client disconnect];
@@ -123,19 +123,19 @@ - (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err {
123123
self.unixSocketPath = nil;
124124
}
125125
} else
126-
[LuaSkin logInfo:[NSString stringWithFormat:@"TCP socket disconnected: %@", [err localizedDescription]]];
126+
[LuaSkin logDebug:[NSString stringWithFormat:@"TCP socket disconnected: %@", [err localizedDescription]]];
127127

128128
sock.userData = nil;
129129
}
130130

131131
- (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag {
132-
[LuaSkin logInfo:@"Data written to TCP socket"];
132+
[LuaSkin logDebug:@"Data written to TCP socket"];
133133
if (self.writeCallback != LUA_NOREF)
134134
writeCallback(self, tag);
135135
}
136136

137137
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag {
138-
[LuaSkin logInfo:@"Data read from TCP socket"];
138+
[LuaSkin logDebug:@"Data read from TCP socket"];
139139
if (self.readCallback != LUA_NOREF)
140140
readCallback(self, data, tag);
141141
}
@@ -148,7 +148,7 @@ - (void)socket:(GCDAsyncSocket *)sock didReceiveTrust:(SecTrustRef)trust complet
148148
}
149149

150150
- (void)socketDidSecure:(GCDAsyncSocket *)sock {
151-
[LuaSkin logInfo:@"TCP socket secured"];
151+
[LuaSkin logDebug:@"TCP socket secured"];
152152
}
153153

154154
@end

extensions/socket/udp.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ - (id)init {
7575
}
7676

7777
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didConnectToAddress:(NSData *)address {
78-
[LuaSkin logInfo:@"UDP socket connected"];
78+
[LuaSkin logDebug:@"UDP socket connected"];
7979
self.userData = DEFAULT;
8080
if (self.connectCallback != LUA_NOREF)
8181
connectCallback(self);
@@ -87,12 +87,12 @@ - (void)udpSocket:(GCDAsyncUdpSocket *)sock didNotConnect:(NSError *)error {
8787
}
8888

8989
- (void)udpSocketDidClose:(GCDAsyncUdpSocket *)sock withError:(NSError *)error {
90-
[LuaSkin logInfo:[NSString stringWithFormat:@"UDP socket closed: %@", [error localizedDescription]]];
90+
[LuaSkin logDebug:[NSString stringWithFormat:@"UDP socket closed: %@", [error localizedDescription]]];
9191
sock.userData = nil;
9292
}
9393

9494
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didSendDataWithTag:(long)tag {
95-
[LuaSkin logInfo:@"Data written to UDP socket"];
95+
[LuaSkin logDebug:@"Data written to UDP socket"];
9696
if (self.writeCallback != LUA_NOREF)
9797
writeCallback(self, tag);
9898
}
@@ -103,7 +103,7 @@ - (void)udpSocket:(GCDAsyncUdpSocket *)sock didNotSendDataWithTag:(long)tag dueT
103103
}
104104

105105
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data fromAddress:(NSData *)address withFilterContext:(id)filterContext {
106-
[LuaSkin logInfo:@"Data read from UDP socket"];
106+
[LuaSkin logDebug:@"Data read from UDP socket"];
107107
if (self.readCallback != LUA_NOREF)
108108
readCallback(self, data, address);
109109
}

0 commit comments

Comments
 (0)