1+ /**
2+ * ClusterODM - A reverse proxy, load balancer and task tracker for NodeODM
3+ * Copyright (C) 2018-present MasseranoLabs LLC
4+ *
5+ * This program is free software: you can redistribute it and/or modify
6+ * it under the terms of the GNU Affero General Public License as
7+ * published by the Free Software Foundation, either version 3 of the
8+ * License, or (at your option) any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU Affero General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU Affero General Public License
16+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
17+ */
18+ "use strict" ;
19+
20+ let config = require ( '../config' ) ;
21+ let winston = require ( 'winston' ) ;
22+ let fs = require ( 'fs' ) ;
23+ let path = require ( 'path' ) ;
24+
25+ let accessLog = ( ) => { } ;
26+
27+ if ( config . accessLog . logFile ) {
28+ const logPath = path . dirname ( config . accessLog . logFile ) ;
29+
30+ try {
31+ fs . accessSync ( logPath , fs . W_OK ) ;
32+ } catch ( e ) {
33+ console . log ( "Access log directory '" + logPath + "' cannot be written to" ) ;
34+ throw e ;
35+ }
36+
37+
38+ let logger = winston . createLogger ( { transports : [
39+ new winston . transports . File ( {
40+ format : winston . format . printf ( info => `${ new Date ( ) . toISOString ( ) } ${ info . message } ` ) ,
41+ filename : config . accessLog . logFile ,
42+ json : false ,
43+ maxsize : config . accessLog . maxFileSize ,
44+ maxFiles : 1 ,
45+ level : "info"
46+ } )
47+ ] } ) ;
48+
49+ accessLog = ( remoteIp , url ) => {
50+ logger . info ( `[${ remoteIp } ] ${ url } ` ) ;
51+ }
52+ }
53+
54+
55+
56+ module . exports = accessLog ;
0 commit comments