{"id":17769738,"url":"https://github.com/jstzwj/rapidlogger","last_synced_at":"2025-04-01T14:24:07.515Z","repository":{"id":100608961,"uuid":"88404236","full_name":"jstzwj/RapidLogger","owner":"jstzwj","description":"A fast logger for C++ ","archived":false,"fork":false,"pushed_at":"2017-04-26T04:05:29.000Z","size":466,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-07T09:12:27.454Z","etag":null,"topics":["async","cpp","logger"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jstzwj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-16T09:44:53.000Z","updated_at":"2017-04-24T14:00:44.000Z","dependencies_parsed_at":"2023-03-05T21:45:57.296Z","dependency_job_id":null,"html_url":"https://github.com/jstzwj/RapidLogger","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jstzwj%2FRapidLogger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jstzwj%2FRapidLogger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jstzwj%2FRapidLogger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jstzwj%2FRapidLogger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jstzwj","download_url":"https://codeload.github.com/jstzwj/RapidLogger/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246652463,"owners_count":20812150,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","cpp","logger"],"created_at":"2024-10-26T21:18:53.897Z","updated_at":"2025-04-01T14:24:07.497Z","avatar_url":"https://github.com/jstzwj.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RapidLogger\nA fast logger for C++ \n\n# Introduction\nThe library was inspired by RapidJSON and log4j.\nRapidLogger is small and fast.\n\n# Compatibility\nThese compilers which have been tested are shown in the following list.\n\n* Visual C++ 2015 on Windows (32/64-bit)\n\n# How to use\nThe RapidLogger library is a header-only library.Just copy the folder in your project.\n\n# Usage\n\n## Log 'hello world'\nUse RapidLogger in two lines.\n\n~~~cpp\n#include\"rapidlogger.h\"\nusing namespace rapidlogger;\nint main(int argc,char **argv)\n{\n  //Init a singleton logger\n  \tinitRapidLogger(argv[0], FileAppender(\"mylog.log\"));\n  //Put a log\n\tinfo_out_d\u003c\u003c \"Hello world 0123456789 abcdefghijklmnopqrstuvwxyz\"\u003c\u003ci;\n\treturn 0;\n}\n~~~\n\n## Init logger\nBefore using a logger, it shall be inited by function 'initRapidLogger'.\n~~~cpp\n initRapidLogger(argv[0]);\n~~~\nThe first paramater of 'initRapidLogger' is the name of logger. The function will call 'setName' and 'start'.\nAnother thread will be created to get logs from message queue, which will be written to appenders.\n\n\n## Get a logger \n\nTo get the logger use rapidlogger::getLogger() function:\n~~~cpp\n Logger \u0026 getLogger()\n~~~\n\n\n## Close a logger\nIf a logger will not be used, you can close it by call 'closeRapidLogger'\n~~~cpp\n void closeRapidLogger()\n~~~\n\n## Some settings of logger\n\nMost settings can only modified when the logger is closed. However, I am considering to make it possible to change settings when logger is running in the future versions.\n\n### Set name\n\n~~~cpp\n void setName(const char * name)\n~~~\nThe name can be used in log layout.\n\n### Set appender\n\n~~~cpp\n template\u003cclass T\u003e void addAppender(const T\u0026 app);\n\n void removeLastAppender();\n\n void clearAppender();\n~~~\n### Set layout\n~~~cpp\n void setLayout(const LogLayout\u0026 _layout);\n~~~\n\n### Set filter\n~~~cpp\n void setFilter(const LogFilter\u0026 _filter);\n~~~\n\n## Output logs\n\n~~~cpp\n logOff_d(msg)\n logFatal_d(msg)\n logError_d(msg)\n logWarn_d(msg)\n logInfo_d(msg)\n logDebug_d(msg)\n logAll_d(msg)\n logCustomer_d(msg,level)\n~~~\n\n\n## C++ stream style logs output\n\n~~~cpp\n off_out_d\n fatal_out_d\n error_out_d\n warn_out_d\n info_out_d\n debug_out_d\n all_out_d\n custom_out_d(level)\n~~~\n\nTake warning for example.\n~~~cpp\n warn_out_d\u003c\u003c\"This is a warning.\";\n~~~\n\n## About log layout\n\nThe LogLayout class\n%m Output the message.\n%p Output the log level, such as WARN, FATAL.\n%r Put the microsecond from the application initialization.\n%t Put the thread id.\n%n Print a newline character. \"\\r\\n\" under Windows. \"\\n\" under Unix.\n%d Print the log time. Default format is \"%Y-%m-%d %H:%M:%S.%SSS\". The format can be defined by user. %d{%Y %m %d %H:%M:%S,%SSS}. It will output \"2002 10 18 22:10:28,921\".\n%l Print the log location in the source including function name, thread id and line number. For example, main(TestLog.cpp:10).\n\n## About appenders\n* ConsoleAppender\n* FileAppender\n* DailyRollingFileAppender\n* RollingFileAppender\n\n\n\n## About log level\nBuilt-in level\n~~~cpp\n#define MAXLEVEL 2147483647\n#define MINLEVEL -2147483647\nenum LevelID\n{\n\tOFF=2147483647,\n\tFATAL=50000,\n\tERROR=40000,\n\tWARN=30000,\n\tINFO=20000,\n\tDEBUG=10000,\n\tALL=-2147483647,\n\tCUSTOMER=20050\n};\n\n#define LEVEL_OFF OffLevel()\n#define LEVEL_FATAL FatalLevel()\n#define LEVEL_ERROR ErrorLevel()\n#define LEVEL_WARN WarnLevel()\n#define LEVEL_INFO InfoLevel()\n#define LEVEL_DEBUG DebugLevel()\n#define LEVEL_ALL AllLevel()\n#define LEVEL_CUSTOM CustomerLevel()\n\n~~~\n\n\n\n## About filter\n\nYou can set a level range for the logs you want.\n~~~cpp\n\nLogFilter();\t//MINLEVEL to MAXLEVEL\nLogFilter(int _start);\t//start to MAXLEVEL including start\nLogFilter(int _start,int _finish);\t//start to finish including start and finish\n\n~~~\n\n\n## Conditional logging macros\n~~~cpp\n/*\nLogger will print a log when condition is true\n*/\nLOG_IF(errlog, LEVEL_INFO,condition) \u003c\u003c \"Hello 0123456789 abcdefghijklmnopqrstuvwxyz\" \u003c\u003c i;\n\n\n~~~\n\n\n# Advanced usage\n\n## Multiple loggers\n~~~cpp\n//Init a singleton logger which instance id is 1.\n  \tinitRapidLogger\u003c1\u003e(argv[0], FileAppender(\"mylog.log\"));\n//Put a log by logger 1.\n\tgetLogger\u003c1\u003e().info_out\u003c\u003c \"Hello world 0123456789 abcdefghijklmnopqrstuvwxyz\"\u003c\u003ci;\n\n~~~\nThe default logger id is 0;\n\n\n## Multiple appenders\n~~~cpp\ntemplate\u003cclass T\u003e\nvoid addAppender(const T\u0026 app);\nvoid removeLastAppender();\nvoid clearAppender();\n\n~~~\n\n\n\n## Custom data type\n~~~cpp\n\nLoggerStream\u0026 operator\u003c\u003c(LoggerStream\u0026 stream,T n);\n\n~~~\n\n## Custom log level\n~~~cpp\nclass MyCustomerLevel :public LogLevel\n{\npublic:\n\tMyCustomerLevel() :LogLevel(\"MYCUSTOMER\", 20051) {}\n};\n\n~~~\n\n## Custom appender\nOverride all of the virtual member function in LogAppender.\n~~~cpp\n\nclass LogAppender\n{\npublic:\n        LogAppender()=default;\n        /*inner function*/\n        virtual int open()=0;\n        /*inner function*/\n        virtual void close()=0;\n        virtual void append(const std::string \u0026 str)=0;\n        virtual void flush()=0;\n};\n\n~~~\n\n\n\n# Performance\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjstzwj%2Frapidlogger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjstzwj%2Frapidlogger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjstzwj%2Frapidlogger/lists"}