Skip to content

Commit d64d4c8

Browse files
committed
src: Migrate all logging to new interface versions .log -> .log.if [#41]
1 parent db73602 commit d64d4c8

File tree

14 files changed

+96
-80
lines changed

14 files changed

+96
-80
lines changed

Diff for: src/cron.q

+12-12
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
/ NOTE: The initialistion function will not overwrite .z.ts if it is already set.
3838
.cron.init:{
3939
if[.ns.isSet `.z.ts;
40-
.log.warn "Timer function is already set. Cron will not override automatically";
40+
.log.if.warn "Timer function is already set. Cron will not override automatically";
4141
:(::);
4242
];
4343

@@ -56,7 +56,7 @@
5656
:(::);
5757
];
5858

59-
.log.info "Enabling cron job scheduler [ Timer Interval: ",string[.cron.cfg.timerInterval]," ms ]";
59+
.log.if.info "Enabling cron job scheduler [ Timer Interval: ",string[.cron.cfg.timerInterval]," ms ]";
6060

6161
.util.system "t ",string .cron.cfg.timerInterval;
6262
};
@@ -67,8 +67,8 @@
6767
:(::);
6868
];
6969

70-
.log.info "Disabling cron job scheduler";
71-
.log.warn " No scheduled jobs will be executed until cron is enabled again";
70+
.log.if.info "Disabling cron job scheduler";
71+
.log.if.warn " No scheduled jobs will be executed until cron is enabled again";
7272

7373
.util.system "t 0";
7474
};
@@ -88,32 +88,32 @@
8888
/ @throws InvalidCronJobTimeException If the start time specified is before the current time or the end time is before the start time
8989
.cron.add:{[func;args;runType;startTime;endTime;interval]
9090
if[not .ns.isSet func;
91-
.log.error "Function to add to cron does not exist [ Function: ",string[func]," ]";
91+
.log.if.error "Function to add to cron does not exist [ Function: ",string[func]," ]";
9292
'"FunctionDoesNotExistFunction";
9393
];
9494

9595
if[not .type.isFunction get func;
96-
.log.error "Symbol reference for cron job is not a function [ Reference: ",string[func]," ]";
96+
.log.if.error "Symbol reference for cron job is not a function [ Reference: ",string[func]," ]";
9797
'"ReferenceIsNotAFunctionException";
9898
];
9999

100100
if[not runType in key .cron.cfg.runners;
101-
.log.error "Invalid cron run type. Expecting one of: ",.convert.listToString key .cron.cfg.runners;
101+
.log.if.error "Invalid cron run type. Expecting one of: ",.convert.listToString key .cron.cfg.runners;
102102
'"InvalidCronRunTypeException";
103103
];
104104

105105
if[startTime < .time.today[]+`second$.time.nowAsTime[];
106-
.log.error "Cron job start time is in the past. Cannot add job";
106+
.log.if.error "Cron job start time is in the past. Cannot add job";
107107
'"InvalidCronJobTimeException";
108108
];
109109

110110
if[not[.util.isEmpty endTime] & endTime < startTime;
111-
.log.error "Cron job end time specified is before the start time. Cannot add job";
111+
.log.if.error "Cron job end time specified is before the start time. Cannot add job";
112112
'"InvalidCronJobTimeException";
113113
];
114114

115115
if[not[.util.isEmpty interval] & .cron.cfg.timerInterval > .convert.timespanToMs interval;
116-
.log.error "Cron job repeat interval is shorter than the cron timer interval. Cannot add job";
116+
.log.if.error "Cron job repeat interval is shorter than the cron timer interval. Cannot add job";
117117
'"InvalidCronJobIntervalException";
118118
];
119119

@@ -200,7 +200,7 @@
200200
jobDetails:.cron.jobs jobId;
201201

202202
if[.type.isInfinite jobDetails`nextRunTime;
203-
.log.debug "Job has been self-cancelled. Will not reschedule [ Job: ",string[jobId]," ]";
203+
.log.if.debug "Job has been self-cancelled. Will not reschedule [ Job: ",string[jobId]," ]";
204204
:status;
205205
];
206206

@@ -231,7 +231,7 @@
231231
status:1b;
232232

233233
if[.ns.const.pExecFailure ~ first result;
234-
.log.error "Cron job failed to execute [ Job ID: ",string[jobId]," ]. Error - ",last result;
234+
.log.if.error "Cron job failed to execute [ Job ID: ",string[jobId]," ]. Error - ",last result;
235235
status:0b;
236236

237237
result:(`errorMsg`backtrace inter key result)#result;

Diff for: src/csv.q

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
'"IllegalArgumentException";
1818
];
1919

20-
.log.info"Loading CSV file ",.convert.hsymToString path;
20+
.log.if.info"Loading CSV file ",.convert.hsymToString path;
2121

2222
:.csv.parse[types;read0 path];
2323
};
@@ -60,7 +60,7 @@
6060
'"UnsupportedColumnTypeException (",.convert.listToString[where unsupported],")";
6161
];
6262

63-
.log.info "Saving CSV file [ Target: ",string[path]," ] [ Table Length: ",string[count data]," ]";
63+
.log.if.info "Saving CSV file [ Target: ",string[path]," ] [ Table Length: ",string[count data]," ]";
6464

6565
:path 0: "," 0: data;
6666
};

Diff for: src/event.q

+12-12
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@
4545
listeners:.event.handlers event;
4646

4747
if[0=count listeners;
48-
.log.debug "Event fired but no listeners [ Event: ",string[event]," ] [ Args: ",.Q.s1[args]," ]";
48+
.log.if.debug "Event fired but no listeners [ Event: ",string[event]," ] [ Args: ",.Q.s1[args]," ]";
4949
:(::);
5050
];
5151

52-
.log.debug "Notifying listeners of event [ Event: ",string[event]," ] [ Args: ",.Q.s1[args]," ]";
52+
.log.if.debug "Notifying listeners of event [ Event: ",string[event]," ] [ Args: ",.Q.s1[args]," ]";
5353

5454
listenRes:listeners!.ns.protectedExecute[;args] each listeners;
5555
listenErr:where .ns.const.pExecFailure~/:first each listenRes;
5656

5757
if[0 < count listenErr;
58-
.log.warn "One or more listeners failed to execute successfully [ Event: ",string[event]," ] [ Errored: ",.convert.listToString[listenErr]," ]";
59-
.log.warn "Listener exception detail:\n",.Q.s listenErr#last each listenRes;
58+
.log.if.warn "One or more listeners failed to execute successfully [ Event: ",string[event]," ] [ Errored: ",.convert.listToString[listenErr]," ]";
59+
.log.if.warn "Listener exception detail:\n",.Q.s listenErr#last each listenRes;
6060
:(::);
6161
];
6262
};
@@ -76,17 +76,17 @@
7676
];
7777

7878
if[not event in key .event.handlers;
79-
.log.info "New event type to be added for management [ Event: ",string[event]," ]";
79+
.log.if.info "New event type to be added for management [ Event: ",string[event]," ]";
8080
];
8181

8282
if[listenFunction in .event.handlers event;
83-
.log.debug "Listener already added for event. Will not re-add [ Event: ",string[event]," ] [ Listener: ",string[listenFunction]," ]";
83+
.log.if.debug "Listener already added for event. Will not re-add [ Event: ",string[event]," ] [ Listener: ",string[listenFunction]," ]";
8484
:(::);
8585
];
8686

8787
.event.handlers[event],:listenFunction;
8888

89-
.log.info "New listener added for event [ Event: ",string[event]," ] [ Listener: ",string[listenFunction]," ]";
89+
.log.if.info "New listener added for event [ Event: ",string[event]," ] [ Listener: ",string[listenFunction]," ]";
9090
};
9191

9292
/ Removes the listener from the specified event
@@ -103,7 +103,7 @@
103103

104104
.event.handlers[event]:.event.handlers[event] except listenFunction;
105105

106-
.log.info "Removed listener from event [ Event: ",string[event]," ] [ Listener: ",string[listenFunction]," ]";
106+
.log.if.info "Removed listener from event [ Event: ",string[event]," ] [ Listener: ",string[listenFunction]," ]";
107107
};
108108

109109
/ Binds an event to a specific function so the event management library can be used with it. This is generally
@@ -113,7 +113,7 @@
113113
/ @param bindFunction (Symbol) Reference to the function that should be set
114114
.event.installHandler:{[event;bindFunction]
115115
if[.ns.isSet bindFunction;
116-
.log.warn "Function to bind event management to is already set. Will not override [ Function: ",string[bindFunction]," ]";
116+
.log.if.warn "Function to bind event management to is already set. Will not override [ Function: ",string[bindFunction]," ]";
117117
:(::);
118118
];
119119

@@ -123,12 +123,12 @@
123123
.event.handlers[event]:`symbol$();
124124
];
125125

126-
.log.info "Event management now enabled [ Event: ",string[event]," ] [ Bound To: ",string[bindFunction]," ]";
126+
.log.if.info "Event management now enabled [ Event: ",string[event]," ] [ Bound To: ",string[bindFunction]," ]";
127127
};
128128

129129
.event.i.defaultExitHandler:{[ec]
130130
$[0=ec;
131-
.log.info "Process is exiting at ",string[.time.now[]]," [ Exit Code: ",string[ec]," ]";
132-
.log.fatal "Process is exiting at ",string[.time.now[]]," with non-zero exit code [ Exit Code: ",string[ec]," ]"
131+
.log.if.info "Process is exiting at ",string[.time.now[]]," [ Exit Code: ",string[ec]," ]";
132+
.log.if.fatal "Process is exiting at ",string[.time.now[]]," with non-zero exit code [ Exit Code: ",string[ec]," ]"
133133
];
134134
};

Diff for: src/file.q

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
/ @returns (FolderPath) The supplied folder to check
6262
.file.ensureDir:{[dir]
6363
if[not .type.isFolder dir;
64-
.log.info "Directory does not exist, creating [ Directory: ",string[dir]," ]";
64+
.log.if.info "Directory does not exist, creating [ Directory: ",string[dir]," ]";
6565
.os.run[`mkdir;.convert.hsymToString dir];
6666
];
6767

Diff for: src/http.q

+14-14
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
.http.init:{
6464
if[.http.cfg.cacheProxy;
65-
.log.info "Querying environment variables for HTTP / HTTPS proxy settings";
65+
.log.if.info "Querying environment variables for HTTP / HTTPS proxy settings";
6666
.http.proxy:.http.i.getProxyConfig[];
6767
];
6868

@@ -71,11 +71,11 @@
7171
.http.userAgent:"-" sv string `kdbplus,.z.K,.z.k,.z.i;
7272
];
7373

74-
.log.info "Send user agent with HTTP requests enabled [ User Agent: ",.http.userAgent," ]";
74+
.log.if.info "Send user agent with HTTP requests enabled [ User Agent: ",.http.userAgent," ]";
7575
];
7676

7777
.http.gzAvailable:.ns.isSet `.Q.gz;
78-
.log.info "HTTP compression with GZIP [ Available: ",string[`no`yes .http.gzAvailable]," ]";
78+
.log.if.info "HTTP compression with GZIP [ Available: ",string[`no`yes .http.gzAvailable]," ]";
7979
};
8080

8181

@@ -154,7 +154,7 @@
154154
location:response[`headers] key[response`headers] first where `location = lower key response`headers;
155155

156156
if[0 < count location;
157-
.log.info "Following HTTP redirect as configured [ Original URL: ",url," ] [ New URL: ",location," ]";
157+
.log.if.info "Following HTTP redirect as configured [ Original URL: ",url," ] [ New URL: ",location," ]";
158158
response:.http.send[method; location; body; contentType; headers];
159159
];
160160
];
@@ -188,7 +188,7 @@
188188
urlArgs:"=" vs/: "&" vs urlArgs;
189189

190190
if[not all 2 = count each urlArgs;
191-
.log.error "URL query string is invalid, must be ampersand separated 'key=value' pairs [ URL: ",urlParts[`path]," ]";
191+
.log.if.error "URL query string is invalid, must be ampersand separated 'key=value' pairs [ URL: ",urlParts[`path]," ]";
192192
'"InvalidUrlQueryStringException";
193193
];
194194

@@ -269,24 +269,24 @@
269269
.http.i.send:{[urlParts; requestStr]
270270
if[any urlParts[`scheme] like/: string[.http.cfg.tlsSchemes],\:"://";
271271
if[not .util.isTlsAvailable[];
272-
.log.error "Cannot open TLS-based connection as TLS is not available in the current process";
272+
.log.if.error "Cannot open TLS-based connection as TLS is not available in the current process";
273273
'"TlsNotAvailableException";
274274
];
275275
];
276276

