本文整理汇总了C++中LOG_PRI函数的典型用法代码示例。如果您正苦于以下问题:C++ LOG_PRI函数的具体用法?C++ LOG_PRI怎么用?C++ LOG_PRI使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LOG_PRI函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: autoLock
status_t ChromiumHTTPDataSource::reconnectAtOffset(off64_t offset) {
Mutex::Autolock autoLock(mLock);
if (mURI.empty()) {
return INVALID_OPERATION;
}
LOG_PRI(ANDROID_LOG_INFO, LOG_TAG, "Reconnecting...");
status_t err = connect_l(mURI.c_str(), &mHeaders, offset);
if (err != OK) {
LOG_PRI(ANDROID_LOG_INFO, LOG_TAG, "Reconnect failed w/ err 0x%08x", err);
}
return err;
}
示例2: vsyslog
void vsyslog(int prio, const char *format, va_list ap)
{
char buf[BUFLEN];
int len;
int fd;
if (__syslog_fd == -1)
openlog(NULL, 0, 0);
buf[0] = '<';
buf[1] = LOG_PRI(prio) + '0';
buf[2] = '>';
len = 3;
if (syslog_flags & LOG_PID)
len += sprintf(buf + 3, "%s[%u]: ", id, getpid());
else if (*id)
len += sprintf(buf + 3, "%s: ", id);
len += vsnprintf(buf + len, BUFLEN - len, format, ap);
if (len > BUFLEN - 1)
len = BUFLEN - 1;
if (buf[len - 1] != '\n')
buf[len++] = '\n';
fd = __syslog_fd;
if (fd == -1)
fd = 2; /* Failed to open log, write to stderr */
write(fd, buf, len);
if (syslog_flags & LOG_PERROR)
_fwrite(buf + 3, len - 3, stderr);
}
示例3: logging_level_prefix
const char *
logging_level_prefix(int priority)
{
/*
* Using LOG_PRI probably isn't standard, but I don't know a more
* portable way to determine the log level from priority, since
* it's perfectly legal for the user to OR the level with the
* facility when forming priority.
*/
switch (LOG_PRI(priority)) {
case LOG_DEBUG:
return "DEBUG: ";
case LOG_INFO:
return "INFO: ";
case LOG_NOTICE:
return "NOTICE: ";
case LOG_WARNING:
return "WARNING: ";
case LOG_ERR:
return "ERR: ";
case LOG_CRIT:
return "CRIT: ";
case LOG_ALERT:
return "ALERT: ";
case LOG_EMERG:
return "EMERG: ";
default:
return "UNKNOWN: ";
}
}
示例4: vsyslog
/******************************************************************************
* vsyslog
*
* Generate a log message using FMT and using arguments pointed to by AP.
*/
void vsyslog( int pri, char* fmt, va_list ap )
{
static char *month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
SYSTEMTIME stm;
int len;
char *p;
if( !(LOG_MASK( LOG_PRI( pri )) & log_mask) )
return;
openlog( NULL, 0, pri & LOG_FACMASK );
if( !initialized )
return;
if( !(pri & LOG_FACMASK) )
pri |= syslog_facility;
GetLocalTime( &stm );
len = sprintf( datagramm, "<%d>%s %2d %02d:%02d:%02d %s %s%s: ",
pri,
month[ stm.wMonth - 1 ], stm.wDay, stm.wHour, stm.wMinute, stm.wSecond,
local_hostname, syslog_ident? syslog_ident : "", str_pid );
vsnprintf( datagramm + len, datagramm_size - len, fmt, ap );
p = strchr( datagramm, '\n' );
if( p )
*p = 0;
p = strchr( datagramm, '\r' );
if( p )
*p = 0;
sendto( sock, datagramm, strlen(datagramm), 0, (SOCKADDR*) &sa_logger, sizeof(SOCKADDR_IN) );
}
示例5: __syslog_chk
void __syslog_chk(int priority, int flag, const char *message, ...)
{
LOCK(lock);
va_list ap;
va_start(ap, message);
char timebuf[16];
time_t now;
struct tm tm;
char buf[256];
int pid;
int l, l2;
if (!(priority & LOG_FACMASK)) priority |= log_facility;
now = time(NULL);
gmtime_r(&now, &tm);
strftime(timebuf, sizeof timebuf, "%b %e %T", &tm);
pid = (log_opt & LOG_PID) ? getpid() : 0;
l = snprintf(buf, sizeof buf, "<%d>%s %s%s%.0d%s: ",
priority, timebuf, log_ident, "["+!pid, pid, "]"+!pid);
l2 = vsnprintf(buf+l, sizeof buf - l, message, ap);
if (l2 >= 0) {
if (l2 >= sizeof buf - l) l = sizeof buf - 1;
else l += l2;
if (buf[l-1] != '\n') buf[l++] = '\n';
fwrite(buf, 1, l, LOG_PRI(priority) >= LOG_ERR ? stderr : stdout);
}
va_end(ap);
UNLOCK(lock);
}
示例6: server_forward_kmsg
void server_forward_kmsg(
Server *s,
int priority,
const char *identifier,
const char *message,
struct ucred *ucred) {
struct iovec iovec[5];
char header_priority[6], header_pid[16];
int n = 0;
char *ident_buf = NULL;
assert(s);
assert(priority >= 0);
assert(priority <= 999);
assert(message);
if (_unlikely_(LOG_PRI(priority) > s->max_level_kmsg))
return;
if (_unlikely_(s->dev_kmsg_fd < 0))
return;
/* Never allow messages with kernel facility to be written to
* kmsg, regardless where the data comes from. */
priority = syslog_fixup_facility(priority);
/* First: priority field */
snprintf(header_priority, sizeof(header_priority), "<%i>", priority);
char_array_0(header_priority);
IOVEC_SET_STRING(iovec[n++], header_priority);
/* Second: identifier and PID */
if (ucred) {
if (!identifier) {
get_process_comm(ucred->pid, &ident_buf);
identifier = ident_buf;
}
snprintf(header_pid, sizeof(header_pid), "[%lu]: ", (unsigned long) ucred->pid);
char_array_0(header_pid);
if (identifier)
IOVEC_SET_STRING(iovec[n++], identifier);
IOVEC_SET_STRING(iovec[n++], header_pid);
} else if (identifier) {
IOVEC_SET_STRING(iovec[n++], identifier);
IOVEC_SET_STRING(iovec[n++], ": ");
}
/* Fourth: message */
IOVEC_SET_STRING(iovec[n++], message);
IOVEC_SET_STRING(iovec[n++], "\n");
if (writev(s->dev_kmsg_fd, iovec, n) < 0)
log_debug("Failed to write to /dev/kmsg for logging: %m");
free(ident_buf);
}
示例7: disconnect_l
status_t ChromiumHTTPDataSource::connect_l(
const char *uri,
const KeyedVector<String8, String8> *headers,
off64_t offset) {
if (mState != DISCONNECTED) {
disconnect_l();
}
LOG_PRI(ANDROID_LOG_INFO, LOG_TAG,
"connect to <URL suppressed> @%lld", offset);
mURI = uri;
mContentType = String8("application/octet-stream");
if (headers != NULL) {
mHeaders = *headers;
} else {
mHeaders.clear();
}
mState = CONNECTING;
mContentSize = -1;
mCurrentOffset = offset;
mDelegate->initiateConnection(mURI.c_str(), &mHeaders, offset);
while (mState == CONNECTING || mState == DISCONNECTING) {
mCondition.wait(mLock);
}
return mState == CONNECTED ? OK : mIOResult;
}
示例8: enqMsg
/* enqueue the the kernel message into the message queue.
* The provided msg string is not freed - thus must be done
* by the caller.
* rgerhards, 2008-04-12
*/
static rsRetVal
enqMsg(uchar *msg, uchar* pszTag, int iFacility, int iSeverity)
{
DEFiRet;
msg_t *pMsg;
assert(msg != NULL);
assert(pszTag != NULL);
CHKiRet(msgConstruct(&pMsg));
MsgSetFlowControlType(pMsg, eFLOWCTL_LIGHT_DELAY);
MsgSetInputName(pMsg, pInputName);
MsgSetRawMsgWOSize(pMsg, (char*)msg);
MsgSetMSGoffs(pMsg, 0); /* we do not have a header... */
MsgSetRcvFrom(pMsg, glbl.GetLocalHostNameProp());
MsgSetRcvFromIP(pMsg, pLocalHostIP);
MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName()));
MsgSetTAG(pMsg, pszTag, ustrlen(pszTag));
pMsg->iFacility = LOG_FAC(iFacility);
pMsg->iSeverity = LOG_PRI(iSeverity);
CHKiRet(submitMsg(pMsg));
finalize_it:
RETiRet;
}
示例9: parse_fac_prio_20
static void parse_fac_prio_20(int pri, char *res20)
{
CODE *c_pri, *c_fac;
if (pri != 0) {
c_fac = facilitynames;
while (c_fac->c_name) {
if (c_fac->c_val != (LOG_FAC(pri) << 3)) {
c_fac++; continue;
}
/* facility is found, look for prio */
c_pri = prioritynames;
while (c_pri->c_name) {
if (c_pri->c_val != LOG_PRI(pri)) {
c_pri++; continue;
}
snprintf(res20, 20, "%s.%s",
c_fac->c_name, c_pri->c_name);
return;
}
/* prio not found, bail out */
break;
}
snprintf(res20, 20, "<%d>", pri);
}
}
示例10: log_internalv
int log_internalv(
int level,
int error,
const char *file,
int line,
const char *func,
const char *format,
va_list ap) {
PROTECT_ERRNO;
char buffer[LINE_MAX];
if (error < 0)
error = -error;
if (_likely_(LOG_PRI(level) > log_max_level))
return -error;
/* Make sure that %m maps to the specified error */
if (error != 0)
errno = error;
vsnprintf(buffer, sizeof(buffer), format, ap);
return log_dispatch(level, error, file, line, func, NULL, NULL, buffer);
}
示例11: log_object_internalv
int log_object_internalv(
int level,
int error,
const char *file,
int line,
const char *func,
const char *object_field,
const char *object,
const char *format,
va_list ap) {
PROTECT_ERRNO;
char *buffer, *b;
size_t l;
if (error < 0)
error = -error;
if (_likely_(LOG_PRI(level) > log_max_level))
return -error;
/* Make sure that %m maps to the specified error */
if (error != 0)
errno = error;
/* Prepend the object name before the message */
if (object) {
size_t n;
n = strlen(object);
l = n + 2 + LINE_MAX;
buffer = newa(char, l);
b = stpcpy(stpcpy(buffer, object), ": ");
} else {
示例12: vlog_msgf
/**
* Log a message to a filedescriptor.
* @param fd File descritpor where the log will be written to
* @param lf Logging priority (equal to syslog)
* @param fmt Format string
* @param ap Variable parameter list
* @param with_errno Flag if errno should be printed too
*/
void
vlog_msgf(int fd, int lf, const char* fmt, va_list ap, int with_errno)
{
int level = LOG_PRI(lf);
char buf[1024];
if (level_ < level)
{
return;
}
if (fd > -1)
{
dprintf(fd, "%s;", flty_[level]);
vdprintf(fd, fmt, ap);
if (with_errno)
{
dprintf(fd, " (%s)", strerror(errno));
}
dprintf(fd, "\n");
}
else
{
vsnprintf(buf, sizeof(buf), fmt, ap);
syslog(level | LOG_DAEMON, "%s", buf);
}
}
示例13: write_to_console
static int write_to_console(
int level,
int error,
const char *file,
int line,
const char *func,
const char *object_field,
const char *object,
const char *buffer) {
char location[256], prefix[1 + DECIMAL_STR_MAX(int) + 2];
struct iovec iovec[6] = {};
unsigned n = 0;
bool highlight;
if (console_fd < 0)
return 0;
if (log_target == LOG_TARGET_CONSOLE_PREFIXED) {
sprintf(prefix, "<%i>", level);
IOVEC_SET_STRING(iovec[n++], prefix);
}
highlight = LOG_PRI(level) <= LOG_ERR && show_color;
if (show_location) {
snprintf(location, sizeof(location), "(%s:%i) ", file, line);
IOVEC_SET_STRING(iovec[n++], location);
}
if (highlight)
IOVEC_SET_STRING(iovec[n++], ANSI_HIGHLIGHT_RED);
IOVEC_SET_STRING(iovec[n++], buffer);
if (highlight)
IOVEC_SET_STRING(iovec[n++], ANSI_NORMAL);
IOVEC_SET_STRING(iovec[n++], "\n");
if (writev(console_fd, iovec, n) < 0) {
if (errno == EIO && getpid() == 1) {
/* If somebody tried to kick us from our
* console tty (via vhangup() or suchlike),
* try to reconnect */
log_close_console();
log_open_console();
if (console_fd < 0)
return 0;
if (writev(console_fd, iovec, n) < 0)
return -errno;
} else
return -errno;
}
return 1;
}
示例14: autoLock
ssize_t ChromiumHTTPDataSource::readAt(off64_t offset, void *data, size_t size) {
Mutex::Autolock autoLock(mLock);
if (mState != CONNECTED) {
return INVALID_OPERATION;
}
#if 0
char value[PROPERTY_VALUE_MAX];
if (property_get("media.stagefright.disable-net", value, 0)
&& (!strcasecmp(value, "true") || !strcmp(value, "1"))) {
LOG_PRI(ANDROID_LOG_INFO, LOG_TAG, "Simulating that the network is down.");
disconnect_l();
return ERROR_IO;
}
#endif
if (offset != mCurrentOffset) {
AString tmp = mURI;
KeyedVector<String8, String8> tmpHeaders = mHeaders;
disconnect_l();
status_t err = connect_l(tmp.c_str(), &tmpHeaders, offset);
if (err != OK) {
LCHLOGD1("err = %d", (int ) err);
return err;
}
}
mState = READING;
int64_t startTimeUs = ALooper::GetNowUs();
mDelegate->initiateRead(data, size);
while (mState == READING) {
mCondition.wait(mLock);
}
if (mIOResult < OK) {
return mIOResult;
}
if (mState == CONNECTED) {
int64_t delayUs = ALooper::GetNowUs() - startTimeUs;
// The read operation was successful, mIOResult contains
// the number of bytes read.
addBandwidthMeasurement(mIOResult, delayUs);
mCurrentOffset += mIOResult;
return mIOResult;
}
return ERROR_IO;
}
示例15: server_forward_kmsg
void server_forward_kmsg(
Server *s,
int priority,
const char *identifier,
const char *message,
const struct ucred *ucred) {
_cleanup_free_ char *ident_buf = NULL;
struct iovec iovec[5];
char header_priority[DECIMAL_STR_MAX(priority) + 3],
header_pid[STRLEN("[]: ") + DECIMAL_STR_MAX(pid_t) + 1];
int n = 0;
assert(s);
assert(priority >= 0);
assert(priority <= 999);
assert(message);
if (_unlikely_(LOG_PRI(priority) > s->max_level_kmsg))
return;
if (_unlikely_(s->dev_kmsg_fd < 0))
return;
/* Never allow messages with kernel facility to be written to
* kmsg, regardless where the data comes from. */
priority = syslog_fixup_facility(priority);
/* First: priority field */
xsprintf(header_priority, "<%i>", priority);
iovec[n++] = IOVEC_MAKE_STRING(header_priority);
/* Second: identifier and PID */
if (ucred) {
if (!identifier) {
get_process_comm(ucred->pid, &ident_buf);
identifier = ident_buf;
}
xsprintf(header_pid, "["PID_FMT"]: ", ucred->pid);
if (identifier)
iovec[n++] = IOVEC_MAKE_STRING(identifier);
iovec[n++] = IOVEC_MAKE_STRING(header_pid);
} else if (identifier) {
iovec[n++] = IOVEC_MAKE_STRING(identifier);
iovec[n++] = IOVEC_MAKE_STRING(": ");
}
/* Fourth: message */
iovec[n++] = IOVEC_MAKE_STRING(message);
iovec[n++] = IOVEC_MAKE_STRING("\n");
if (writev(s->dev_kmsg_fd, iovec, n) < 0)
log_debug_errno(errno, "Failed to write to /dev/kmsg for logging: %m");
}