perl的Sys::Syslog模块(openlog,syslog,closelog函数,setlogsock)-自定义日志

http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=30572348&id=5603558

自定义日志模块(Sys::Syslog)

1、语法:
use Sys::Syslog;                          # all except setlogsock(), or:
use Sys::Syslog qw(:DEFAULT setlogsock);  # default set, plus setlogsock()增强版
use Sys::Syslog qw(:standard :macros);    # standard functions, plus macros

2、setlogsock使用
     setlogsock($sock_type)
     setlogsock($sock_type, $stream_location)
           ·   "native" - use the native C functions from your syslog(3) library (added in "Sys::Syslog" 0.15).
           ·   "eventlog" - send messages to the Win32 events logger (Win32 only; added in "Sys::Syslog" 0.19).
           ·   "tcp" - connect to a TCP socket, on the "syslog/tcp" or "syslogng/tcp" service.
           ·   "udp" - connect to a UDP socket, on the "syslog/udp" service.
           ·   "inet" - connect to an INET socket, either TCP or UDP, tried in that order.
           ·   "unix" - connect to a UNIX domain socket (in some systems a character special device).  The name of that socket is
               the second parameter or, if you omit the second parameter, the value returned by the "_PATH_LOG" macro (if your
               system defines it), or /dev/log or /dev/conslog, whatever is writable.
           ·   "stream" - connect to the stream indicated by the pathname provided as the optional second parameter, or, if
               omitted, to /dev/conslog.  For example Solaris and IRIX system may prefer "stream" instead of "unix".
           ·   "pipe" - connect to the named pipe indicated by the pathname provided as the optional second parameter, or, if
               omitted, to the value returned by the "_PATH_LOG" macro (if your system defines it), or /dev/log (added in
               "Sys::Syslog" 0.21).
           ·   "console" - send messages directly to the console, as for the "cons" option of "openlog()".

3、函数:
3.1openlog函数
  openlog($ident, $logopt, $facility;)  定义日志内容     
          $ident //每一个日志信息前均会附加$ident
          $logopt //选项
          $facility // 类型

logopt选项:
        ·   "cons" - This option is ignored, since the failover mechanism will drop down to the console automatically if all other media fail.
        ·   "ndelay" - Open the connection immediately (normally, the connection is opened when the first message is logged).
        ·   "nofatal" - When set to true, "openlog()" and "syslog()" will only emit warnings instead of dying if theconnection to the syslog can't be established.
        ·   "nowait" - Don't wait for child processes that may have been created while logging the message.  (The GNU C library does not create a child process, so this option has no effect on Linux.)
        ·   "perror" - Write the message to standard error output as well to the system log.
        ·   "pid" - Include PID with each message.

facility类型:
      auth            用户认证
      authpriv        有特权的用户认证
      cron             cron守护进程
      daemon          各种系统守护进程
      ftp              ftp守护进程
      kern             内核消息
      local0-local7   保留用于本地用法
      lpr               打印机
      mail            邮件
      news            新闻
      syslog          内部syslog
      uucp            uucp系统
      user            各种用户程序来的消息

3.2syslog函数
  syslog($priority, $message)
  syslog($priority, $format, @args)
  syslog可定义优先级
  $priority can specify a level, or a level and a facility.

  *先用openlog()定义格式,syslog()定义内容 //use "openlog()" before using "syslog()"

3.3closelog()
        Closes the log file and returns true on success.

具体例子:
setlogsock(["unix", "udp", "native", "tcp"]);  #通过unix,udp,tcp socket连接LOG  
my $identity = "czw-syslog";
my @options = ('cons','pid');
my $facility = "local5";
openlog($identity,\@options,$facility);  #定义了格式等

syslog('info', "message");

-----------------------------

$facility="local0";
openlog($identity,\@options,$facility);
#syslog 优先级:  emerg alert crit err warning notice info debug
syslog('err',$message);

===================================