277277
urlForLog:.http.i.urlForLog urlParts;
278278

279-
.log.info "Sending HTTP request [ URL: ",urlForLog," ] [ Via Proxy: ",string[`no`yes urlParts`proxy]," ]";
280-
.log.trace "HTTP request:\n",requestStr;
279+
.log.if.info "Sending HTTP request [ URL: ",urlForLog," ] [ Via Proxy: ",string[`no`yes urlParts`proxy]," ]";
280+
.log.if.trace "HTTP request:\n",requestStr;
281281

282282
httpResp:@[urlParts`hp; requestStr; { (`HTTP_REQUEST_FAIL; x) }];
283283

284284
if[`HTTP_REQUEST_FAIL ~ first httpResp;
285-
.log.error "Failed to connect to HTTP endpoint [ URL: ",urlForLog," ]. Error - ",last httpResp;
285+
.log.if.error "Failed to connect to HTTP endpoint [ URL: ",urlForLog," ]. Error - ",last httpResp;
286286
'"HttpConnectionFailedException";
287287
];
288288

289-
.log.info "HTTP request returned OK [ URL: ",urlForLog," ]";
289+
.log.if.info "HTTP request returned OK [ URL: ",urlForLog," ]";
290290

291291
:httpResp;
292292
};
@@ -344,16 +344,16 @@
344344
proxyHp:.http.proxy `$urlParts`scheme;
345345

346346
if["" ~ proxyHp;
347-
.log.trace "HTTP access request will route direct (no proxy config) [ Base URL: ",urlParts[`baseUrl]," ]";
347+
.log.if.trace "HTTP access request will route direct (no proxy config) [ Base URL: ",urlParts[`baseUrl]," ]";
348348
:`proxy`hp!(0b; `$":",raze urlParts`scheme`baseUrl);
349349
];
350350

