forked from simonsww/edpx-zhixin
/
Log.php
684 lines (626 loc) · 22.6 KB
/
Log.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
<?php
/***************************************************************************
*
* Copyright (c) 2010 Baidu.com, Inc. All Rights Reserved
* $Id: Log.php,v 1.3 2011/01/21 12:05:28 liushi Exp $
* $Id: Log.php,v 1.4 2011/03/21 12:05:28 chenqiuwu Inf $
*
**************************************************************************/
/**
* @file Log.php
* @author zhujt(zhujianting@baidu.com)
* @date 2009/08/04 10:31:44
* @version $Revision: 1.2 $
* @brief class for logging
*
**/
/*********************************************
* format string 格式,取自lighttpd文档
* 前面标记 - 代表ODP的Log库不支持
* 行为不一致的,均有注释说明
* 后面的 === 之后的,是ODP Log库扩展的功能
====== ================================
Option Description
====== ================================
%% a percent sign
%h name or address of remote-host
-%l ident name (not supported)
-%u authenticated user
%t timestamp of the end-time of the request //param, show current time, param specifies strftime format
-%r request-line
-%s status code
-%b bytes sent for the body
%i HTTP-header field //param
%a remote address
%A local address
-%B same as %b
%C cookie field (not supported) //param
%D time used in ms
%e environment variable //param
%f physical filename
%H request protocol (HTTP/1.0, ...)
%m request method (GET, POST, ...)
-%n (not supported)
-%o `response header`_
%p server port
-%P (not supported)
%q query string
%T time used in seconds //support param, s, ms, us, default to s
%U request URL
%v server-name
%V HTTP request host name
-%X connection status
-%I bytes incomming
-%O bytes outgoing
====== ================================
%L Log level
%N line number
%E err_no
%l log_id
%u user
%S strArray, support param, takes a key and removes the key from %S
%M error message
%x ODP extension, supports various param, like log_level, line_number etc.
currently supported param for %x:
log_level, line, class, function, err_no, err_msg, log_id, app, function_param, argv, encoded_str_array
in %x, prepend u_ to key to urlencode before its value
*************************************************/
class Bd_Log
{
const LOG_LEVEL_FATAL = 0x01;
const LOG_LEVEL_WARNING = 0x02;
const LOG_LEVEL_NOTICE = 0x04;
const LOG_LEVEL_TRACE = 0x08;
const LOG_LEVEL_DEBUG = 0x10;
public static $arrLogLevels = array(
self::LOG_LEVEL_FATAL => 'FATAL',
self::LOG_LEVEL_WARNING => 'WARNING',
self::LOG_LEVEL_NOTICE => 'NOTICE',
self::LOG_LEVEL_TRACE => 'TRACE',
self::LOG_LEVEL_DEBUG => 'DEBUG',
);
protected $intLevel;
protected $strLogFile;
protected $bolAutoRotate;
protected $addNotice = array();
private static $arrInstance = array();
public static $current_instance;
private static $bolIsOmp = null;
private static $strLogPath = null;
private static $strDataPath = null;
const DEFAULT_FORMAT = '%L: %t [%f:%N] errno[%E] logId[%l] uri[%U] user[%u] refer[%{referer}i] cookie[%{cookie}i] %S %M';
const DEFAULT_FORMAT_STD = '%L: %{%m-%d %H:%M:%S}t %{app}x * %{pid}x [logid=%l filename=%f lineno=%N errno=%{err_no}x %{encoded_str_array}x errmsg=%{u_err_msg}x]';
private function __construct($arrLogConfig)
{
$this->intLevel = $arrLogConfig['level'];
$this->bolAutoRotate = $arrLogConfig['auto_rotate'];
$this->strLogFile = $arrLogConfig['log_file'];
$this->strFormat = $arrLogConfig['format'];
$this->strFormatWF = $arrLogConfig['format_wf'];
}
/**
* @brief ODP环境下日志的前缀为AppName,非ODP环境需要配置指定前缀
*
* @return public static function
* @retval
* @see
* @note
* @author luhaixia
* @date 2012/07/31 17:10:32
**/
public static function getLogPrefix(){
if(defined('IS_ODP') && IS_ODP == true){
return Bd_AppEnv::getCurrApp();
}else{
if(defined('MODULE')){
return MODULE;
}else{
return 'unknow';
}
}
}
/**
* @brief 日志打印的根目录
*
* @return public static function
* @retval
* @see
* @note
* @author luhaixia
* @date 2012/07/31 17:15:59
**/
public static function getLogPath(){
if(defined('IS_ODP') && IS_ODP == true){
return LOG_PATH;
}else{
if(self::$strLogPath == null){
$ret = Bd_Conf::getConf('/log/log_path');
if(false !== $ret){
self::$strLogPath = $ret;
}else{
self::$strLogPath = './';
}
}
return self::$strLogPath;
}
}
/**
* @brief 日志库依赖的数据文件根目录
*
* @return public static function
* @retval
* @see
* @note
* @author luhaixia
* @date 2012/07/31 17:16:30
**/
public static function getDataPath(){
if(defined('IS_ODP') && IS_ODP == true){
return DATA_PATH;
}else{
if(self::$strDataPath == null){
$ret = Bd_Conf::getConf('/log/data_path');
if(false !== $ret){
self::$strDataPath = $ret;
}else{
self::$strDataPath = "./";
}
}
return self::$strDataPath;
}
}
/**
* @brief 是否打印omp日志
*
* @return public static function
* @retval
* @see
* @note
* @author luhaixia
* @date 2012/08/09 20:25:18
**/
public static function isOMP(){
if(self::$bolIsOmp == null){
$ret = Bd_Conf::getConf('/log/is_omp');
if(false !== $ret && $ret <= 2 && $ret >= 0){
self::$bolIsOmp = intval($ret);
}else{
self::$bolIsOmp = 0;
}
}
return self::$bolIsOmp;
}
// 获取指定App的log对象,默认为当前App
public static function getInstance($app = null)
{
if(empty($app))
{
$app = self::getLogPrefix();
}
if(empty(self::$arrInstance[$app]))
{
$g_log_conf = Bd_Conf::getConf('/log/');
$app_log_conf = Bd_Conf::getAppConf('log', $app);
// app配置优先
if(is_array($app_log_conf))
{
$g_log_conf = array_merge($g_log_conf, $app_log_conf);
}
// 生成路径
$logPath = self::getLogPath();
if($g_log_conf['use_sub_dir'] == "1")
{
if(!is_dir($logPath."/$app"))
{
@mkdir($logPath."/$app");
}
$log_file = $logPath."/$app/$app.log";
}
else
{
$log_file = $logPath."/$app.log";
}
//get log format
if (isset($g_log_conf['format'])) {
$format = $g_log_conf['format'];
} else {
$format = self::DEFAULT_FORMAT;
}
if (isset($g_log_conf['format_wf'])) {
$format_wf = $g_log_conf['format_wf'];
} else {
$format_wf = $format;
}
$log_conf = array(
'level' => intval($g_log_conf['level']),
'auto_rotate' => ($g_log_conf['auto_rotate'] == '1'),
'log_file' => $log_file,
'format' => $format,
'format_wf' => $format_wf,
);
self::$arrInstance[$app] = new Bd_Log($log_conf);
}
return self::$arrInstance[$app];
}
public static function debug($str, $errno = 0, $arrArgs = null, $depth = 0)
{
if(self::isOMP() == 0 || self::isOMP() == 1){
$ret = self::getInstance()->writeLog(self::LOG_LEVEL_DEBUG, $str, $errno, $arrArgs, $depth + 1, '.new', self::DEFAULT_FORMAT_STD);
}
if(self::isOMP() == 0 || self::isOMP() == 2){
$ret = self::getInstance()->writeLog(self::LOG_LEVEL_DEBUG, $str, $errno, $arrArgs, $depth + 1);
}
return $ret;
}
public static function trace($str, $errno = 0, $arrArgs = null, $depth = 0)
{
if(self::isOMP() == 0 || self::isOMP() == 1){
$ret = self::getInstance()->writeLog(self::LOG_LEVEL_TRACE, $str, $errno, $arrArgs, $depth + 1, '.new', self::DEFAULT_FORMAT_STD);
}
if(self::isOMP() == 0 || self::isOMP() == 2){
$ret = self::getInstance()->writeLog(self::LOG_LEVEL_TRACE, $str, $errno, $arrArgs, $depth + 1);
}
return $ret;
}
public static function notice($str, $errno = 0, $arrArgs = null, $depth = 0)
{
if(self::isOMP() == 0 || self::isOMP() == 1){
$ret = self::getInstance()->writeLog(self::LOG_LEVEL_NOTICE, $str, $errno, $arrArgs, $depth + 1, '.new', self::DEFAULT_FORMAT_STD);
}
if(self::isOMP() == 0 || self::isOMP() == 2){
$ret = self::getInstance()->writeLog(self::LOG_LEVEL_NOTICE, $str, $errno, $arrArgs, $depth + 1);
}
}
public static function warning($str, $errno = 0, $arrArgs = null, $depth = 0)
{
if(self::isOMP() == 0 || self::isOMP() == 1){
$ret = self::getInstance()->writeLog(self::LOG_LEVEL_WARNING, $str, $errno, $arrArgs, $depth + 1, '.new', self::DEFAULT_FORMAT_STD);
}
if(self::isOMP() == 0 || self::isOMP() == 2){
$ret = self::getInstance()->writeLog(self::LOG_LEVEL_WARNING, $str, $errno, $arrArgs, $depth + 1);
}
}
public static function fatal($str, $errno = 0, $arrArgs = null, $depth = 0)
{
if(self::isOMP() == 0 || self::isOMP() == 1){
$ret = self::getInstance()->writeLog(self::LOG_LEVEL_FATAL, $str, $errno, $arrArgs, $depth + 1, '.new', self::DEFAULT_FORMAT_STD);
}
if(self::isOMP() == 0 || self::isOMP() == 2){
$ret = self::getInstance()->writeLog(self::LOG_LEVEL_FATAL, $str, $errno, $arrArgs, $depth + 1);
}
}
public static function addNotice($key, $value)
{
$log = self::getInstance();
if(!isset($value)) {
$value = $key;
$key = '@';
}
$info = is_array($value) ? strtr(strtr(var_export($value, true),
array(" array (\n"=>'{', "array (\n"=>'{', ' => '=> ':',",\n"=> ',',)),
array('{ '=> '{', ":\n{"=>':{', ' ), ' => '},', '),' => '},', ',)'=>'}', ', '=>',',))
: $value;
$log->addNotice[$key] = $info;
}
// 生成logid
public static function genLogID()
{
if(defined('LOG_ID')){
return LOG_ID;
}
if(getenv('HTTP_X_BD_LOGID')){
define('LOG_ID', trim(getenv('HTTP_X_BD_LOGID')));
}elseif(isset($_REQUEST['logid'])){
define('LOG_ID', intval($_REQUEST['logid']));
}else{
$arr = gettimeofday();
$logId = ((($arr['sec']*100000 + $arr['usec']/10) & 0x7FFFFFFF) | 0x80000000);
define('LOG_ID', $logId);
}
return LOG_ID;
}
// 获取客户端ip
public static function getClientIp()
{
return Bd_Ip::getClientIp();
}
private function writeLog($intLevel, $str, $errno = 0, $arrArgs = null, $depth = 0, $filename_suffix = '', $log_format = null)
{
if( $intLevel > $this->intLevel || !isset(self::$arrLogLevels[$intLevel]) )
{
return;
}
//log file name
$strLogFile = $this->strLogFile;
if( ($intLevel & self::LOG_LEVEL_WARNING) || ($intLevel & self::LOG_LEVEL_FATAL) )
{
$strLogFile .= '.wf';
}
$strLogFile .= $filename_suffix;
//assign data required
$this->current_log_level = self::$arrLogLevels[$intLevel];
//build array for use as strargs
$_arr_args = false;
$_add_notice = false;
if (is_array($arrArgs) && count($arrArgs) > 0) {
$_arr_args = true;
}
if (!empty($this->addNotice)) {
$_add_notice = true;
}
if ($_arr_args && $_add_notice) { //both are defined, merge
$this->current_args = $arrArgs + $this->addNotice;
} else if (!$_arr_args && $_add_notice) { //only add notice
$this->current_args = $this->addNotice;
} else if ($_arr_args && !$_add_notice) { //only arr args
$this->current_args = $arrArgs;
} else { //empty
$this->current_args = array();
}
$this->current_err_no = $errno;
$this->current_err_msg = $str;
$trace = debug_backtrace();
$depth2 = $depth + 1;
if( $depth >= count($trace) )
{
$depth = count($trace) - 1;
$depth2 = $depth;
}
$this->current_file = isset( $trace[$depth]['file'] )
? $trace[$depth]['file'] : "" ;
$this->current_line = isset( $trace[$depth]['line'] )
? $trace[$depth]['line'] : "";
$this->current_function = isset( $trace[$depth2]['function'] )
? $trace[$depth2]['function'] : "";
$this->current_class = isset( $trace[$depth2]['class'] )
? $trace[$depth2]['class'] : "" ;
$this->current_function_param = isset( $trace[$depth2]['args'] )
? $trace[$depth2]['args'] : "";
self::$current_instance = $this;
//get the format
if ($log_format == null)
$format = $this->getFormat($intLevel);
else
$format = $log_format;
$str = $this->getLogString($format);
if($this->bolAutoRotate)
{
$strLogFile .= '.'.date('YmdH');
}
return file_put_contents($strLogFile, $str, FILE_APPEND);
}
// added support for self define format
private function getFormat($level) {
if ($level == self::LOG_LEVEL_FATAL || $level == self::LOG_LEVEL_WARNING) {
$fmtstr = $this->strFormatWF;
} else {
$fmtstr = $this->strFormat;
}
return $fmtstr;
}
public function getLogString($format) {
$md5val = md5($format);
$func = "_bd_log_$md5val";
if (function_exists($func)) {
return $func();
}
$dataPath = self::getDataPath();
$filename = $dataPath . '/log/'.$md5val.'.php';
if (!file_exists($filename)) {
$tmp_filename = $filename . '.' . posix_getpid() . '.' . rand();
if (!is_dir($dataPath . '/log')) {
@mkdir($dataPath . '/log');
}
file_put_contents($tmp_filename, $this->parseFormat($format));
rename($tmp_filename, $filename);
}
include_once($filename);
$str = $func();
return $str;
}
// parse format and generate code
public function parseFormat($format) {
$matches = array();
$regex = '/%(?:{([^}]*)})?(.)/';
preg_match_all($regex, $format, $matches);
$prelim = array();
$action = array();
$prelim_done = array();
$len = count($matches[0]);
for($i = 0; $i < $len; $i++) {
$code = $matches[2][$i];
$param = $matches[1][$i];
switch($code) {
case 'h':
$action[] = "(defined('CLIENT_IP')? CLIENT_IP : Bd_Log::getClientIp())";
break;
case 't':
$action[] = ($param == '')? "strftime('%y-%m-%d %H:%M:%S')" : "strftime(" . var_export($param, true) . ")";
break;
case 'i':
$key = 'HTTP_' . str_replace('-', '_', strtoupper($param));
$key = var_export($key, true);
$action[] = "(isset(\$_SERVER[$key])? \$_SERVER[$key] : '')";
break;
case 'a':
$action[] = "(defined('CLIENT_IP')? CLIENT_IP : Bd_Log::getClientIp())";
break;
case 'A':
$action[] = "(isset(\$_SERVER['SERVER_ADDR'])? \$_SERVER['SERVER_ADDR'] : '')";
break;
case 'C':
if ($param == '') {
$action[] = "(isset(\$_SERVER['HTTP_COOKIE'])? \$_SERVER['HTTP_COOKIE'] : '')";
} else {
$param = var_export($param, true);
$action[] = "(isset(\$_COOKIE[$param])? \$_COOKIE[$param] : '')";
}
break;
case 'D':
$action[] = "(defined('REQUEST_TIME_US')? (microtime(true) * 1000 - REQUEST_TIME_US/1000) : '')";
break;
case 'e':
$param = var_export($param, true);
$action[] = "((getenv($param) !== false)? getenv($param) : '')";
break;
case 'f':
$action[] = 'Bd_Log::$current_instance->current_file';
break;
case 'H':
$action[] = "(isset(\$_SERVER['SERVER_PROTOCOL'])? \$_SERVER['SERVER_PROTOCOL'] : '')";
break;
case 'm':
$action[] = "(isset(\$_SERVER['REQUEST_METHOD'])? \$_SERVER['REQUEST_METHOD'] : '')";
break;
case 'p':
$action[] = "(isset(\$_SERVER['SERVER_PORT'])? \$_SERVER['SERVER_PORT'] : '')";
break;
case 'q':
$action[] = "(isset(\$_SERVER['QUERY_STRING'])? \$_SERVER['QUERY_STRING'] : '')";
break;
case 'T':
switch($param) {
case 'ms':
$action[] = "(defined('REQUEST_TIME_US')? (microtime(true) * 1000 - REQUEST_TIME_US/1000) : '')";
break;
case 'us':
$action[] = "(defined('REQUEST_TIME_US')? (microtime(true) * 1000000 - REQUEST_TIME_US) : '')";
break;
default:
$action[] = "(defined('REQUEST_TIME_US')? (microtime(true) - REQUEST_TIME_US/1000000) : '')";
}
break;
case 'U':
$action[] = "(isset(\$_SERVER['REQUEST_URI'])? \$_SERVER['REQUEST_URI'] : '')";
break;
case 'v':
$action[] = "(isset(\$_SERVER['HOSTNAME'])? \$_SERVER['HOSTNAME'] : '')";
break;
case 'V':
$action[] = "(isset(\$_SERVER['HTTP_HOST'])? \$_SERVER['HTTP_HOST'] : '')";
break;
case 'L':
$action[] = 'Bd_Log::$current_instance->current_log_level';
break;
case 'N':
$action[] = 'Bd_Log::$current_instance->current_line';
break;
case 'E':
$action[] = 'Bd_Log::$current_instance->current_err_no';
break;
case 'l':
$action[] = "Bd_Log::genLogID()";
break;
case 'u':
if (!isset($prelim_done['user'])) {
$prelim[] = '$____user____ = Bd_Passport::getUserInfoFromCookie();';
$prelim_done['user'] = true;
}
$action[] = "((defined('CLIENT_IP') ? CLIENT_IP: Bd_Log::getClientIp()) . ' ' . \$____user____['uid'] . ' ' . \$____user____['uname'])";
break;
case 'S':
if ($param == '') {
$action[] = 'Bd_Log::$current_instance->get_str_args()';
} else {
$param_name = var_export($param, true);
if (!isset($prelim_done['S_'.$param_name])) {
$prelim[] =
"if (isset(Bd_Log::\$current_instance->current_args[$param_name])) {
\$____curargs____[$param_name] = Bd_Log::\$current_instance->current_args[$param_name];
unset(Bd_Log::\$current_instance->current_args[$param_name]);
} else \$____curargs____[$param_name] = '';";
$prelim_done['S_'.$param_name] = true;
}
$action[] = "\$____curargs____[$param_name]";
}
break;
case 'M':
$action[] = 'Bd_Log::$current_instance->current_err_msg';
break;
case 'x':
$need_urlencode = false;
if (substr($param, 0, 2) == 'u_') {
$need_urlencode = true;
$param = substr($param, 2);
}
switch($param) {
case 'log_level':
case 'line':
case 'class':
case 'function':
case 'err_no':
case 'err_msg':
$action[] = 'Bd_Log::$current_instance->current_'.$param;
break;
case 'log_id':
$action[] = "Bd_Log::genLogID()";
break;
case 'app':
$action[] = "Bd_Log::getLogPrefix()";
break;
case 'function_param':
$action[] = 'Bd_Log::flattenArgs(Bd_Log::$current_instance->current_function_param)';
break;
case 'argv':
$action[] = '(isset($GLOBALS["argv"])? Bd_Log::flattenArgs($GLOBALS["argv"]) : \'\')';
break;
case 'pid':
$action[] = 'posix_getpid()';
break;
case 'encoded_str_array':
$action[] = 'Bd_Log::$current_instance->get_str_args_std()';
break;
default:
$action[] = "''";
}
if ($need_urlencode) {
$action_len = count($action);
$action[$action_len-1] = 'rawurlencode(' . $action[$action_len-1] . ')';
}
break;
case '%':
$action[] = "'%'";
break;
default:
$action[] = "''";
}
}
$strformat = preg_split($regex, $format);
$code = var_export($strformat[0], true);
for($i = 1; $i < count($strformat); $i++) {
$code = $code . ' . ' . $action[$i-1] . ' . ' . var_export($strformat[$i], true);
}
$code .= ' . "\n"';
$pre = implode("\n", $prelim);
$cmt = "Used for app " . self::getLogPrefix() . "\n";
$cmt .= "Original format string: " . str_replace('*/', '* /', $format);
$md5val = md5($format);
$func = "_bd_log_$md5val";
$str = "<?php \n/*\n$cmt\n*/\nfunction $func() {\n$pre\nreturn $code;\n}";
return $str;
}
//helper functions for use in generated code
public static function flattenArgs($args) {
if (!is_array($args)) return '';
$str = array();
foreach($args as $a) {
$str[] = preg_replace('/[ \n\t]+/', " ", $a);
}
return implode(', ', $str);
}
public function get_str_args() {
$strArgs = '';
foreach($this->current_args as $k=>$v){
$strArgs .= ' '.$k.'['.$v.']';
}
return $strArgs;
}
//ORP Log Specification
public function get_str_args_std() {
$args = array();
foreach($this->current_args as $k=>$v){
$args[] = rawurlencode($k).'='.rawurlencode($v);
}
return implode(' ', $args);
}
}