关于Log 的一些东西

关于LOG,思考一下就个问题:

1. 为何有Log

2. Log要如何准确,明白的,分类别的记录。

3. 如何保证Log信息的安全

下面是StackOverflow 一些信息,记录有待整理

1. 关于Log的一些建议。

I‘m basing my response on the excellent response of Robert Kozak, even though I don‘t quite use my logging the same way

I use five types of log statements:

  • DEBUG
  • INFO
  • WARNING
  • ERROR
  • FATAL

DEBUG statements are statements which are useful when you are still writing an application, and when you need a complete understanding of what/where your execution flow is. You can use DEBUG statements to measure the queue in front of a lock, or check usernames of users logging in, or even the parameters for a certain SQL call that‘s been troubling. DEBUG is for statements which are not generally needed to be known.

INFO should be used whenever there is information which will be very useful if something goes wrong, but does not indicate that anything has gone wrong. If you use too many INFO statements, your logs will become bloated and unuseful, so be careful. Use INFO for any critical information which you will need on error, and it is no where near where the error will be throw.

Use WARN level if you have detected a recoverable, but still unexpected (at least a little expected, because you caught it). It indicates that your application MAY be in an unworkable state, but that you believe you can recover/continue on the current execution path.

ERROR warnings are for whenever you catch an unexpected exception. If you are recovering/retrying the current method, I‘d suggest using WARN. If you are canceling/bailing out, use the ERROR. Even if your program can continue, ERROR means that you were attempting to do something and were rejected, and are therefore moving on to other things.

FATAL is for use when you catch something at a level far beneath where it was thrown, and you essentially have no idea what‘s going on. It means you are not even attempting to continue execution, you are simply going to log every possible bit of information at your disposal and then try to exit gracefully. FATAL errors are infrequently used because generally if you catch an error, you have enough information to try and continue execution. But in the scenarios where corruption might occur if you try and continue, log a FATAL error, and then run away.



As for where you‘re logging to. I usually like to log to a ‘shared‘ folder on my app servers (be careful about permissioning so that they are not public) so that the logs are very easily accessible and they are always my first step for debugging. If possible, set it up so that any errors that are WARNING, ERROR, or FATAL are sent out by email so that you‘ll have ‘advanced‘ warning.

2. Log 不仅可以用文本,DB的形式存储,还可以发布到Web。可参考方案:Apache Chainsaw, log4net Dashboard

时间: 2024-10-25 10:42:01

关于Log 的一些东西的相关文章

一个c++给程序打log的单例模式类

开发过程中需要给程序打log. 所以照着网上写了个单例模式的log类 1 #ifndef MISCLOGWRITER_H_ 2 #define MISCLOGWRITER_H_ 3 4 #include <iostream> 5 #include <fstream> 6 #include <string> 7 #include <vector> 8 9 namespace miscfactory 10 { 11 class MiscLogWriter 12

利用 CocoaLumberjack 搭建自己的 Log 系统(转)

一直需要一个 Log 系统,可以将程序运行过程中打的 log 发送到自己服务器,方便之后数据分析或者除错.之前也尝试过找一些第三方服务,但看来看去,国内貌似没看到专门做这一块的,而国外看了下有 Loggly,似乎满足需求,但它要收费且日志保存时间太短.后来无意间看了下 Loggly 提供的 SDK 源代码,发现了CocoaLumberjack这个好东西,而 Loggly 其也不过就是在 CocoaLumberjack 上自定义了 Logger 和 Formatter 而已.自己做的话,也很简单.

利用 CocoaLumberjack 搭建自己的 Log 系统

先说下需求,我理想中的 Log 系统需要: 可以设定 Log 等级 可以积攒到一定量的 log 后,一次性发送给服务器,绝对不能打一个 Log 就发一次 可以一定时间后,将未发送的 log 发送到服务器 可以在 App 切入后台时将未发送的 log 发送到服务器 其他一些需求,比如可以远程设定发送 log 的等级阀值,还有阀值的有效期等,和本文无关就不写了. 开始动手前,先了解下 CocoaLumberjack 是什么: CocoaLumberjack 最早是由 Robbie Hanson 开发

js console.log 打印 对像 数组 详解

console.log是什么东西,其实就是一个打印js数组和对像的函数而已,就像是php的print_r,var_dump.console.log这个函数本身没什么好说的,这篇博客告诉大家怎么去用这个函数.在说这个函数之前,我想大家用的最多查看js输出,是alert吧,但是alert,只能弹string或者是int的 一,测试文件test.html <html xmlns="http://www.w3.org/1999/xhtml"> <head> <me

Linux 之HA集群酌置

HA(高可用 High avaiilable)集群 Web1 提供服务,如果1主宕机了,2备就可以马上启用,这样有用户这端没有任何影响. 在架构的时候要配置一条心跳线来传递信息.流动IP 也是就是VIP,是主从对外共同的IP. [[email protected] ~]# iptables -F [[email protected] ~]# getenforce Disabled [[email protected] ~]# vim /etc/hosts #在主上编译上 10.72.4.21 L

HTML5之canvas

canvas的创建,canvas图片的绘制及图片的封装,矩形,矩形边框,圆,线的绘制. JavaScript代码如下:main.js /** * Created by zengkm on 15-9-1. */ //初始化 var myworld=function(){ console.log("输出一些东西"); var canvas = document.getElementById("my_canvas"); canvas.width="800&quo

毕业工作的一些事

关于方向 电子专业,原想当嵌入式工程师的,毕业去搞通信协议栈,搞搞网络编程,再也接触不了硬件.其实说起来也不是什么重要的事,只是觉得人生的进程其实难以预料.... 做什么,就学什么呗,做技术的心还是依然嘛.想换方向的话,得吃点苦头,只要愿意学习,换方向其实没那么难. 工作后的启示 说的是技术方面.  首先是日志系统.在校写程序没加过日志系统,工作的代码大把log,这东西写时觉得麻烦, 出bug时就觉得珍贵.(此处mark一下,以后补一篇有关log的随笔). 其次是轮子的应用,学校里不知轮子的概念

koa中使用的模块

今天开始学习目前呼声很高的koa模块,不过目前使用koa还是要用--harmony-generator标识,即便在刚出的nodejs 12上也是如此~,io.js倒是不需要,去年的nodejs和iojs分派不知道会不会带来什么大的变革,不过既然koa目前呼声这么高,肯定有他值得学习的地方,所以先搞着吧,多学点总比不学好. 这篇文章把koa依赖的模块列举一下,以后再自己学习koa的过程中减少一点查询的过程,也算是nodejs打基础的第一步吧~ accepts Higher level conten

BOM以及定时器

一.BOM 1.操作浏览器的一些方法 (浏览器对象模型) 2.window是is中的顶级变量,是一个全局的变量,所有人都可以访问到它,基本 的方法和属性 (document,alert,console.log,这些东西都是window的),由于他太常用可以省略不写,全局变 量和全局函数是window的一个属性和方法 3.window.onload=function(){ [入口函数] 事件会在页面加载完成后,以及页面中的所有图片都加载完才开始执行 } img标签会加载,而图片不会被加载,是为了优