351351
if[urlParts[`baseUrl] in .http.proxy`bypass;
352-
.log.trace "HTTP access request will bypass proxy due to 'NO_PROXY' match [ Base URL: ",urlParts[`baseUrl]," ]";
352+
.log.if.trace "HTTP access request will bypass proxy due to 'NO_PROXY' match [ Base URL: ",urlParts[`baseUrl]," ]";
353353
:`proxy`hp!(0b; `$":",raze urlParts`scheme`baseUrl);
354354
];
355355

356-
.log.trace "HTTP access request will route via proxy [ Base URL: ",urlParts[`baseUrl]," ] [ Proxy: ",proxyHp," ]";
356+
.log.if.trace "HTTP access request will route via proxy [ Base URL: ",urlParts[`baseUrl]," ] [ Proxy: ",proxyHp," ]";
357357
:`proxy`hp!(1b; `$":",proxyHp);
358358
};
359359

@@ -397,7 +397,7 @@
397397
];
398398

399399
if[not[.http.gzAvailable] | not "gzip" ~ ppHeaders`contentEncoding;
400-
.log.error "Invalid content encoding in HTTP response [ Specified: ",ppHeaders[`contentEncoding]," ] [ Supported: ",string[`none`gzip .http.gzAvailable]," ]";
400+
.log.if.error "Invalid content encoding in HTTP response [ Specified: ",ppHeaders[`contentEncoding]," ] [ Supported: ",string[`none`gzip .http.gzAvailable]," ]";
401401

402402
if[.http.cfg.errorOnInvaildContentEncoding;
403403
'"InvalidContentEncodingException";

Diff for: src/if.q

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
/ @throws ImplementationFunctionDoesNotExistException If the implementation function is a reference but doesn't exist
7676
/ @throws InvalidImplementationFunctionException If the implementation function is a reference to something that isn't a function
7777
.if.i.bindFunction:{[ifFunc; implFunc; overwrite]
78-
if[not 1 = count key ifFunc;
78+
if[not 0 = count key ifFunc;
7979
if[not overwrite;
8080
.if.i.log[`info;] "Interface: Not overwriting existing implementation for interface [ Interface: ",string[ifFunc]," ]";
8181
:(::);