perl的Sys::Syslog模块(openlog,syslog,closelog函数,setlogsock)-自定义日志的更多相关文章

  1. sys,os,模块-正则表达式

    # *__conding:utf-8__* """"我是注释""" sys,os模块 import sysimport os pr ...

  2. day2_python的数据类型,sys,os模块,编码解码,列表,字典

    今天主要了解了python的数据类型,sys,os模块,编码解码,列表,字典 1.数据类型:int(python3没有长整型)文本总是Unicode,str表示二进制用byte类表示布尔型:True( ...

  3. Perl 学习笔记-模块

    1.Perl模块介绍 2个来源, 一个是随Perl发行版本一同打包, 只要安装了Perl就可以使用;  另一种是需要从CPAN上下载,自己安装.   寻找模块之前, 先检查系统上是否已经安装过了,   ...

  4. man syslog | col -b > syslog.txt

    linux man手册导出,解决man乱码 man syslog | col -b > syslog.txt

  5. time | sys | os 模块,递归删除文件,项目分析

    一,复习 ''' 1.跨文件夹导包 - 不用考虑包的情况下直接导入文件夹(包)下的具体模块 2.__name__: py自执行 '__main__' | py被导入执行 '模块名' 3.包:一系列模块 ...

  6. python模块知识二 random -- 随机模块、序列化 、os模块、sys -- 系统模块

    4.random -- 随机模块 a-z:97 ~ 122 A-Z :65 ~ 90 import random #浮点数 print(random.random())#0~1,不可指定 print( ...

  7. os 和 sys 的模块使用方法和模块

    os  的模块  方法 os.remove()删除文件 os.rename()重命名文件 os.walk()生成目录树下的所有文件名 os.chdir()改变目录 os.mkdir/maked ...

  8. python第二十课——math模块中常用的函数

    属性: e:自然数 pi:圆周率 函数: ceil():向上取整 floor():向下取整 sqrt():开平方根 radians():角度转弧度 degrees():弧度转角度 import mat ...

  9. Python:包、模块、类、函数的调用

    一.关系 包一般指文件夹或者安装包(安装包一般也是压缩后的文件夹),里面包含多个.py文件(必须有一个__init__.py文件),一般也含有多个子包(或子文件夹): 一般一个.py文件就是一个模块, ...

随机推荐

  1. 亚马逊VPS

    添加用户: 第一步 注册亚马逊云(已注册直接进入第二步)1.开始前需要准备好:有外币支付功能的信用卡一张(注册需要,不扣钱).Email地址.电话(手机更方便一些)2.访问 https://amazo ...

  2. Struts2的动态方法,及result跳转方式,全局结果以及默认的action的配置

    Action动态方法的调用 首先我们需要在struts.xml中去配置一个常量值如下 那么去哪找呢?找到Struts-core.jar并打开 method属性 <action name=&quo ...

  3. Hadoop(17)-MapReduce框架原理-MapReduce流程,Shuffle机制,Partition分区

    MapReduce工作流程 1.准备待处理文件 2.job提交前生成一个处理规划 3.将切片信息job.split,配置信息job.xml和我们自己写的jar包交给yarn 4.yarn根据切片规划计 ...

  4. 转载:小白使用eclipse提交到GitHub (详细步骤)

    本篇文章只是备忘,以防电脑重装找不到记录 教程:https://blog.csdn.net/bendanany/article/details/78891804

  5. 003---设计首页index页面

    在项目的urls.py文件添加一条url from django.contrib import admin from django.urls import path, re_path from app ...

  6. HDU暑假多校第八场G-Card Game

    一.题意 给出N个卡牌,卡牌的正反两面具有两个数字,取值范围为[1,2*n],给出若干个默认正面向上的卡牌,求最小反转多少张卡牌可以使得,每张卡牌朝上的面上都有一个不同的数字,同时满足最小反转次数的反 ...

  7. 分支push不上去的问题

    还原一下现场,我在自己的项目里面,从master里面checkout的一个分支,当我在我这个分支里面进行 push代码的操作,我突然发现我的代码不能执行push的操作,如图 这个原因是由于远端的仓库没 ...

  8. WPF中InkCanvas(墨水面板)用法

    原文:WPF中InkCanvas(墨水面板)用法   WPF中InkCanvas(墨水面板)用法                                                    ...

  9. 1 opencv2.4 + vs2013

    http://blog.csdn.net/poem_qianmo/article/details/19809337 1.安装vs2013 2.安装opencv2.4 下载地址:https://sour ...

  10. P1189 SEARCH(逃跑的拉尔夫)

    P1189 SEARCH 题目描述 年轻的拉尔夫开玩笑地从一个小镇上偷走了一辆车,但他没想到的是那辆车属于警察局,并且车上装有用于发射车子移动路线的装置. 那个装置太旧了,以至于只能发射关于那辆车的移 ...