Diff for: src/ipc.q

+8-8
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@
9292
];
9393
];
9494

95-
.log.info "Attempting to connect to ",logHostPort," (timeout ",string[timeout]," ms)";
95+
.log.if.info "Attempting to connect to ",logHostPort," (timeout ",string[timeout]," ms)";
9696

9797
h:@[hopen; (hostPort; timeout); { (`CONN_FAIL;x) }];
9898

9999
if[`CONN_FAIL~first h;
100-
.log.error "Failed to connect to ",logHostPort,". Error - ",last h;
100+
.log.if.error "Failed to connect to ",logHostPort,". Error - ",last h;
101101
'"ConnectionFailedException (",logHostPort,")";
102102
];
103103

104-
.log.info "Successfully connected to ",logHostPort," on handle ",string h;
104+
.log.if.info "Successfully connected to ",logHostPort," on handle ",string h;
105105

106106
`.ipc.outbound upsert (h; `$logHostPort; .time.now[]);
107107

@@ -118,7 +118,7 @@
118118
.ipc.i.connectionClosed h;
119119

120120
if[`FAILED_TO_CLOSE~first closeRes;
121-
.log.warn "Failed to close handle ",string[h],". Error - ",last closeRes;
121+
.log.if.warn "Failed to close handle ",string[h],". Error - ",last closeRes;
122122
:0b;
123123
];
124124

@@ -130,7 +130,7 @@
130130
/ @see .ipc.i.handleOpen
131131
/ @see .ipc.i.connectionClosed
132132
.ipc.i.enableInboundConnTracking:{
133-
.log.info "Enabling inbound connection tracking";
133+
.log.if.info "Enabling inbound connection tracking";
134134

135135
/ Optional dependency if inbound connection tracking required. Otherwise event is not loaded
136136
.require.lib`event;
@@ -160,7 +160,7 @@
160160
sourceIp:.convert.ipOctalToSymbol .z.a;
161161
user:`unknown^.z.u;
162162

163-
.log.info "New inbound ",string[connectType]," connection on handle ",string[h]," [ IP Address: ",string[sourceIp]," ] [ User: ",string[user]," ]";
163+
.log.if.info "New inbound ",string[connectType]," connection on handle ",string[h]," [ IP Address: ",string[sourceIp]," ] [ User: ",string[user]," ]";
164164

165165
`.ipc.inbound upsert (h;sourceIp;user;.time.now[];connectType);
166166
};
@@ -172,12 +172,12 @@
172172
.ipc.i.connectionClosed:{[h]
173173
if[h in key .ipc.inbound;
174174
hDetail:.ipc.inbound h;
175-
.log.info "Inbound connection on handle ",string[h]," closed [ IP Address: ",string[hDetail`sourceIp]," ] [ User: ",string[hDetail`user]," ]";
175+
.log.if.info "Inbound connection on handle ",string[h]," closed [ IP Address: ",string[hDetail`sourceIp]," ] [ User: ",string[hDetail`user]," ]";
176176
delete from `.ipc.inbound where handle = h;
177177
];
178178

179179
if[h in key .ipc.outbound;
180-
.log.info "Outbound connection on handle ",string[h]," closed";
180+
.log.if.info "Outbound connection on handle ",string[h]," closed";
181181
delete from `.ipc.outbound where handle = h;
182182
];
183183
};

0 commit comments

Comments
 (0)